Ejemplo n.º 1
0
def ticket_edit(request, ticket_id):
	ticket = get_object_or_404(Ticket, pk=ticket_id)
	if not (ticket.owned_by_user(request.user) or ticket.is_project_owner(request.user)):	
		request.flash['error'] = 'Du har ej rättigheter att editera ticket'
		return redirect(index)

	if request.method == "POST":
		form = TicketForm(request.POST, instance = ticket)
		if form.is_valid():
			try:
				ticket = form.save()
				request.flash['notice'] = 'Ticket uppdaterad!'
				return redirect(ticket_show, ticket.pk)
			except:
				return HttpResponseServerError()
	else:
		form = TicketForm(instance = ticket)

	return render(request, 'tickets/edit.html', {"form": form, "ticket" : ticket,})
Ejemplo n.º 2
0
def ticket_add(request, project_id):
	project = get_object_or_404(Project, pk=project_id)
	if not (project.user_in_project(request.user) or project.owned_by_user(request.user)):	
		request.flash['error'] = 'Du har ej rättigheter att lägga till ticket till detta projekt'
		return redirect(index)

	if request.method == "POST":
		form = TicketForm(request.POST)
		if form.is_valid():
			form.instance.project = project
			form.instance.user = request.user
			try:
				ticket = form.save()
				request.flash['notice'] = 'Ticket sparad!'
				return redirect(ticket_show, ticket.pk)
			except:
				return HttpResponseServerError()
	else:
		form = TicketForm()
	return render(request, 'tickets/add.html', {"form": form})