def photo_review(request, instance): page_number = int(request.REQUEST.get('page', '1')) sort_order = request.REQUEST.get('sort', '-created_at') is_archived = request.REQUEST.get('archived', 'False') == 'True' photos = get_photos(instance, sort_order, is_archived) paginator = Paginator(photos, _PHOTO_PAGE_SIZE) try: paged_photos = paginator.page(page_number) except EmptyPage: # If the page number is out of bounds, return the last page paged_photos = paginator.page(paginator.num_pages) urlizer = UrlParams('photo_review', instance.url_name, page=page_number, sort=sort_order, archived=is_archived) return { 'photos': paged_photos, 'sort_order': sort_order, 'is_archived': is_archived, 'is_archived_text': _("Archived") if is_archived else _("Active"), 'is_archived_text_lower': (_("archived") if is_archived else _("active")), 'url_for_pagination': urlizer.url('sort', 'archived'), 'url_for_filter': urlizer.url('sort'), 'url_for_sort': urlizer.url('archived'), 'full_params': urlizer.params('page', 'sort', 'archived') }
def comment_moderation(request, instance): (is_archived, is_removed, sort) = _comments_params(request.GET) page_number = int(request.GET.get('page', '1')) page_size = int(request.GET.get('size', '5')) comments = get_comments(request.GET, instance) paginator = Paginator(comments, page_size) try: paged_comments = paginator.page(page_number) except EmptyPage: # If the page number is out of bounds, return the last page paged_comments = paginator.page(paginator.num_pages) urlizer = UrlParams('comment_moderation', instance.url_name, archived=is_archived, sort=sort, removed=is_removed, page=paged_comments.number) comments_url_for_pagination = urlizer.url('archived', 'removed', 'sort') comments_url_for_sort = urlizer.url('archived', 'removed') comments_url_for_filter = urlizer.url('sort') full_params = urlizer.params('archived', 'removed', 'sort', 'page') comments_filter = ('Active', _('active')) if is_archived is None and is_removed: comments_filter = ('Hidden', _('hidden')) elif is_archived and is_removed is None: comments_filter = ('Archived', _('archived')) checked_comments = get_ids_from_request(request) if len(checked_comments) == 1: # Don't check the box for non-batch requests checked_comments = [] return { 'comments': paged_comments, 'comments_filter': comments_filter[0], 'comments_filter_trans': comments_filter[1], 'comments_url_for_pagination': comments_url_for_pagination, 'comments_url_for_sort': comments_url_for_sort, 'comments_url_for_filter': comments_url_for_filter, 'comments_params': full_params, 'comments_sort': sort, 'comment_ids': checked_comments }