示例#1
0
def newproject(request):
	basic = get_basic(request)
	if request.method == 'POST':
		form = ProjectForm(request.user, request.POST, request.FILES)
		if form.is_valid():
			obj = form.save(commit=False)
			obj.user = request.user
			obj.save()
			form.save_m2m()
			return HttpResponseRedirect('/project?id=' + str(obj.id))
	else:
		proj = Project()
		proj.user = request.user
		form = ProjectForm(request.user, instance=proj)
	return render(request, 'newproject.html', {'form': form, 'basic': basic})
示例#2
0
def add_project(request):
	# REMEMBER TO HANDLE UNAUTHENTICATED USERS
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False) 
			project.creator = request.user
			project.soundCloud = getIFrameSrc(projectForm.cleaned_data['soundCloud'])
			project.is_active = True
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('profile/' + request.user.username)
		else: 
			return render(request, 'addProject.html', {'projectForm': projectForm})
	else: 
		projectForm = ProjectForm()
		return render(request, 'addProject.html', {'projectForm': projectForm})
示例#3
0
def editproject(request):
	basic = get_basic(request)
	try:
		proj = Project.objects.get(id=request.GET['id'])
		# Prevent from editing another user's project
		if proj.user.id != request.user.id:
			raise AssertionError
	except (ObjectDoesNotExist, KeyError, AssertionError):
		return HttpResponseRedirect('/editprojects/')
	if request.method == 'POST':
		form = ProjectForm(request.user, request.POST, request.FILES, instance=proj)
		if form.is_valid():
			obj = form.save(commit=False)
			obj.user = request.user
			obj.save()
			form.save_m2m()
			return HttpResponseRedirect('/project?id=' + str(obj.id))
	else:
		form = ProjectForm(request.user, instance=proj)
	return render(request, 'editproject.html', {'form': form, 'basic': basic})
示例#4
0
def edit_project(request, project_id):
	if not request.user.is_authenticated(): 
		return render(request, 'test.html')
	
	# get the object 
	try:
		project = Project.objects.get(id = project_id)
	except :
		raise Http404
	 
	if request.method == 'POST':
		projectForm = ProjectForm(request.POST, instance = project)
		if projectForm.is_valid() and request.user.is_authenticated():
			project = projectForm.save(commit = False)
			project.user = request.user
			project.save()
			projectForm.save_m2m()
			return HttpResponseRedirect('/profile/' + request.user.username)
		else:
			return render(request, 'editProject.html', {'projectForm': projectForm})
	else:
		projectForm = ProjectForm(instance = project)
		return render(request, 'editProject.html', {'projectForm': projectForm})