def new_create(request, project_id=None, project=None): if request.method == 'POST': form = TicketForm(request.POST) if form.is_valid(): form.instance.owner = request.user form.instance.project = project form.instance.date_added = datetime.datetime.today() form.instance.date_updated = datetime.datetime.today() try: form.save() messages.success(request, 'Ticket "%s" was created' % form.instance.name) return redirect(project) except: HttpResponseServerError() else: form = TicketForm() return render(request, 'tickets/new.html', {'form': form, 'header': 'New ticket', 'button': 'Create ticket'})
def edit_update(request, project_id=None, ticket_id=None): project = get_object_or_404(Project, id=project_id) ticket = get_object_or_404(project.tickets, id=ticket_id) user = request.user if project.owned_by_user(user) or ticket.owned_by_user(user): if request.method == 'POST': form = TicketForm(request.POST, instance=ticket) if form.is_valid(): try: form.instance.date_updated = datetime.datetime.today() form.save() messages.success(request, 'Ticket was updated') return redirect(ticket) except: return HttpResponseServerError() else: form = TicketForm(instance=ticket) else: return render(request, 'shared/error.html', {'error_type': 'permission'}) return render(request, 'tickets/new.html', {'form': form, 'header': 'Edit ticket', 'button': 'Update ticket'})