diff --git a/imagehosting/models.py b/imagehosting/models.py index 8da68c2..382bb56 100644 --- a/imagehosting/models.py +++ b/imagehosting/models.py @@ -1,19 +1,19 @@ # -*- 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) - + thumb_name = property(thumb_name) + orig_name = property(orig_name) + def publish(self): self.published_date = timezone.now() - print(self.__dict__) self.save() def __unicode__(self): @@ -22,21 +22,7 @@ class Post(models.Model): def thumb_name(self): x = os.path.split(self.file.name)[-1] return '/thumb_' + x - - thumb_name = property(thumb_name) - + def orig_name(self): - x = os.path.split(self.file.name)[-1] - return x - - 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)''' + return x \ No newline at end of file diff --git a/imagehosting/templates/imagehosting/all.html b/imagehosting/templates/imagehosting/all.html index b65dcf5..5b3f92f 100644 --- a/imagehosting/templates/imagehosting/all.html +++ b/imagehosting/templates/imagehosting/all.html @@ -1,38 +1,35 @@ {% extends 'imagehosting/base.html' %} + {% load static %} {% block content%} -
-{% for image in all %}{% endfor %} -
- - +
+ {% for image in all %}{% endfor %} +
+ + + {% endblock content %} diff --git a/imagehosting/templates/imagehosting/base.html b/imagehosting/templates/imagehosting/base.html index 7a36805..4a15b1b 100644 --- a/imagehosting/templates/imagehosting/base.html +++ b/imagehosting/templates/imagehosting/base.html @@ -1,105 +1,114 @@ - - - - - - - - + ul.menu-icon {display: block} + a.right-menu {display: none} + } + -
- - new image - all images - -
+
+ new image + all images + +
{% block content %} {% endblock%} - - + + diff --git a/imagehosting/templates/imagehosting/carousel.html b/imagehosting/templates/imagehosting/carousel.html deleted file mode 100644 index 0a0dc16..0000000 --- a/imagehosting/templates/imagehosting/carousel.html +++ /dev/null @@ -1,62 +0,0 @@ - {% load staticfiles %} - - - Gallery - - - - - - - - - - - - - - - -
- - -
- -
-
-{% for image in all %} - -{% endfor %} -
-
- -
1
- diff --git a/imagehosting/templates/imagehosting/image.html b/imagehosting/templates/imagehosting/image.html index 6a33bc1..3a3ad33 100644 --- a/imagehosting/templates/imagehosting/image.html +++ b/imagehosting/templates/imagehosting/image.html @@ -2,16 +2,14 @@ {% block content %}
-
- {% if user.is_authenticated %} - удалить - {% endif %} - {{ post.name }} скачать + {% if user.is_authenticated %} + удалить + {% endif %} + {{ post.name }} скачать
- {% endblock %} diff --git a/imagehosting/templates/imagehosting/index.html b/imagehosting/templates/imagehosting/index.html index 52d204a..48a0592 100644 --- a/imagehosting/templates/imagehosting/index.html +++ b/imagehosting/templates/imagehosting/index.html @@ -2,9 +2,9 @@ {% block content %}
-
{% csrf_token %} - {{ form.as_p }} - -
+
{% csrf_token %} + {{ form.as_p }} + +
{% endblock %} diff --git a/imagehosting/templates/imagehosting/login.html b/imagehosting/templates/imagehosting/login.html index e1223e0..d1dae58 100644 --- a/imagehosting/templates/imagehosting/login.html +++ b/imagehosting/templates/imagehosting/login.html @@ -1,15 +1,12 @@ {% extends 'imagehosting/base.html' %} + {% block content %} - -
- - {% csrf_token %} - {{form.as_table}} - -
- - - -
- -{% endblock %} +
+ + {% csrf_token %} + {{form.as_table}} + +
+ +
+{% endblock %} \ No newline at end of file diff --git a/imagehosting/urls.py b/imagehosting/urls.py index 5f64c5a..0698c51 100644 --- a/imagehosting/urls.py +++ b/imagehosting/urls.py @@ -8,11 +8,11 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib import admin from django.contrib.auth.views import login, logout + 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'), url(r'^admin/', admin.site.urls), url(r'^login$', login, {'template_name':'imagehosting/login.html'}, name='login'), diff --git a/imagehosting/views.py b/imagehosting/views.py index a2a1d79..37f3036 100644 --- a/imagehosting/views.py +++ b/imagehosting/views.py @@ -5,84 +5,47 @@ 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 from django.contrib.auth.decorators import login_required from ih import 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 = 'imagehost/media/images/' + filename - # f = str(filename) - # print(filename) - # print f # Create thumbnail - print("DEBUG: Resizing image " + orig_file) thumb_name = images.resize_image(orig_file, { 'name': filename, 'size': [300, 300], 'dest': 'imagehost/media/images' } - ) - return thumb_name + @login_required(login_url="/login") 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) - print(post.orig_name) create_thumb_from_file(post.orig_name) return redirect('imagehosting.views.image_detail', pk=post.id) else: form = PostForm() return render(request, 'imagehosting/index.html', {'form': form}) - + def image_detail(request, pk): post = get_object_or_404(Post, pk=pk) - print(post) return render(request, 'imagehosting/image.html', {'post': post}) - + def all_posts(request): all = Post.objects.order_by('-pk') - # page = request.POST.get("page") return render(request, 'imagehosting/all.html', {'all': all}) -def carousel(request): - return render(request, 'imagehosting/carousel.html', {'all': Post.objects.all()}) - -#@requires_csrf_token @login_required(login_url="/login") def delete_post(request, pk): post_to_delete = get_object_or_404(Post, pk=pk) @@ -93,6 +56,4 @@ def delete_post(request, pk): return HttpResponseRedirect('/admin') post_to_delete.delete() return redirect('imagehosting.views.all_posts') - - #return render(request, 'imagehosting/delete.html', {'form': form}) - return render(request, 'imagehosting/delete.html', {'form': form}) + return render(request, 'imagehosting/delete.html', {'form': form}) \ No newline at end of file diff --git a/templates/imagehost/all.html b/templates/imagehost/all.html deleted file mode 100644 index 2ab1f0c..0000000 --- a/templates/imagehost/all.html +++ /dev/null @@ -1,18 +0,0 @@ -{% 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 deleted file mode 100644 index f705c4b..0000000 --- a/templates/imagehost/base.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - -
- {% block content %} - {% endblock%} - - diff --git a/templates/imagehost/carousel.html b/templates/imagehost/carousel.html deleted file mode 100644 index 0a0dc16..0000000 --- a/templates/imagehost/carousel.html +++ /dev/null @@ -1,62 +0,0 @@ - {% load staticfiles %} - - - Gallery - - - - - - - - - - - - - - - -
- - -
- -
-
-{% for image in all %} - -{% endfor %} -
-
- -
1
- diff --git a/templates/imagehost/delete.html b/templates/imagehost/delete.html deleted file mode 100644 index 26e9e4e..0000000 --- a/templates/imagehost/delete.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'base.html' %} - - {% block content %} -

Delete

-
{% csrf_token %} - {{ form.as_p }} - -
-
- {% endblock %} diff --git a/templates/imagehost/image.html b/templates/imagehost/image.html deleted file mode 100644 index b1152aa..0000000 --- a/templates/imagehost/image.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -{% endblock %} - - diff --git a/templates/imagehost/index.html b/templates/imagehost/index.html deleted file mode 100644 index 682821d..0000000 --- a/templates/imagehost/index.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -
-
{% csrf_token %} - {{ form.as_p }} - -
-
-{% endblock %}