Пример #1
0
def ticket_edit(request, project_id = None, ticket_id = None):
    ticket = Ticket.objects.get(id = ticket_id)
    project = get_object_or_404(Project.objects.filter(id = project_id))
    if project.owned_by_user(request.user) or ticket.owned_by_user(request.user):
        if request.method == 'POST': # If the form has been submitted...
            form = TicketForm(request.POST, instance = ticket) # A form bound to the POST data
            if form.is_valid(): # All validation rules pass
                form.save()
                return redirect('ticket_list', project_id, ticket_id)
            else:
                return render(request, 'projects/edit.html', {'form': form}) # Redirect after POST
        else:
            form = TicketForm(instance = ticket)
            return render(request, 'tickets/edit.html', {'form': form}) # Redirect after POST
    else:
        return HttpResponse("Permission denied")
Пример #2
0
def ticket_add(request, project_id = None):
    project = get_object_or_404(Project.objects.filter(id = project_id))
    if project.owned_by_user(request.user) or project.member_by_user(request.user):
        if request.method == 'POST': # If the form has been submitted...
            form = TicketForm(request.POST) # A form bound to the POST data
            if form.is_valid(): # All validation rules pass

                form.instance.added_by_user = request.user
                form.instance.projects = Project.objects.get(id = project_id)
                new_ticket = form.save()

                return redirect('ticket_list', project_id, new_ticket.id) # Redirect after POST
        else:
            form = TicketForm() # An unbound form

            return render(request, 'tickets/add.html', {'form': form})
    else:
        return HttpResponse("Permission denied")