Beispiel #1
0
def edit_thread(request,thread_id):
    thread=Thread.objects.get(pk=thread_id)
    if request.method=='POST':
        form=ThreadForm(request.POST)
        if form.is_valid():
            thread.title=form.cleaned_data['title']
            thread.description=form.cleaned_data['description']
            thread.save()
            logger.debug("editing a form")
            return HttpResponseRedirect('/thread/%s/' % thread.id)
        
    else:
        form=ThreadForm()
        form.fields['title'].initial=thread.title
        form.fields['description'].initial=thread.description
    
    context=RequestContext(request,{'title':'Edit Item','form':form})
    return render_to_response('addThread.html', locals())
Beispiel #2
0
def add_thread(request):
	#logger.debug('add_thread')
	if request.method == 'POST':
		form=ThreadForm(request.POST)
		if form.is_valid():
		    #logger.debug('username' + str(form.cleaned_data['username']))
		    thread = Thread.objects.create(
		        thread_user = User.objects.get(pk = request.user.id),
                title = form.cleaned_data['title'],
				description = form.cleaned_data['description'],
			)
	       
	        
		return HttpResponseRedirect('/')
	else:	
		logger.debug('init form')
		form=ThreadForm()

	context=RequestContext(request,{'title':'Add Item','form':form})
	return render_to_response('addThread.html', locals())