示例#1
0
def index(request, slugs=None):
    # TODO This function is perfect for a request context processors reused
    # in gallery pages...
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro')
    categories = Gallery.objects.filter(parent__title_slug=parent_slug)

    if current_category:
        photos = current_category.photos.all()
        if current_category.photos_ordering:
            photos = photos.custom_order_by(current_category.photos_ordering)
    else:
        photos = Photo.objects.orphans()

    user_groups = request.user.groups.all().values_list("name", flat=True)
    if 'Editor' in user_groups and len(user_groups) == 1:
        return HttpResponseRedirect(reverse("daguerro-pages-index"))

    page_no = int(request.GET.get('page', 1))
    paginator = DiggPaginator(photos, django_settings.get('DAG_RESULTS_PER_PAGE'))
    context = {'categories': categories,
               'current_category': current_category,
               'photos_page': paginator.page(page_no),
               'add_photo_in_root': django_settings.get('DAG_ALLOW_PHOTOS_IN_ROOT_GALLERY'),
               'no_image_thumb_url': os.path.join(settings.STATIC_URL,
                                                  settings.DAG_NO_IMAGE[settings.DAG_GALLERY_THUMB_SIZE_KEY]),
               'search_options_form': SearchOptionsForm(),
               }
    return render_to_response('daguerro/gallery.html', context,
                              context_instance=RequestContext(request))
示例#2
0
def gallery(request, slugs=None):
    parent_slug, current_gallery = process_category_thread(request, slugs)
    no_image_thumb_url = os.path.join(settings.STATIC_URL, 
                                          settings.DAG_NO_IMAGE[settings.DAG_GALLERY_THUMB_SIZE_KEY])
    
    # TODO Find a better way to do this (parent by default for a category, i.e. root)
    if current_gallery:
        children_galleries = current_gallery.get_children().filter(is_public=True)
        brother_galleries = current_gallery.get_siblings(include_self=True).filter(is_public=True)
        photos = current_gallery.photos.public()
        if current_gallery.photos_ordering:
            photos = photos.custom_order_by(current_gallery.photos_ordering)
    else:
        brother_galleries = None
        children_galleries = None
        photos = Photo.objects.public().orphans()
    
    page_no = int(request.GET.get('page', 1))
    paginator = DiggPaginator(photos, django_settings.get('DAG_RESULTS_PER_PAGE'))
    template = 'website/gallery.html' if slugs else 'website/index.html'  
    return render_to_response(template, {'gallery': current_gallery, 
                                         'brother_galleries': brother_galleries, 
                                         'children_galleries': children_galleries,
                                         'search_options_form': SearchOptionsForm(),
                                         'no_image_thumb_url': no_image_thumb_url,
                                         'photos_page': paginator.page(page_no),
                                         }, context_instance=RequestContext(request)
                              )
示例#3
0
    def build_page(self):
        """
        Paginates the results appropriately.

        In case someone does not want to use Django's built-in pagination, it
        should be a simple matter to override this method to do what they would
        like.
        """
        try:
            page_no = int(self.request.GET.get('page', 1))
        except (TypeError, ValueError):
            raise Http404("Not a valid number for page.")

        if page_no < 1:
            raise Http404("Pages should be 1 or greater.")

        start_offset = (page_no - 1) * self.results_per_page
        self.results[start_offset:start_offset + self.results_per_page]

        paginator = DiggPaginator(self.results, self.results_per_page)

        try:
            page = paginator.page(page_no)
        except InvalidPage:
            raise Http404("No such page!")

        return (paginator, page)