All pastes #481407 Raw Edit

Unnamed

public python v1 · immutable
·published 2007-05-10 20:19 UTC
rendered paste body
from django.http import HttpResponseRedirect, HttpResponsefrom django.shortcuts import render_to_responsefrom django.template import Context, loaderfrom django.contrib.auth import authenticatefrom django.contrib.auth.models import User#from django import formsfrom django.core import validatorsfrom django import newforms as formsfrom ppcgcms.Faq.models import Faq, Question, Answerclass QuestionForm(forms.Form):	form = forms.form_for_model(Question)def faqTag(request, tag, idquest):	if idquest:		print "dupa"	else :		idfaq = Faq.objects.get(name=tag)		a = Question.objects.filter(faq=idfaq)		return render_to_response('Faq/index.html', {			'faq'				: a,			'fname'			: idfaq,				})def index(request):	faq_db = Faq.objects.all().distinct()#	a = {}#	for f in faq_db:#		a[f.name] = int(Question.objects.filter(id=f).count())#	for k, v in a.iteritems():#	   k,v##	a = []##	for f in faq_db:##		a.append({f.name:int(Question.objects.filter(id=f).count())} )##	faq_descr = a##	faq_descr		a = []	for f in faq_db:		a.append((f.name,int(Question.objects.filter(faq=f.id).count())))		Question.objects.filter(id=f).count()	faq_descr = a		question = QuestionForm.form()	login_href 		   = True	register_href		= True	logout_href 		= False	changepass_href	= False	changeemail_href 	= False	profile_href 		= False	show_faq 			= True	if request.POST:			data = request.POST.copy()			f = Faq.objects.get(id=int(data['faq']))			q = Question.objects.create(faq=f, content=data['content'], status='0')#			Question(faq=int(data["faq"]), content=data["content"], status="0")#			Question.save()			q.save()			return render_to_response('Users/messages.html', {						'message' : _('Dodano pytanie.'),					})		if request.user.is_authenticated():		user 			     = request.user		logout_href 	  = True		login_href 		  = False		register_href	  = False		changepass_href  = True		changeemail_href = True		profile_href     = True#		form = forms.FormWrapper(question_form, {}, {})	return render_to_response('Faq/index.html', {		'login_href' 		: login_href,		'logout_href' 		: logout_href,		'register_href'		: register_href,		'changepass_href'	: changepass_href,		'changeemail_href'	: changeemail_href,		'profile_href'	:	profile_href,		'show_faq'		: show_faq,		'questions_db'	: faq_descr,		'form'		: question,	})