root/trunk/opentrials/assistance/views.py @ 626

Revision 626, 1.3 kB (checked in by rafael.soares, 3 years ago)

added i18n in the presentation of the contents of the faq, refs #125

  • Property svn:executable set to *
Line 
1# coding: utf-8
2
3from django.shortcuts import render_to_response
4from django.template.context import RequestContext
5
6from assistance.models import Question, QuestionTranslation
7from assistance.models import Category, CategoryTranslation
8
9
10def faq(request):
11    questions = Question.objects.all().order_by('category', 'order')
12
13    if len(questions) < 1:
14        object_list = None
15    else:
16        object_list = []
17        for question in questions:
18            q = Question()
19            c = Category()
20            try:
21                trans = question.translations.get(language__iexact=request.LANGUAGE_CODE)
22                q.title = trans.title
23                q.answer = trans.answer
24                q.order = question.order
25                q.created = question.created
26            except QuestionTranslation.DoesNotExist:
27                q = question
28            try:
29                trans = question.category.translations.get(language__iexact=request.LANGUAGE_CODE)
30                c.label = trans.label
31            except CategoryTranslation.DoesNotExist:
32                c = question.category
33           
34            q.category = c
35            object_list.append(q)
36
37    return render_to_response('assistance/question_list.html', {
38                          'object_list': object_list,},
39                          context_instance=RequestContext(request))
Note: See TracBrowser for help on using the browser.