Commits

b7w committed 969acfc

Add option to allow/disallow gallery archiving

  • Participants
  • Parent commits 91e799f

Comments (0)

Files changed (6)

File bviewer/archive/views.py

 # -*- coding: utf-8 -*-
 import json
-
 import logging
-
 from django.core.urlresolvers import reverse
 from django.http import Http404, HttpResponse, HttpResponseRedirect
 from django.shortcuts import render
 
 logger = logging.getLogger(__name__)
 
+NO_USER_DEFINED = 'No user defined'
+NO_GALLERY_FOUND = 'No gallery found'
+NOT_ALBUM = 'It is not album with images'
+NOT_ALLOW_ARCHIVING = 'Archiving is disabled for this gallery'
+
 
 def index_view(request, gid):
     """
     """
     holder = get_gallery_user(request)
     if not holder:
-        return message_view(request, message='No user defined')
+        return message_view(request, message=NO_USER_DEFINED)
 
     controller = GalleryController(holder, request.user, gid)
     main = controller.get_object()
     if not main:
-        return message_view(request, message='No gallery found')
+        return message_view(request, message=NO_GALLERY_FOUND)
 
     if not controller.is_album():
-        return message_view(request, message='It is not album with images')
+        return message_view(request, message=NOT_ALBUM)
+
+    if not controller.is_archiving_allowed():
+        return message_view(request, message=NOT_ALLOW_ARCHIVING)
 
     image_paths = [i.path for i in controller.get_images()]
     z = ZipArchiveController(image_paths, holder)
     """
     holder = get_gallery_user(request)
     if not holder:
-        raise Http404('No user defined')
+        raise Http404(NO_USER_DEFINED)
 
     controller = GalleryController(holder, request.user, gid)
     main = controller.get_object()
     if not main:
-        return HttpResponse(json.dumps(dict(error='No gallery found')))
+        return HttpResponse(json.dumps(dict(error=NO_GALLERY_FOUND)))
 
     if not controller.is_album():
-        return HttpResponse(json.dumps(dict(error='It is not album with images')))
+        return HttpResponse(json.dumps(dict(error=NOT_ALBUM)))
+
+    if not controller.is_archiving_allowed():
+        return HttpResponse(json.dumps(dict(error=NOT_ALLOW_ARCHIVING)))
 
     image_paths = [i.path for i in controller.get_images()]
     z = ZipArchiveController(image_paths, holder, name=uid)
     """
     holder = get_gallery_user(request)
     if not holder:
-        raise Http404('No user defined')
+        raise Http404(NO_USER_DEFINED)
 
     controller = GalleryController(holder, request.user, gid)
     main = controller.get_object()
     if not main:
-        raise Http404('No gallery found')
+        raise Http404(NO_GALLERY_FOUND)
 
     if not controller.is_album():
-        return message_view(request, message='It is not album with images')
+        return message_view(request, message=NOT_ALBUM)
+
+    if not controller.is_archiving_allowed():
+        return message_view(request, message=NOT_ALLOW_ARCHIVING)
 
     image_paths = [i.path for i in controller.get_images()]
     z = ZipArchiveController(image_paths, holder, name=uid)

File bviewer/core/controllers.py

 # -*- coding: utf-8 -*-
 import logging
 import re
-
 from django.conf import settings
 from django.core.cache import cache
 from django.db.models import Q
                 result.append(gallery)
         return result
 
+    def is_archiving_allowed(self):
+        obj = self.get_object()
+        return obj and obj.allow_archiving
+
     def is_album(self):
         """
         Is no any sub albums

File bviewer/core/models.py

         help_text='HIDDEN - not shown on page for anonymous, PRIVATE - available only to the holder')
     gallery_sorting = models.SmallIntegerField(max_length=1, choices=SORT_CHOICE, default=ASK,
         help_text='How to sort galleries inside')
+    allow_archiving = models.BooleanField(default=True)
     description = models.TextField(max_length=512, null=True, blank=True)
     thumbnail = models.ForeignKey('Image', null=True, blank=True, related_name='thumbnail', on_delete=models.SET_NULL)
     time = models.DateTimeField(default=date_now)

File bviewer/core/templates/core/gallery.html

     <li class="view-full">
         <a href="#" onclick="playSlideshow()">Slideshow</a>
     </li>
+    {% if main.allow_archiving %}
     <li class="view-full">
         <a href="{% url 'archive.archive' main.id %}" title="Download all images in archive">Download</a>
     </li>
+    {% endif %}
 {% endblock %}
 
 {% block main %}

File bviewer/profile/admin.py

     search_fields = ('title', 'description',)
 
     readonly_fields = ('images', 'thumbnails',)
-    fields = ('parent', 'title', 'visibility', 'gallery_sorting', 'images', 'description', 'time', 'thumbnails', )
+    fields = ('parent', 'title', 'visibility', 'gallery_sorting', 'allow_archiving',
+              'images', 'description', 'time', 'thumbnails', )
 
     def images(self, obj):
         if Gallery.objects.safe_get(id=obj.id):

File docs/releases/notes.rst

 .. index:: Release notes
 
 | **v1.0.8 dev**
-| Add some small features
+| Add some small features. Need database scheme update.
 
+| ``ALTER TABLE core_gallery ADD COLUMN allow_archiving boolean NOT NULL DEFAULT true;``
+
+* Fix bug not safe HTML_EXTRA
 * Fix bug admin gallery title unique integrity error
-* Fix bug not safe HTML_EXTRA
+* Add option to allow/disallow gallery archiving
 * Add disk cache info in user profile