def __call__(self, request, pk, *args, **kwargs): issue = get_object_or_404(Issue, pk = pk) form_type = request.GET.get('form_type', '') if form_type == 'voteform': form, redirect = self.handle_voteform(request, issue) if redirect: return redirect elif form_type == 'voteblankform': form, redirect = self.handle_voteblankform(request, issue) if redirect: return redirect elif form_type == 'tagform': form, redirect = self.handle_tagform(request, issue) if redirect: return redirect else: pass if request.user.is_authenticated(): votes, css = vote_helper_authenticated(request.user, [issue]) else: votes, css = vote_helper_anonymous(request, [issue]) extra_context = { 'issue' : issue, 'vote_class' : css[0], 'vote_text' : votes[0], 'title' : u'ISSUE DETAIL VIEW', 'clean_request_path_for_form' : request.path + u'?' + self.clean_GET_parameters(request).urlencode(), } if form_type in ['voteform','voteblankform', 'tagform']: extra_context[form_type] = form return render_to_response('web/issue_detail.html', extra_context, context_instance=RequestContext(request), )
def __call__(self, request, *args, **kwargs): """ View instance method that does does all the standard things for Issue list views. """ sort_order = issue_sort_order_helper(request) qs = self.issue_queryset(request , *args , **kwargs) queryset = qs.order_by(sort_order).reverse() paginator = Paginator(queryset, 5) # Grab page number from the HTTP GET parameters if present. try: page_no = int(request.GET.get('page', '1')) except ValueError: page_no = 1 # See wether requested page is available at all from the paginator. try: current_page = paginator.page(page_no) except (EmptyPage, InvalidPage): current_page = paginator.page(paginator.num_pages) # grab votes from DB / session if request.user.is_authenticated(): user_votes, vote_css_class = vote_helper_authenticated(request.user, current_page.object_list) else: user_votes, vote_css_class = vote_helper_anonymous(request, current_page.object_list) self.extra_context.update({ 'sort_order' : sort_order, 'current_page' : current_page, 'num_pages' : paginator.num_pages, 'show_more_info_link' : True, 'object_list' : zip(current_page.object_list, user_votes, vote_css_class, ) , 'actions' : gamelogic.actions.get_actions(request.user), 'unavailable_actions' : gamelogic.actions.get_unavailable_actions(request.user), }) return render_to_response('web/issue_list.html', self.extra_context, context_instance=RequestContext(request), )