def edit_ticket(request, ticket_id=None, project=None, template='ponymine/edit_ticket.html', redirect_url=None, form_class=TicketForm): """ Creates or modifies a ticket """ data = {} # get the ticket if ticket_id: ticket = get_object_or_404(Ticket, pk=ticket_id) project = ticket.project else: ticket = Ticket(project=project) data['ticket'] = ticket utils.check_membership(project, request.user) if request.method == "POST": form = form_class(request.POST, instance=ticket) if form.is_valid(): # copy the existing ticket so we can make the change log old_ticket = copy.copy(ticket) # create or update the ticket new_ticket = form.save(commit=False) if not new_ticket.id: new_ticket.reported_by = request.user new_ticket.project = project new_ticket.save() # log any differences between the tickets utils.create_change_logs(request, old_ticket, new_ticket, form.cleaned_data.get('notes', '')) # determine where the user should go after saving the ticket if not redirect_url: redirect_url = new_ticket.get_absolute_url() return HttpResponseRedirect(redirect_url) else: # set the ticket's status based on the query string status_id = request.GET.get('status', None) if status_id: ticket.status = Status.objects.get(pk=int(status_id)) form = form_class(instance=ticket) # limit which users can be assigned a ticket project_member_ids = [u.id for u in project.members.all()] members = User.objects.filter(pk__in=project_member_ids) form.limit_assignable_users(members) data['title'] = ticket.id and _('Update Ticket') or _('New Ticket') data['form'] = form data['project'] = project return render(template, data, context_instance=RequestContext(request))
def view_ticket(request, ticket_id, template='ponymine/ticket_detail.html'): """ Displays a ticket """ data = {} ticket = get_object_or_404(Ticket, pk=ticket_id) utils.check_membership(ticket.project, request.user) data['title'] = ticket.__unicode__() data['ticket'] = ticket data['project'] = ticket.project data['change_status_form'] = ChangeStatusForm() return render(template, data, context_instance=RequestContext(request))
def project_summary(request, path, template='ponymine/project_summary.html'): """ Offers the user a brief overview of the project described by `path` """ data = {} project = Project.objects.with_path(path, request.user) # raise a 404 if no project matches the path if not project: raise Http404() utils.check_membership(project, request.user) data['title'] = _('Summary') data['project'] = project data['ticket_types'] = ((tt.name, (project.tickets.open().filter(ticket_type=tt).count(), project.tickets.filter(ticket_type=tt).count())) for tt in TicketType.objects.all()) data['roles'] = ((r.name, (m.user for m in Membership.objects.filter(project=project, role=r))) for r in Role.objects.all()) return render(template, data, context_instance=RequestContext(request))