Пример #1
0
def project_add_ticket(request, project_id):
    user = request.user
    project = Project.objects.get(id = project_id)
    if project.owned_by_user(user) or project.member_in_project(user): 
      if request.method == "POST":
        form = TicketForm(request.POST)
        if form.is_valid():
          form.instance.date_added = datetime.date.today()
          form.instance.date_updated = datetime.date.today()
          form.instance.user = User.objects.get(id = request.session["user_id"])
          form.instance.project = Project.objects.get(id = project_id)
          try:
            form.save()
            messages.success(request, 'You have successfully added a ticket for the "' + project.name + '"" project!')
            tickets = project.tickets
            url = reverse('project_show', kwargs={'project_id': project.id})
            return HttpResponseRedirect(url)
          except:
            return HttpResponseServerError()
      else:
          form = TicketForm()
      return render(request, 'tickets/add.html', {"form" : form, "project" : project})
      return HttpResponse('Permission denied')
    else:
      messages.info(request, 'You have no permission to add a ticket, you need to be a member of the "' + project.name + '" project.')
      url = reverse('project_show', kwargs={'project_id': project.id})
      return HttpResponseRedirect(url)
Пример #2
0
def ticket_edit(request, project_id, ticket_id):
    ticket = get_object_or_404(Ticket, pk=ticket_id)
    project = get_object_or_404(Project, pk = project_id)
    if project.owned_by_user(request.user) or ticket.owned_by_user(request.user):
      if(request.method == "POST"):
        form = TicketForm(request.POST, instance = ticket)
        if form.is_valid():
          form.instance.date_added = datetime.date.today()
          form.instance.date_updated = datetime.date.today()
          form.instance.user = User.objects.get(id = request.session["user_id"])
          form.instance.project = project
          try:
            form.save()
            messages.success(request, 'You have successfully edited the ticket "' + ticket.name + '"!')
            url = reverse('project_show', kwargs={'project_id': project.id})
            return HttpResponseRedirect(url)
          except:
            return HttpResponseServerError()
      else:
        form = TicketForm(instance = ticket)
      return render(request, 'tickets/edit.html', {"form" : form, "ticket" : ticket, "project" : project})
    else:
      messages.error(request, 'You have no permission to edit the "' + ticket.name + '" ticket.')
      return render(request, 'tickets/show.html', {"project" : project, "ticket" : ticket})