regluit/questionnaire/qprocessors/custom.py

29 lines
902 B
Python
Raw Normal View History

2016-04-26 18:38:32 +00:00
#
# Custom type exists for backwards compatibility. All custom types should now
# exist in the drop down list of the management interface.
#
2016-04-28 16:23:19 +00:00
from django.utils.translation import ugettext as _
2016-04-26 18:38:32 +00:00
from .. import add_type, question_proc, answer_proc, AnswerException
from .. import Processors, QuestionProcessors
@question_proc('custom')
def question_custom(request, question):
cd = question.getcheckdict()
_type = cd['type']
d = {}
if _type in QuestionProcessors:
d = QuestionProcessors[_type](request, question)
if 'template' not in d:
d['template'] = 'questionnaire/%s.html' % _type
return d
@answer_proc('custom')
def process_custom(question, answer):
cd = question.getcheckdict()
_type = cd['type']
if _type in Processors:
return Processors[_type](question, answer)
raise AnswerException(_(u"Processor not defined for this question"))