Ejemplo n.º 1
0
def editView(request, thought_id):
	if request.method=="POST":
		thought=Thought.objects.get_with_permission(request, thought_id)
		form=ThoughtForm(request.POST, instance=thought)
		temp=""
		if form.is_valid():
			if(form.cleaned_data['thought']!=""):
				temp=form.save(commit=False)
				temp.save(request)
			else:
				pass
		else:
			raise Exception('thought form invalid')
		return redirect(reverse('thought_detail', kwargs={'thought_id':temp.pk}))

	else:
		thought=Thought.objects.get_with_permission(request, thought_id)
		form=ThoughtForm(instance=thought)
		c={'thought':thought, 'form':form}
		return render(request, "thought_edit.html", c)
Ejemplo n.º 2
0
def thoughtView(request):
	if request.method=="POST":
		form=ThoughtForm(request.POST)
		temp=""
		if form.is_valid():
			if(form.cleaned_data['thought']!=""):
				temp=form.save(commit=False)
				temp.save(request)
			else:
				error='Please enter a thought.'
				c={'form':form, 'recent':Thought.objects.latest_with_permission(request), 'error':error}
				return render(request, 'thought.html', c)
		else:
			raise Exception('thought form invalid')
		return redirect(reverse('thought_distortion', kwargs={'thought_id':temp.pk}))
		
	else:
		form=ThoughtForm()
		c={'form':form, 'recent':Thought.objects.latest_with_permission(request)}
		return render(request, "thought.html", c)