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) filter_value = dict(archived=is_archived) filter_context = make_filter_context(urlizer, filter_value, [ (_('Active'), _('active'), dict(archived=False)), (_('Archived'), _('archived'), dict(archived=True)), ]) filter_context['container_attr'] = 'data-photo-filter' return { 'photos': paged_photos, 'sort_order': sort_order, 'is_archived': is_archived, 'archived_filter': filter_context, 'url_for_pagination': urlizer.url('sort', 'archived'), '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') full_params = urlizer.params('archived', 'removed', 'sort', 'page') checked_comments = get_ids_from_request(request) if len(checked_comments) == 1: # Don't check the box for non-batch requests checked_comments = [] filter_value = dict(archived=is_archived, removed=is_removed) filter_context = make_filter_context(urlizer, filter_value, [ (_('Active'), _('active'), dict(archived=False, removed=None)), (_('Hidden'), _('hidden'), dict(archived=None, removed=True)), (_('Archived'), _('archived'), dict(archived=True, removed=None)), ]) filter_context['container_attr'] = 'data-comments-filter' return { 'comments': paged_comments, 'comments_filter': filter_context, 'comments_url_for_pagination': comments_url_for_pagination, 'comments_url_for_sort': comments_url_for_sort, 'comments_params': full_params, 'comments_sort': sort, 'comment_ids': checked_comments }