Example #1
0
    def paginate(self, page_number, page_size):
        photoset_id = self.kwargs.get('photoset_id')
        self.photoset = Photoset(id=photoset_id)
        photos, paginator, page = self.photoset.getPhotos(page=page_number,
                                                          per_page=page_size)

        if not photos:
            raise Http404(
                _('No photos not found for photoset %(photoset_id)s') %
                {'photoset_id': photoset_id})

        return photos, paginator, page
Example #2
0
    def get(self, request, *args, **kwargs):
        num_page = request.GET.get('page')
        per_page = request.GET.get('per-page')

        photosets, paginator, page = Photoset.getList()

        photoset_id = request.GET.get('photoset')
        photoset_list = [(photoset.id, photoset.title) for photoset in photosets]

        response_data = {"photosets": photoset_list, 'numOfPages': 1, 'photos': []}

        if photoset_id:
            photoset = list(filter(lambda x: x.id == photoset_id, photosets))

            if len(photoset):
                photoset = photoset.pop()
                photos, paginator, page = photoset.getPhotos(page=num_page, per_page=per_page)

                response_data['photos'] = [{
                    "id": photo.id,
                    "title": photo.title,
                    "large_square_url": photo.large_square_url,
                    "medium_url": photo.medium_url,
                    "url": photo.url
                } for photo in page]

                response_data['numOfPages'] = paginator.num_pages
                response_data['totalOfPhotos'] = paginator.total

        return JsonResponse(response_data)
Example #3
0
class FlickrPhotosListView(PaginatedMixin, TemplateView):
    template_name = getattr(settings, 'PHOTOS_LIST_TEMPLATE')
    paginate_by = getattr(settings, 'PHOTOS_PER_PAGE')
    page_kwarg = getattr(settings, 'PAGE_FIELD')
    per_page_field = getattr(settings, 'PER_PAGE_FIELD')
    context_object_name = 'photos'
    photoset = None

    def paginate(self, page_number, page_size):
        photoset_id = self.kwargs.get('photoset_id')
        self.photoset = Photoset(id=photoset_id)
        photos, paginator, page = self.photoset.getPhotos(page=page_number,
                                                          per_page=page_size)

        if not photos:
            raise Http404(
                _('No photos not found for photoset %(photoset_id)s') %
                {'photoset_id': photoset_id})

        return photos, paginator, page

    def get_context_data(self, **kwargs):
        context = super(FlickrPhotosListView, self).get_context_data(**kwargs)
        context['photoset'] = self.photoset
        return context
def photosets_as_choices(blank_option=BLANK_OPTION):
    choices = (blank_option,)
    exclude = [photoset.photoset_id for photoset in PhotosetModel.objects.all()]

    photosets, paginator, page_obj = Photoset.getList()
    photosets = [(photoset.id, photoset.title) for photoset in photosets if not photoset.id in exclude]
    choices += tuple(photosets)
    return choices
def get_photos_by_photoset(context,
                           photoset_id,
                           page=None,
                           per_page=None,
                           template_name="gallery/flickr/tags/photoset.html"):
    """
    Get photos by photoset_id. Allow paginator.
    :param context:
        Context object.
    :param photoset_id:
        Photoset id to get a photoset.
    :param page:
        Current page number.
    :param per_page:
        How many objects per page.
    :param template_name:
        Template to render tag.
    :return: context object.
    """
    request = context['request']

    # get page number
    if per_page is not None:
        page = page or request.GET.get(PAGE_FIELD, None)

    photoset = Photoset(id=photoset_id)
    photos, paginator, page_obj = photoset.getPhotos(page=page,
                                                     per_page=per_page)
    is_paginated = paginator is not None and page_obj is not None

    context = {
        'photoset': photoset,
        'photos': photos,
        'object_list': photos,
        'template': template_name
    }

    if is_paginated:
        context.update({
            'is_paginated': True,
            'paginator': paginator,
            'page_obj': page_obj
        })

    return context
Example #6
0
def photosets_as_choices(blank_option=BLANK_OPTION):
    choices = (blank_option, )
    exclude = [
        photoset.photoset_id for photoset in PhotosetModel.objects.all()
    ]

    photosets, paginator, page_obj = Photoset.getList()
    photosets = [(photoset.id, photoset.title) for photoset in photosets
                 if not photoset.id in exclude]
    choices += tuple(photosets)
    return choices
def get_photos_by_photoset(context, photoset_id, page=None, per_page=None,
                           template_name="gallery/flickr/tags/photoset.html"):
    """
    Get photos by photoset_id. Allow paginator.
    :param context:
        Context object.
    :param photoset_id:
        Photoset id to get a photoset.
    :param page:
        Current page number.
    :param per_page:
        How many objects per page.
    :param template_name:
        Template to render tag.
    :return: context object.
    """
    request = context['request']

    # get page number
    if per_page is not None:
        page = page or request.GET.get(PAGE_FIELD, None)

    photoset = Photoset(id=photoset_id)
    photos, paginator, page_obj = photoset.getPhotos(page=page, per_page=per_page)
    is_paginated = paginator is not None and page_obj is not None

    context = {
        'photoset': photoset,
        'photos': photos,
        'object_list': photos,
        'template': template_name
    }

    if is_paginated:
        context.update({
            'is_paginated': True,
            'paginator': paginator,
            'page_obj': page_obj
        })

    return context
Example #8
0
class FlickrPhotosListView(PaginatedMixin, TemplateView):
    template_name = getattr(settings, 'PHOTOS_LIST_TEMPLATE')
    paginate_by = getattr(settings, 'PHOTOS_PER_PAGE')
    page_kwarg = getattr(settings, 'PAGE_FIELD')
    per_page_field = getattr(settings, 'PER_PAGE_FIELD')
    context_object_name = 'photos'
    photoset = None

    def paginate(self, page_number, page_size):
        self.photoset = Photoset(id=self.kwargs.get('photoset_id'))
        photos, paginator, page = self.photoset.getPhotos(page=page_number, per_page=page_size)
        return photos, paginator, page

    def get_context_data(self, **kwargs):
        context = super(FlickrPhotosListView, self).get_context_data(**kwargs)
        context['photoset'] = self.photoset
        return context
Example #9
0
 def paginate(self, page_number, page_size):
     self.photoset = Photoset(id=self.kwargs.get('photoset_id'))
     photos, paginator, page = self.photoset.getPhotos(page=page_number, per_page=page_size)
     return photos, paginator, page
Example #10
0
 def paginate(self, page_number, page_size):
     photosets, paginator, page = Photoset.getList(page=page_number, per_page=page_size)
     return photosets, paginator, page
Example #11
0
 def items(self):
     """
     Return published entries.
     """
     photosets, paginator, page = Photoset.getList()
     return photosets
Example #12
0
 def paginate(self, page_number, page_size):
     photosets, paginator, page = Photoset.getList(page=page_number,
                                                   per_page=page_size)
     return photosets, paginator, page
Example #13
0
 def paginate(self, page_number, page_size):
     self.photoset = Photoset(id=self.kwargs.get('photoset_id'))
     photos, paginator, page = self.photoset.getPhotos(page=page_number,
                                                       per_page=page_size)
     return photos, paginator, page