diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/admin.py b/admin.py
new file mode 100644
index 0000000..2d0670b
--- /dev/null
+++ b/admin.py
@@ -0,0 +1,7 @@
+from django.contrib import admin
+
+from .models import Post
+
+admin.site.register(Post
+)
+# Register your models here.
diff --git a/apps.py b/apps.py
new file mode 100644
index 0000000..9a28b40
--- /dev/null
+++ b/apps.py
@@ -0,0 +1,7 @@
+from __future__ import unicode_literals
+
+from django.apps import AppConfig
+
+
+class ImagehostConfig(AppConfig):
+ name = 'imagehost'
diff --git a/forms.py b/forms.py
new file mode 100644
index 0000000..34b26a1
--- /dev/null
+++ b/forms.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+
+from django import forms
+from .models import Post
+
+class PostForm(forms.ModelForm):
+
+ class Meta:
+ model = Post
+ fields = ('name', 'file')
+class DeleteForm(forms.ModelForm):
+
+ class Meta:
+ model = Post
+ fields = []
diff --git a/imagehosting b/imagehosting
new file mode 160000
index 0000000..d5ff54c
--- /dev/null
+++ b/imagehosting
@@ -0,0 +1 @@
+Subproject commit d5ff54c6682be0fc024848d3f1be344aa49c79aa
diff --git a/manage.py b/manage.py
new file mode 100644
index 0000000..8a50ec0
--- /dev/null
+++ b/manage.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
diff --git a/models.py b/models.py
new file mode 100644
index 0000000..1bf72d1
--- /dev/null
+++ b/models.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from django.db import models
+from django.utils import timezone
+from ih import images
+import os
+
+class Post(models.Model):
+ name = models.CharField(max_length=30, blank=True)
+ file = models.FileField(upload_to='images')
+# thumb = models.CharField(max_length=32, null=True, blank=True)
+
+ def publish(self):
+ self.published_date = timezone.now()
+ print(self.__dict__)
+ self.save()
+
+ def __unicode__(self):
+ return self.name
+
+ def thumb_name(self):
+ x = str(self.file)
+ t = x.split('/')
+
+ return '/thumb_' + t[1]
+
+ thumb_name = property(thumb_name)
+
+ def orig_name(self):
+ x = str(self.file)
+ return x.split('/')[1]
+ orig_name = property(orig_name)
+
+ '''def resize_image(self.file):
+ path, file_long = os.path.split(self.file)
+
+ im=image.open(file_long)
+ size = 128, 128
+ im.thumbnail(size)
+ im.save(thumb_name)
+ property(resize_image)'''
diff --git a/templates/imagehost/all.html b/templates/imagehost/all.html
new file mode 100644
index 0000000..2ab1f0c
--- /dev/null
+++ b/templates/imagehost/all.html
@@ -0,0 +1,18 @@
+{% extends 'base.html' %}
+
+{% load pagination_tags %}
+
+{% block content%}
+
+{% for image in all %}
+
+{% endfor %}
+
+
+{% endblock content %}
+
+
diff --git a/templates/imagehost/base.html b/templates/imagehost/base.html
new file mode 100644
index 0000000..f705c4b
--- /dev/null
+++ b/templates/imagehost/base.html
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {% block content %}
+ {% endblock%}
+
+
diff --git a/templates/imagehost/carousel.html b/templates/imagehost/carousel.html
new file mode 100644
index 0000000..0a0dc16
--- /dev/null
+++ b/templates/imagehost/carousel.html
@@ -0,0 +1,62 @@
+ {% load staticfiles %}
+
+
+ Gallery
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{% for image in all %}
+
+ {% endfor %}
+
+
+
+
+
+{% for image in all %}
+
+{% endfor %}
+
+
+
+1
+
diff --git a/templates/imagehost/delete.html b/templates/imagehost/delete.html
new file mode 100644
index 0000000..26e9e4e
--- /dev/null
+++ b/templates/imagehost/delete.html
@@ -0,0 +1,10 @@
+{% extends 'base.html' %}
+
+ {% block content %}
+
Delete
+
+
+ {% endblock %}
diff --git a/templates/imagehost/image.html b/templates/imagehost/image.html
new file mode 100644
index 0000000..b1152aa
--- /dev/null
+++ b/templates/imagehost/image.html
@@ -0,0 +1,13 @@
+{% extends 'base.html' %}
+
+{% block content %}
+
+{% endblock %}
+
+
diff --git a/templates/imagehost/index.html b/templates/imagehost/index.html
new file mode 100644
index 0000000..682821d
--- /dev/null
+++ b/templates/imagehost/index.html
@@ -0,0 +1,10 @@
+{% extends 'base.html' %}
+
+{% block content %}
+
+
+
+{% endblock %}
diff --git a/tests.py b/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/urls.py b/urls.py
new file mode 100644
index 0000000..d13043a
--- /dev/null
+++ b/urls.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+
+from django.conf.urls import url
+from . import views
+from django.conf import settings
+from django.conf.urls.static import static
+urlpatterns = [
+ url(r'^$', views.image_new, name='image_new'),
+ url(r'^post/(?P[0-9]+)/$', views.image_detail, name='image_detail'),
+ url(r'^all/$', views.all_posts, name='all_posts'),
+ url(r'^carousel/$', views.carousel, name='carousel'),
+ url(r'^delete/(?P[0-9]+)/$', views.delete_post, name='delete_post')
+]
diff --git a/views.py b/views.py
new file mode 100644
index 0000000..3e68053
--- /dev/null
+++ b/views.py
@@ -0,0 +1,93 @@
+# -*- coding: utf-8 -*-
+
+from django.shortcuts import render, get_object_or_404, HttpResponseRedirect
+from .models import Post
+from .forms import PostForm, DeleteForm
+from django.shortcuts import redirect
+from ih import files, images
+from django.views.decorators.csrf import requires_csrf_token
+
+'''def create_thumbnail(request):
+ # Get file from
+ file_l, filename = files.get_file_from_request(request, 'file')
+ fh = files.write_to_shm(file_l, filename)
+ file_l = None
+
+ # Create thumbnail
+ thumb_name = images.resize_image(fh, {
+ 'name': filename,
+ 'size': (100, 100),
+ 'dest': 'mysite/media/images'
+ }
+
+ )
+ print(thumb_name)
+ # Remove file from shm
+ e = files.rm_from_shm(filename)
+ if e is not True:
+ print "WARNING: " + e
+
+ return thumb_name'''
+
+
+def create_thumb_from_file(filename):
+ orig_file = 'mysite/media/images/' + str(filename)
+
+ print(filename)
+ # Create thumbnail
+ print("DEBUG: Resizing image " + orig_file)
+ thumb_name = images.resize_image(orig_file, {
+ 'name': filename,
+ 'size': [300, 300],
+ 'dest': 'mysite/media/images'
+ }
+
+ )
+
+ return thumb_name
+
+
+
+def image_new(request):
+ if request.method == "POST":
+ form = PostForm(request.POST, request.FILES)
+ if form.is_valid():
+ # thumb_name = create_thumbnail(request)
+ post = form.save(commit=False)
+ post.save()
+ print("FILE: ", post.file)
+ create_thumb_from_file(post.orig_name)
+ return redirect('imagehost.views.image_detail', pk=post.id)
+ else:
+ form = PostForm()
+ return render(request, 'imagehost/index.html', {'form': form})
+
+
+def image_detail(request, pk):
+ post = get_object_or_404(Post, pk=pk)
+ print(post)
+ return render(request, 'imagehost/image.html', {'post': post})
+
+
+def all_posts(request):
+ all = Post.objects.order_by('-pk')
+ page = request.POST.get("page")
+ return render(request, 'imagehost/all.html', {'all': all})
+
+def carousel(request):
+ return render(request, 'imagehost/carousel.html', {'all': Post.objects.all()})
+
+@requires_csrf_token
+def delete_post(request, pk):
+ post_to_delete = get_object_or_404(Post, pk=pk)
+ if request.method == 'POST':
+ form = DeleteForm(request.POST, instance=post_to_delete)
+ if form.is_valid(): # checks CSRF
+ if not request.user.is_authenticated():
+ return HttpResponseRedirect('/admin')
+ post_to_delete.delete()
+ return redirect('imagehost.views.all_posts')
+ else:
+ form = DeleteForm(instance=post_to_delete)
+
+ return render(request, 'imagehost/delete.html', {'form': form})