def badge(request, id): #todo: supplement database data with the stuff from badges.py badge = get_object_or_404(BadgeData, id=id) all_badge_recipients = User.objects.filter( award_user__badge=badge).annotate( last_awarded_at=Max('award_user__awarded_at'), award_count=Count('award_user')).order_by('-last_awarded_at') objects_list = Paginator(all_badge_recipients, askbot_settings.USERS_PAGE_SIZE) page = PageField().clean(request.GET.get('page')) try: badge_recipients = objects_list.page(page) except (EmptyPage, InvalidPage): badge_recipients = objects_list.page(objects_list.num_pages) paginator_data = { 'is_paginated': (objects_list.num_pages > 1), 'pages': objects_list.num_pages, 'current_page_number': page, 'page_object': badge_recipients, 'base_url': reverse('badge', kwargs={'id': badge.id}) + '?' } paginator_context = functions.setup_paginator(paginator_data) data = { 'active_tab': 'badges', 'badge_recipients': badge_recipients, 'badge': badge, 'page_class': 'meta', 'paginator_context': paginator_context } return render(request, 'badge.html', data)
def list_suggested_tags(request): """moderators and administrators can list tags that are in the moderation queue, apply suggested tag to questions or cancel the moderation reuest.""" if askbot_settings.ENABLE_TAG_MODERATION == False: raise Http404 tags = Tag.objects.filter( status = Tag.STATUS_SUGGESTED, language_code=translation.get_language() ) tags = tags.order_by('-used_count', 'name') #paginate moderated tags paginator = Paginator(tags, 20) page_no = PageField().clean(request.GET.get('page')) try: page = paginator.page(page_no) except (EmptyPage, InvalidPage): page = paginator.page(paginator.num_pages) paginator_context = functions.setup_paginator({ 'is_paginated' : True, 'pages': paginator.num_pages, 'current_page_number': page_no, 'page_object': page, 'base_url' : request.path }) data = { 'tags': page.object_list, 'active_tab': 'tags', 'tab_id': 'suggested', 'page_class': 'moderate-tags-page', 'page_title': _('Suggested tags'), 'paginator_context' : paginator_context, } return render(request, 'list_suggested_tags.html', data)
def tags(request): #view showing a listing of available tags - plain list #1) Get parameters. This normally belongs to form cleaning. post_data = request.GET sortby = post_data.get('sort', 'used') page = PageField().clean(post_data.get('page')) if sortby == 'name': order_by = 'name' else: order_by = '-used_count' query = post_data.get('query', '').strip() tag_list_type = askbot_settings.TAG_LIST_FORMAT #2) Get query set for the tags. query_params = { 'deleted': False, 'language_code': translation.get_language() } if query != '': query_params['name__icontains'] = query tags_qs = Tag.objects.filter(**query_params).exclude(used_count=0) tags_qs = tags_qs.order_by(order_by) #3) Start populating the template context. data = { 'active_tab': 'tags', 'page_class': 'tags-page', 'tag_list_type': tag_list_type, 'query': query, 'tab_id': sortby, 'keywords': query, 'search_state': SearchState(*[None for x in range(8)]) } if tag_list_type == 'list': #plain listing is paginated objects_list = Paginator(tags_qs, DEFAULT_PAGE_SIZE) try: tags = objects_list.page(page) except (EmptyPage, InvalidPage): tags = objects_list.page(objects_list.num_pages) paginator_data = { 'is_paginated': (objects_list.num_pages > 1), 'pages': objects_list.num_pages, 'current_page_number': page, 'page_object': tags, 'base_url': reverse('tags') + '?sort=%s&' % sortby } paginator_context = functions.setup_paginator(paginator_data) data['paginator_context'] = paginator_context else: #tags for the tag cloud are given without pagination tags = tags_qs font_size = extra_tags.get_tag_font_size(tags) data['font_size'] = font_size data['tags'] = tags data.update( context.get_extra('ASKBOT_TAGS_PAGE_EXTRA_CONTEXT', request, data)) if request.is_ajax(): template = get_template('tags/content.html') template_context = RequestContext(request, data) json_data = { 'success': True, 'html': template.render(template_context) } json_string = simplejson.dumps(json_data) return HttpResponse(json_string, content_type='application/json') else: return render(request, 'tags.html', data)