Esempio n. 1
0
def project_add(request):
	if request.method == "POST":
		form = ProjectForm(request.POST)
		if form.is_valid():
			form.instance.owner = request.user
			try:
				project = form.save()
				request.flash['notice'] = 'Projektet sparat!'
				return redirect(project_show, project.pk)
			except:
				return HttpResponseServerError()
	else:
		form = ProjectForm()

	return render(request, 'projects/add.html', {"form": form})
Esempio n. 2
0
def project_edit(request, project_id):
	project = get_object_or_404(Project, pk=project_id)

	if not project.owned_by_user(request.user):
		request.flash['error'] = 'Du har ej rättigheter att editera projektet'
		return redirect(index)

	if request.method == "POST":
		form = ProjectForm(request.POST, instance = project)
		if form.is_valid():
			try:
				form.save()
				request.flash['notice'] = 'Projektet uppdaterat!'
				return redirect(project_show, project.pk)
			except:
				return HttpResponseServerError()
	else:
		form = ProjectForm(instance = project)
	return render(request, 'projects/edit.html', {"form": form, "project" : project,})