def _tickets(request, tickets=''): user = request.user # grab all the tickets created_by or assigned to this user if(tickets == 'created_by'): tickets = Ticket.objects.tickets().filter(Q(created_by=user)) elif(tickets =='assigned'): tickets = Ticket.objects.tickets().filter(Q(assigned_to=user)) else: tickets = Ticket.objects.tickets().filter(Q(created_by=user) | Q(assigned_to=user)) ticket_filterset = TicketFilterSet(request.GET, queryset=tickets) # XXX: not DRY, but there is no systemic way to request this ordering # from the context of a QuerySet tickets = ticket_filterset.qs.order_by("-status__importance", "-global_order", "-priority__rank") tickets_json = querySetToJSON(tickets) # paginate on tickets queryset do_pagination = False if not request.GET.get('showall', False): paginator = Paginator(tickets, TICKETS_PAGINATE_BY) page = request.GET.get('page') try: tickets = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. tickets = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. tickets = paginator.page(paginator.num_pages) finally: do_pagination = True # get all the work created by this user, but isn't yet done running_work = Work.objects.filter(created_by=user).exclude(state=Work.DONE).select_related("created_by", "type", "ticket").order_by('-created_on') return render(request, "accounts/tickets.html", { "tickets": tickets, "running_work": running_work, "queries": connection.queries, "tickets_json": tickets_json, "filterset": ticket_filterset, "do_pagination": do_pagination, "page": tickets, })
def detail(request, project_id): project = get_object_or_404(Project, pk=project_id) ticket_filterset = TicketFilterSet(request.GET, queryset=project.tickets()) # XXX: not DRY, but there is no systemic way to request this ordering # from the context of a QuerySet tickets = ticket_filterset.qs.order_by("-status__importance", "-global_order", "-priority__rank") tickets_json = querySetToJSON(tickets) # paginate on tickets queryset do_pagination = False if not request.GET.get("showall", False): paginator = Paginator(tickets, TICKETS_PAGINATE_BY) page = request.GET.get("page") try: tickets = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. tickets = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. tickets = paginator.page(paginator.num_pages) finally: do_pagination = True components = project.components() work = project.latestWork(10) milestones = Milestone.objects.filter(project=project) return render( request, "projects/detail.html", { "project": project, "tickets": tickets, "queries": connection.queries, "components": components, "work": work, "tickets_json": tickets_json, "milestones": milestones, "filterset": ticket_filterset, "do_pagination": do_pagination, "page": tickets, }, )