author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 15 Sep 2009 20:54:40 +0200 | |
changeset 2922 | 6e373954bbf6 |
parent 2798 | ec1857f0d0c7 |
permissions | -rw-r--r-- |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
2 |
# |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
4 |
# |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
8 |
# |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
10 |
# |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
16 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
17 |
"""Views for Surveys. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
18 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
19 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
21 |
'"Daniel Diniz" <ajaksu@gmail.com>', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
22 |
'"James Levy" <jamesalexanderlevy@gmail.com>', |
2463
05af53239799
Add more flexibility to the Survey helper for use with the new Survey types.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2455
diff
changeset
|
23 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
24 |
] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
25 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
26 |
import datetime |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
27 |
import re |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
28 |
import string |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
29 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
30 |
from google.appengine.ext import db |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
31 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
32 |
from django import forms |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
33 |
from django import http |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
34 |
from django.utils import simplejson |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
35 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
36 |
from soc.logic import cleaning |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
37 |
from soc.logic import dicts |
2543
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
38 |
from soc.logic.helper import timeline |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
39 |
from soc.logic.models.survey import logic as survey_logic |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
40 |
from soc.logic.models.user import logic as user_logic |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
41 |
from soc.models.survey import Survey |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
42 |
from soc.models.survey_record import SurveyRecord |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
43 |
from soc.models.user import User |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
44 |
from soc.views import out_of_band |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
45 |
from soc.views.helper import access |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
46 |
from soc.views.helper import decorators |
2501
d612b48e6e12
Added Survey From Field validation.
Daniel Diniz <ajaksu@gmail.com>
parents:
2497
diff
changeset
|
47 |
from soc.views.helper import forms as forms_helper |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
48 |
from soc.views.helper import lists |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
49 |
from soc.views.helper import redirects |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
50 |
from soc.views.helper import responses |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
51 |
from soc.views.helper import surveys |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
52 |
from soc.views.helper import widgets |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
53 |
from soc.views.models import base |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
54 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
55 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
56 |
DEF_CHOICE_TYPES = set(('selection', 'pick_multi', 'choice', 'pick_quant')) |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
57 |
DEF_TEXT_TYPES = set(('long_answer', 'short_answer')) |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
58 |
DEF_PROPERTY_TYPES = tuple(DEF_CHOICE_TYPES) + tuple(DEF_TEXT_TYPES) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
59 |
|
2502
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
60 |
# used in View.getSchemaOptions to map POST values |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
61 |
DEF_BOOL = {'True': True, 'False': False} |
2502
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
62 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
63 |
DEF_SHORT_ANSWER = ("Short Answer", |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
64 |
"Less than 40 characters. Rendered as a text input. " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
65 |
"It's possible to add a free form question (Content) " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
66 |
"and a in-input prompt/example text.") |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
67 |
DEF_CHOICE = ( |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
68 |
"Selection", |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
69 |
"Can be set as a single choice (selection) or multiple choice " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
70 |
"(pick_multi) question. Rendered as a select (single choice) " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
71 |
"or a group of checkboxes (multiple choice). It's possible to " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
72 |
"add a free form question (Content) and as many free form options " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
73 |
"as wanted. Each option can be edited (double-click), deleted " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
74 |
"(click on (-) button) or reordered (drag and drop).") |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
75 |
DEF_LONG_ANSWER = ( |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
76 |
"Long Answer", |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
77 |
"Unlimited length, auto-growing field. Rendered as a textarea. " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
78 |
"It's possible to add a free form question (Content) and an in-input " |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
79 |
"prompt/example text.") |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
80 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
81 |
DEF_QUESTION_TYPES = dict(short_answer=DEF_SHORT_ANSWER, |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
82 |
long_answer=DEF_LONG_ANSWER, choice=DEF_CHOICE) |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
83 |
|
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
84 |
# for toCSV and View.exportSerialized |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
85 |
DEF_FIELDS = 'author modified_by' |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
86 |
DEF_PLAIN = 'is_featured content created modified' |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
87 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
88 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
89 |
class View(base.View): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
90 |
"""View methods for the Survey model. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
91 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
92 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
93 |
def __init__(self, params=None): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
94 |
"""Defines the fields and methods required for the base View class |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
95 |
to provide the user with list, public, create, edit and delete views. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
96 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
97 |
Params: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
98 |
params: a dict with params for this View |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
99 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
100 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
101 |
rights = access.Checker(params) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
102 |
rights['any_access'] = ['allow'] |
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
103 |
rights['show'] = [('checkIsSurveyWritable', survey_logic)] |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
104 |
rights['create'] = ['checkIsUser'] |
2471
04f13163c1e8
Brown paper bag "without tea" morning typo fix in Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2469
diff
changeset
|
105 |
rights['edit'] = [('checkIsSurveyWritable', survey_logic)] |
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
106 |
rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
107 |
rights['list'] = ['checkDocumentList'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
108 |
rights['pick'] = ['checkDocumentPick'] |
2733
054a2227249c
Added and enabled access check for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2731
diff
changeset
|
109 |
rights['record'] = [('checkHasAny', [ |
054a2227249c
Added and enabled access check for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2731
diff
changeset
|
110 |
[('checkIsSurveyReadable', [survey_logic]), |
054a2227249c
Added and enabled access check for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2731
diff
changeset
|
111 |
('checkIsMySurveyRecord', [survey_logic, 'id'])] |
054a2227249c
Added and enabled access check for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2731
diff
changeset
|
112 |
])] |
2750
e3e3be4bed01
Open up the Survey Results view for users.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2745
diff
changeset
|
113 |
rights['results'] = ['checkIsUser'] |
2534
c880489123fc
Fixed basic Survey access check.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2519
diff
changeset
|
114 |
rights['take'] = [('checkIsSurveyTakeable', survey_logic)] |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
115 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
116 |
new_params = {} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
117 |
new_params['logic'] = survey_logic |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
118 |
new_params['rights'] = rights |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
119 |
|
2582
df5939fecaff
Added Surveys to sidebar menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2576
diff
changeset
|
120 |
new_params['name'] = 'Survey' |
df5939fecaff
Added Surveys to sidebar menu.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2576
diff
changeset
|
121 |
new_params['sidebar_grouping'] = "Surveys" |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
122 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
123 |
new_params['extra_django_patterns'] = [ |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
124 |
(r'^%(url_name)s/(?P<access_type>take)/%(key_fields)s$', |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
125 |
'soc.views.models.%(module_name)s.take', |
2485
4f4e4fdc283d
Fixed typo in title of Survey Take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2484
diff
changeset
|
126 |
'Take %(name)s'), |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
127 |
(r'^%(url_name)s/(?P<access_type>json)/%(scope)s$', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
128 |
'soc.views.models.%(module_name)s.json', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
129 |
'Export %(name)s as JSON'), |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
130 |
(r'^%(url_name)s/(?P<access_type>record)/%(key_fields)s$', |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
131 |
'soc.views.models.%(module_name)s.record', |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
132 |
'View survey record for %(name)s'), |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
133 |
(r'^%(url_name)s/(?P<access_type>results)/%(key_fields)s$', |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
134 |
'soc.views.models.%(module_name)s.results', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
135 |
'View survey results for %(name)s'), |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
136 |
(r'^%(url_name)s/(?P<access_type>show)/user/(?P<link_id>)\w+$', |
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
137 |
'soc.views.models.%(module_name)s.results', |
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
138 |
'View survey results for user'), |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
139 |
] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
140 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
141 |
new_params['export_content_type'] = 'text/text' |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
142 |
new_params['export_extension'] = '.csv' |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
143 |
new_params['export_function'] = surveys.toCSV(self) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
144 |
new_params['delete_redirect'] = '/' |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
145 |
new_params['list_key_order'] = [ |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
146 |
'link_id', 'scope_path', 'name', 'short_name', 'title', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
147 |
'content', 'prefix','read_access','write_access'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
148 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
149 |
new_params['edit_template'] = 'soc/survey/edit.html' |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
150 |
new_params['create_template'] = 'soc/survey/edit.html' |
2478
985fd974e095
Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents:
2477
diff
changeset
|
151 |
new_params['public_template'] = 'soc/survey/public.html' |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
152 |
new_params['record_template'] = 'soc/survey/view_record.html' |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
153 |
new_params['take_template'] = 'soc/survey/take.html' |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
154 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
155 |
new_params['no_create_raw'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
156 |
new_params['no_create_with_scope'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
157 |
new_params['no_create_with_key_fields'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
158 |
new_params['no_list_raw'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
159 |
new_params['sans_link_id_create'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
160 |
new_params['sans_link_id_list'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
161 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
162 |
new_params['create_dynafields'] = [ |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
163 |
{'name': 'link_id', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
164 |
'base': forms.fields.CharField, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
165 |
'label': 'Survey Link ID', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
166 |
}, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
167 |
] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
168 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
169 |
new_params['create_extra_dynaproperties'] = { |
2558
ba32a4f5716b
Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2546
diff
changeset
|
170 |
'content': forms.fields.CharField(required=False, label='Description', |
ba32a4f5716b
Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2546
diff
changeset
|
171 |
widget=widgets.FullTinyMCE(attrs={'rows': 25, 'cols': 100})), |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
172 |
'survey_html': forms.fields.CharField(widget=forms.HiddenInput, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
173 |
required=False), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
174 |
'scope_path': forms.fields.CharField(widget=forms.HiddenInput, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
175 |
required=True), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
176 |
'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
177 |
required=True), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
178 |
'clean_content': cleaning.clean_html_content('content'), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
179 |
'clean_link_id': cleaning.clean_link_id('link_id'), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
180 |
'clean_scope_path': cleaning.clean_scope_path('scope_path'), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
181 |
'clean': cleaning.validate_document_acl(self, True), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
182 |
} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
183 |
|
2558
ba32a4f5716b
Added the possiblitity to add a description to the top of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2546
diff
changeset
|
184 |
new_params['extra_dynaexclude'] = ['author', 'created', |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
185 |
'home_for', 'modified_by', 'modified', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
186 |
'take_survey', 'survey_content'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
187 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
188 |
new_params['edit_extra_dynaproperties'] = { |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
189 |
'doc_key_name': forms.fields.CharField(widget=forms.HiddenInput), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
190 |
'created_by': forms.fields.CharField(widget=widgets.ReadOnlyInput(), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
191 |
required=False), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
192 |
'last_modified_by': forms.fields.CharField( |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
193 |
widget=widgets.ReadOnlyInput(), required=False), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
194 |
'clean': cleaning.validate_document_acl(self), |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
195 |
} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
196 |
|
2745
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
197 |
new_params['survey_take_form'] = surveys.SurveyTakeForm |
2798
ec1857f0d0c7
Added SurveyRecordForm for viewing a SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2766
diff
changeset
|
198 |
new_params['survey_record_form'] = surveys.SurveyRecordForm |
2745
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
199 |
|
2464
64b241a237b2
Merge params from inheriting Survey views so functionality can be reused.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2463
diff
changeset
|
200 |
params = dicts.merge(params, new_params, sub_merge=True) |
2463
05af53239799
Add more flexibility to the Survey helper for use with the new Survey types.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2455
diff
changeset
|
201 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
202 |
super(View, self).__init__(params=params) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
203 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
204 |
def list(self, request, access_type, page_name=None, params=None, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
205 |
filter=None, order=None, **kwargs): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
206 |
"""See base.View.list. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
207 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
208 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
209 |
return super(View, self).list(request, access_type, page_name=page_name, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
210 |
params=params, filter=kwargs) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
211 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
212 |
def _public(self, request, entity, context): |
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
213 |
"""Add a preview version of the Survey to the page's context. |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
214 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
215 |
Args: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
216 |
request: the django request object |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
217 |
entity: the entity to make public |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
218 |
context: the context object |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
219 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
220 |
|
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
221 |
# construct the form to be shown on the page |
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
222 |
# TODO(ljvderijk) Generate SurveyForm without passing along the logic |
2745
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
223 |
survey_form = self._params['survey_take_form']( |
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
224 |
survey_content=entity.survey_content, survey_logic=self._params['logic']) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
225 |
|
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
226 |
survey_form.getFields() |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
227 |
|
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
228 |
context['survey_form'] = survey_form |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
229 |
|
2723
9e03061402ac
The Survey public view now uses the proper page name.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2722
diff
changeset
|
230 |
context['page_name'] = "%s titled '%s'" %( |
9e03061402ac
The Survey public view now uses the proper page name.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2722
diff
changeset
|
231 |
context['page_name'], entity.title) |
9e03061402ac
The Survey public view now uses the proper page name.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2722
diff
changeset
|
232 |
|
2473
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
233 |
# return True to signal that the page may be displayed |
5cf0625dfa73
Changed the Survey public view to give a preview of the Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2472
diff
changeset
|
234 |
return True |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
235 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
236 |
def _editPost(self, request, entity, fields): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
237 |
"""See base.View._editPost(). |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
238 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
239 |
Processes POST request items to add new dynamic field names, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
240 |
question types, and default prompt values to SurveyContent model. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
241 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
242 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
243 |
user = user_logic.getForCurrentAccount() |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
244 |
schema = {} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
245 |
survey_fields = {} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
246 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
247 |
if not entity: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
248 |
# new Survey |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
249 |
if 'serialized' in request.POST: |
2478
985fd974e095
Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents:
2477
diff
changeset
|
250 |
fields, schema, survey_fields = self.importSerialized(request, fields, |
985fd974e095
Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents:
2477
diff
changeset
|
251 |
user) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
252 |
fields['author'] = user |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
253 |
else: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
254 |
fields['author'] = entity.author |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
255 |
schema = self.loadSurveyContent(schema, survey_fields, entity) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
256 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
257 |
# remove deleted properties from the model |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
258 |
self.deleteQuestions(schema, survey_fields, request.POST) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
259 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
260 |
# add new text questions and re-build choice questions |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
261 |
self.getRequestQuestions(schema, survey_fields, request.POST) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
262 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
263 |
# get schema options for choice questions |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
264 |
self.getSchemaOptions(schema, survey_fields, request.POST) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
265 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
266 |
survey_content = getattr(entity,'survey_content', None) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
267 |
# create or update a SurveyContent for this Survey |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
268 |
survey_content = survey_logic.createSurvey(survey_fields, schema, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
269 |
survey_content=survey_content) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
270 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
271 |
# save survey_content for existent survey or pass for creating a new one |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
272 |
if entity: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
273 |
entity.modified_by = user |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
274 |
entity.survey_content = survey_content |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
275 |
db.put(entity) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
276 |
else: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
277 |
fields['survey_content'] = survey_content |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
278 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
279 |
fields['modified_by'] = user |
2543
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
280 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
281 |
super(View, self)._editPost(request, entity, fields) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
282 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
283 |
def loadSurveyContent(self, schema, survey_fields, entity): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
284 |
"""Populate the schema dict and get text survey questions. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
285 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
286 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
287 |
if hasattr(entity, 'survey_content'): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
288 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
289 |
# there is a SurveyContent already |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
290 |
survey_content = entity.survey_content |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
291 |
schema = eval(survey_content.schema) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
292 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
293 |
for question_name in survey_content.dynamic_properties(): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
294 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
295 |
# get the current questions from the SurveyContent |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
296 |
if question_name not in schema: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
297 |
continue |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
298 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
299 |
if schema[question_name]['type'] not in DEF_CHOICE_TYPES: |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
300 |
# Choice questions are always regenerated from request, see |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
301 |
# self.get_request_questions() |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
302 |
question = getattr(survey_content, question_name) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
303 |
survey_fields[question_name] = question |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
304 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
305 |
return schema |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
306 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
307 |
def deleteQuestions(self, schema, survey_fields, POST): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
308 |
"""Process the list of questions to delete, from a hidden input. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
309 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
310 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
311 |
deleted = POST.get('__deleted__', '') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
312 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
313 |
if deleted: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
314 |
deleted = deleted.split(',') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
315 |
for field in deleted: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
316 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
317 |
if field in schema: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
318 |
del schema[field] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
319 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
320 |
if field in survey_fields: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
321 |
del survey_fields[field] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
322 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
323 |
def getRequestQuestions(self, schema, survey_fields, POST): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
324 |
"""Get fields from request. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
325 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
326 |
We use two field/question naming and processing schemes: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
327 |
- Choice questions consist of <input/>s with a common name, being rebuilt |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
328 |
anew on every edit POST so we can gather ordering, text changes, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
329 |
deletions and additions. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
330 |
- Text questions only have special survey__* names on creation, afterwards |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
331 |
they are loaded from the SurveyContent dynamic properties. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
332 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
333 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
334 |
for key, value in POST.items(): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
335 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
336 |
if key.startswith('id_'): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
337 |
# Choice question fields, they are always generated from POST contents, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
338 |
# as their 'content' is editable and they're reorderable. Also get |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
339 |
# its field index for handling reordering fields later. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
340 |
name, number = key[3:].replace('__field', '').rsplit('_', 1) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
341 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
342 |
if name not in schema: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
343 |
if 'NEW_' + name in POST: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
344 |
# new Choice question, set generic type and get its index |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
345 |
schema[name] = {'type': 'choice'} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
346 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
347 |
if name in schema and schema[name]['type'] in DEF_CHOICE_TYPES: |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
348 |
# build an index:content dictionary |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
349 |
if name in survey_fields: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
350 |
if value not in survey_fields[name]: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
351 |
survey_fields[name][int(number)] = value |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
352 |
else: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
353 |
survey_fields[name] = {int(number): value} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
354 |
|
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
355 |
elif key.startswith('survey__'): # Text question |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
356 |
# this is super ugly but unless data is serialized the regex is needed |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
357 |
prefix = re.compile('survey__([0-9]{1,3})__') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
358 |
prefix_match = re.match(prefix, key) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
359 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
360 |
index = prefix_match.group(0).replace('survey', '').replace('__','') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
361 |
index = int(index) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
362 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
363 |
field_name = prefix.sub('', key) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
364 |
field = 'id_' + key |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
365 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
366 |
for ptype in DEF_PROPERTY_TYPES: |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
367 |
# should only match one |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
368 |
if ptype + "__" in field_name: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
369 |
field_name = field_name.replace(ptype + "__", "") |
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
370 |
if field_name not in schema: |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
371 |
schema[field_name]= {} |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
372 |
schema[field_name]["index"] = index |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
373 |
schema[field_name]["type"] = ptype |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
374 |
|
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
375 |
# store text question tooltip from the input/textarea value |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
376 |
schema[field_name]["tip"] = value |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
377 |
|
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
378 |
# add the question as a dynamic property to survey_content |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
379 |
survey_fields[field_name] = value |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
380 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
381 |
def getSchemaOptions(self, schema, survey_fields, POST): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
382 |
"""Get question, type, rendering and option order for choice questions. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
383 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
384 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
385 |
RENDER = {'checkboxes': 'multi_checkbox', 'select': 'single_select', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
386 |
'radio_buttons': 'quant_radio'} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
387 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
388 |
RENDER_TYPES = {'select': 'selection', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
389 |
'checkboxes': 'pick_multi', |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
390 |
'radio_buttons': 'pick_quant' } |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
391 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
392 |
for key in schema: |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
393 |
if schema[key]['type'] in DEF_CHOICE_TYPES and key in survey_fields: |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
394 |
render_for = 'render_for_' + key |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
395 |
if render_for in POST: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
396 |
schema[key]['render'] = RENDER[POST[render_for]] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
397 |
schema[key]['type'] = RENDER_TYPES[POST[render_for]] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
398 |
|
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
399 |
# set the choice question's tooltip |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
400 |
tip_for = 'tip_for_' + key |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
401 |
schema[key]['tip'] = POST.get(tip_for) |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
402 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
403 |
# handle reordering fields |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
404 |
ordered = False |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
405 |
order = 'order_for_' + key |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
406 |
if order in POST and isinstance(survey_fields[key], dict): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
407 |
order = POST[order] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
408 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
409 |
# 'order_for_name' is jquery serialized from a sortable, so it's in |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
410 |
# a 'name[]=1&name[]=2&name[]=0' format ('id-li-' is set in our JS) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
411 |
order = order.replace('id-li-%s[]=' % key, '') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
412 |
order = order.split('&') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
413 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
414 |
if len(order) == len(survey_fields[key]) and order[0]: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
415 |
order = [int(number) for number in order] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
416 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
417 |
if set(order) == set(survey_fields[key]): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
418 |
survey_fields[key] = [survey_fields[key][i] for i in order] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
419 |
ordered = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
420 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
421 |
if not ordered: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
422 |
# we don't have a good ordering to use |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
423 |
ordered = sorted(survey_fields[key].items()) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
424 |
survey_fields[key] = [value for index, value in ordered] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
425 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
426 |
# set 'question' entry (free text label for question) in schema |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
427 |
question_for = 'NEW_' + key |
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
428 |
if question_for in POST and POST[question_for]: |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
429 |
schema[key]["question"] = POST[question_for] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
430 |
|
2502
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
431 |
# set wheter the question is required |
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
432 |
required_for = 'required_for_' + key |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
433 |
schema[key]['required'] = DEF_BOOL[POST[required_for]] |
2502
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
434 |
|
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
435 |
# set wheter the question allows comments |
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
436 |
comment_for = 'comment_for_' + key |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
437 |
schema[key]['has_comment'] = DEF_BOOL[POST[comment_for]] |
2502
2e096acc8720
Surveys can now have required questions and comments can be turned on/off.
Daniel Diniz <ajaksu@gmail.com>
parents:
2501
diff
changeset
|
438 |
|
2560
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
439 |
# set the question index from JS-calculated value |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
440 |
index_for = 'index_for_' + key |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
441 |
if index_for in POST: |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
442 |
schema[key]['index'] = int(POST[index_for].replace('__', '')) |
a944c0169ad8
Added ability to add custom tooltips and UI improvements.
Daniel Diniz <ajaksu@gmail.com>
parents:
2558
diff
changeset
|
443 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
444 |
def createGet(self, request, context, params, seed): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
445 |
"""Pass the question types for the survey creation template. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
446 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
447 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
448 |
context['question_types'] = DEF_QUESTION_TYPES |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
449 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
450 |
# avoid spurious results from showing on creation |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
451 |
context['new_survey'] = True |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
452 |
return super(View, self).createGet(request, context, params, seed) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
453 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
454 |
def editGet(self, request, entity, context, params=None): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
455 |
"""Process GET requests for the specified entity. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
456 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
457 |
Builds the SurveyForm that represents the Survey question contents. |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
458 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
459 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
460 |
self._entity = entity |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
461 |
survey_content = entity.survey_content |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
462 |
|
2517
97117d341f62
Split SurveyForm into SurveyTakeForm and SurveyEditForm.
Daniel Diniz <ajaksu@gmail.com>
parents:
2516
diff
changeset
|
463 |
survey_form = surveys.SurveyEditForm(survey_content=survey_content, |
97117d341f62
Split SurveyForm into SurveyTakeForm and SurveyEditForm.
Daniel Diniz <ajaksu@gmail.com>
parents:
2516
diff
changeset
|
464 |
survey_logic=params['logic']) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
465 |
survey_form.getFields() |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
466 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
467 |
local = dict(survey_form=survey_form, question_types=DEF_QUESTION_TYPES, |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
468 |
survey_h=entity.survey_content) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
469 |
context.update(local) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
470 |
|
2478
985fd974e095
Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents:
2477
diff
changeset
|
471 |
params['edit_form'] = surveys.HelperForm(params['edit_form']) |
2440
05c430d1c147
Renamed opening to survey_start and deadline to survey_end.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2439
diff
changeset
|
472 |
if entity.survey_end and datetime.datetime.now() > entity.survey_end: |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
473 |
# are we already passed the survey_end? |
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
474 |
context["passed_survey_end"] = True |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
475 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
476 |
return super(View, self).editGet(request, entity, context, params=params) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
477 |
|
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
478 |
@decorators.merge_params |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
479 |
@decorators.check_access |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
480 |
def take(self, request, access_type, page_name=None, |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
481 |
params=None, **kwargs): |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
482 |
"""View for taking a Survey. |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
483 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
484 |
For Args see base.View().public(). |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
485 |
""" |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
486 |
|
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
487 |
survey_logic = params['logic'] |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
488 |
|
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
489 |
try: |
2497
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
490 |
entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
491 |
except out_of_band.Error, error: |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
492 |
return responses.errorResponse( |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
493 |
error, request, template=params['error_public']) |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
494 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
495 |
template = params['take_template'] |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
496 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
497 |
# get the context for this webpage |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
498 |
context = responses.getUniversalContext(request) |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
499 |
responses.useJavaScript(context, params['js_uses_all']) |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
500 |
context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
501 |
context['entity'] = entity |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
502 |
|
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
503 |
# try to get an existing SurveyRecord for the current user |
2497
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
504 |
survey_record = self._getSurveyRecordFor(entity, request, params) |
2766
93e4745ebdbd
Fixed Survey Take page which was erroring on undefined variables.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2752
diff
changeset
|
505 |
post_dict = request.POST |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
506 |
|
2519
53b0cc84ab00
Added _getSurveyTakeForm to the Survey view.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2518
diff
changeset
|
507 |
# get an instance of SurveyTakeForm to use |
2745
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
508 |
survey_form = params['survey_take_form']( |
2766
93e4745ebdbd
Fixed Survey Take page which was erroring on undefined variables.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2752
diff
changeset
|
509 |
survey_content=entity.survey_content, |
93e4745ebdbd
Fixed Survey Take page which was erroring on undefined variables.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2752
diff
changeset
|
510 |
survey_record=survey_record, |
2745
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
511 |
survey_logic=params['logic'], |
c45dc8a5d64e
Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2740
diff
changeset
|
512 |
data=post_dict) |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
513 |
|
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
514 |
# fill context with the survey_form and additional information |
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
515 |
context['survey_form'] = survey_form |
2740
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
516 |
self._setSurveyTakeContext(request, params, context, entity, survey_record) |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
517 |
|
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
518 |
if request.POST: |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
519 |
return self.takePost(request, template, context, params, survey_form, |
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
520 |
entity, survey_record, **kwargs) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
521 |
else: #request.GET |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
522 |
return self.takeGet(request, template, context, params, survey_form, |
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
523 |
entity, survey_record, **kwargs) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
524 |
|
2497
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
525 |
def _getSurveyRecordFor(self, survey, request, params): |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
526 |
"""Returns the SurveyRecord for the given Survey and request. |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
527 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
528 |
Args: |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
529 |
survey: a Survey entity |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
530 |
request: a Django HTTPRequest object |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
531 |
params: params for the requesting view |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
532 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
533 |
Returns: |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
534 |
An existing SurveyRecord iff any exists for the given Survey, request |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
535 |
and any other conditions that must apply. |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
536 |
""" |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
537 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
538 |
survey_logic = params['logic'] |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
539 |
record_logic = survey_logic.getRecordLogic() |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
540 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
541 |
user_entity = user_logic.getForCurrentAccount() |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
542 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
543 |
filter = {'survey': survey, |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
544 |
'user': user_entity} |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
545 |
|
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
546 |
return record_logic.getForFields(filter, unique=True) |
996f381d458c
Added _getSurveyRecordFor method to Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
547 |
|
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
548 |
def takeGet(self, request, template, context, params, survey_form, entity, |
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
549 |
record, **kwargs): |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
550 |
"""Handles the GET request for the Survey's take page. |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
551 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
552 |
Args: |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
553 |
template: the template used for this view |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
554 |
survey_form: instance of SurveyTakeForm |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
555 |
entity: the Survey entity |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
556 |
record: a SurveyRecord entity iff any exists |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
557 |
rest: see base.View.public() |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
558 |
""" |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
559 |
|
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
560 |
# call the hook method |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
561 |
self._takeGet(request, template, context, params, entity, record, **kwargs) |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
562 |
|
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
563 |
return responses.respond(request, template, context) |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
564 |
|
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
565 |
def _takeGet(self, request, template, context, params, entity, record, |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
566 |
**kwargs): |
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
567 |
"""Hook for the GET request for the Survey's take page. |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
568 |
|
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
569 |
This method is called just before the GET page is shown. |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
570 |
|
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
571 |
Args: |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
572 |
template: the template used for this view |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
573 |
entity: the Survey entity |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
574 |
record: a SurveyRecord entity |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
575 |
rest: see base.View.public() |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
576 |
""" |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
577 |
pass |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
578 |
|
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
579 |
def takePost(self, request, template, context, params, survey_form, entity, |
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
580 |
record, **kwargs): |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
581 |
"""Handles the POST request for the Survey's take page. |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
582 |
|
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
583 |
Args: |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
584 |
template: the template used for this view |
2518
66405056baf8
Only initialize a SurveyTakeForm in take instead of in takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2517
diff
changeset
|
585 |
survey_form: instance of SurveyTakeForm |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
586 |
entity: the Survey entity |
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
587 |
record: a SurveyRecord entity |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
588 |
rest: see base.View.public() |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
589 |
""" |
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
590 |
|
2484
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
591 |
survey_logic = params['logic'] |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
592 |
record_logic = survey_logic.getRecordLogic() |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
593 |
|
2501
d612b48e6e12
Added Survey From Field validation.
Daniel Diniz <ajaksu@gmail.com>
parents:
2497
diff
changeset
|
594 |
if not survey_form.is_valid(): |
2516
afae8791ad97
Do not call takeGet when SurveyForm ValidationError occurs.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2504
diff
changeset
|
595 |
# show the form errors |
afae8791ad97
Do not call takeGet when SurveyForm ValidationError occurs.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2504
diff
changeset
|
596 |
return self._constructResponse(request, entity=entity, context=context, |
afae8791ad97
Do not call takeGet when SurveyForm ValidationError occurs.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2504
diff
changeset
|
597 |
form=survey_form, params=params, |
afae8791ad97
Do not call takeGet when SurveyForm ValidationError occurs.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2504
diff
changeset
|
598 |
template=template) |
2501
d612b48e6e12
Added Survey From Field validation.
Daniel Diniz <ajaksu@gmail.com>
parents:
2497
diff
changeset
|
599 |
|
d612b48e6e12
Added Survey From Field validation.
Daniel Diniz <ajaksu@gmail.com>
parents:
2497
diff
changeset
|
600 |
# retrieve the data from the form |
d612b48e6e12
Added Survey From Field validation.
Daniel Diniz <ajaksu@gmail.com>
parents:
2497
diff
changeset
|
601 |
_, properties = forms_helper.collectCleanedFields(survey_form) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
602 |
|
2484
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
603 |
# add the required SurveyRecord properties |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
604 |
properties['user'] = user_logic.getForCurrentAccount() |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
605 |
properties['survey'] = entity |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
606 |
|
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
607 |
# call the hook method before updating the SurveyRecord |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
608 |
self._takePost(request, params, entity, record, properties) |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
609 |
|
2484
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
610 |
# update the record entity if any and clear all dynamic properties |
2540
1e44d71c0e3e
Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2534
diff
changeset
|
611 |
record_logic.updateOrCreateFromFields(record, properties, |
1e44d71c0e3e
Several style fixes due to code reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2534
diff
changeset
|
612 |
clear_dynamic=True) |
2484
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
613 |
|
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
614 |
# TODO: add notice to page that the response has been saved successfully |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
615 |
# redirect to the same page for now |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
616 |
redirect = request.path |
f41a9e1eeeea
Add a base implementation of takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2478
diff
changeset
|
617 |
return http.HttpResponseRedirect(redirect) |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
618 |
|
2486
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
619 |
def _takePost(self, request, params, entity, record, properties): |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
620 |
"""Hook for the POST request for the Survey's take page. |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
621 |
|
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
622 |
This method is called just before the SurveyRecord is stored. |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
623 |
|
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
624 |
Args: |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
625 |
request: Django Request object |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
626 |
params: the params for the current view |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
627 |
entity: a Survey entity |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
628 |
record: a SurveyRecord entity |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
629 |
properties: properties to be stored in the SurveyRecord entity |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
630 |
""" |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
631 |
pass |
78c87d9f4af7
Added hook methods to takeGet and takePost.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2485
diff
changeset
|
632 |
|
2740
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
633 |
def _setSurveyTakeContext(self, request, params, context, survey, |
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
634 |
survey_record): |
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
635 |
"""Sets the help_text and status for take template use. |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
636 |
|
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
637 |
Args: |
2740
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
638 |
request: HTTP request object |
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
639 |
params: the params for the current View |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
640 |
context: the context for the view to update |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
641 |
survey: a Survey entity |
2740
4b8aa5b9cb23
Added project title and student name to the ProjectSurvey take page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2733
diff
changeset
|
642 |
survey_record: a SurveyRecordEntity iff exists |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
643 |
""" |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
644 |
|
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
645 |
if not survey.survey_end: |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
646 |
survey_end_text = "" |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
647 |
else: |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
648 |
survey_end_text = " by " + str( |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
649 |
survey.survey_end.strftime("%A, %d. %B %Y %I:%M%p")) |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
650 |
|
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
651 |
if survey_record: |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
652 |
help_text = "You may edit and re-submit this survey %s." %( |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
653 |
survey_end_text) |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
654 |
status = "edit" |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
655 |
else: |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
656 |
help_text = "Please complete this survey %s." %( |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
657 |
survey_end_text) |
2477
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
658 |
status = "create" |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
659 |
|
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
660 |
# update the context with the help_text and status |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
661 |
context_update = dict(status=status, help_text=help_text) |
e5629995d118
Implemented the takeGet view for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2476
diff
changeset
|
662 |
context.update(context_update) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
663 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
664 |
@decorators.merge_params |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
665 |
@decorators.check_access |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
666 |
def viewResults(self, request, access_type, page_name=None, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
667 |
params=None, **kwargs): |
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
668 |
"""View that lists all SurveyRecords which are of interest to the user. |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
669 |
|
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
670 |
For params see base.View.public(). |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
671 |
""" |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
672 |
|
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
673 |
# TODO: this view could also contain statistics for the Survey |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
674 |
|
2727
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
675 |
survey_logic = params['logic'] |
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
676 |
record_logic = survey_logic.getRecordLogic() |
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
677 |
|
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
678 |
try: |
2727
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
679 |
entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
680 |
except out_of_band.Error, error: |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
681 |
return responses.errorResponse( |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
682 |
error, request, template=params['error_public']) |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
683 |
|
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
684 |
# get the context for this webpage |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
685 |
context = responses.getUniversalContext(request) |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
686 |
responses.useJavaScript(context, params['js_uses_all']) |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
687 |
context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
688 |
context['entity'] = entity |
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
689 |
|
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
690 |
# add the first question to the context show a preview can be shown |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
691 |
context['first_question'] = entity.survey_content.orderedProperties()[0] |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
692 |
|
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
693 |
# get the rights checker |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
694 |
user_entity = user_logic.getForCurrentAccount() |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
695 |
rights = self._params['rights'] |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
696 |
rights.setCurrentUser(user_entity.account, user_entity) |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
697 |
|
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
698 |
# check if the current user is allowed to visit the read the survey |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
699 |
allowed_to_read = False |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
700 |
|
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
701 |
try: |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
702 |
rights.checkIsSurveyReadable( |
2752
fb3bed3eecd8
Fix copy/paste fail in Survey results view regarding allowed_to_read.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2751
diff
changeset
|
703 |
{'key_name': entity.key().name(), |
fb3bed3eecd8
Fix copy/paste fail in Survey results view regarding allowed_to_read.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2751
diff
changeset
|
704 |
'prefix': entity.prefix, |
fb3bed3eecd8
Fix copy/paste fail in Survey results view regarding allowed_to_read.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2751
diff
changeset
|
705 |
'scope_path': entity.scope_path, |
fb3bed3eecd8
Fix copy/paste fail in Survey results view regarding allowed_to_read.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2751
diff
changeset
|
706 |
'link_id': entity.link_id, |
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
707 |
'user': user_entity}, |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
708 |
survey_logic) |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
709 |
allowed_to_read = True |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
710 |
except: |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
711 |
pass |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
712 |
|
2751
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
713 |
# get the filter for the SurveyRecords |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
714 |
fields = self._getResultsViewRecordFields(entity, allowed_to_read) |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
715 |
|
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
716 |
list_params = params.copy() |
2727
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
717 |
list_params['logic'] = record_logic |
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
718 |
list_params['list_heading'] = 'soc/survey/list/records_heading.html' |
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
719 |
list_params['list_row'] = 'soc/survey/list/records_row.html' |
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
720 |
list_params['list_description'] = \ |
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
721 |
"List of Records for the %s titled '%s'." %(list_params['name'], |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
722 |
entity.title) |
2727
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
723 |
list_params['list_action'] = (redirects.getViewSurveyRecordRedirect, |
19e985f09de8
ViewResults for Surveys is now showing all SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2723
diff
changeset
|
724 |
list_params) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
725 |
|
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
726 |
record_list = lists.getListContent(request, list_params, fields, idx=0) |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
727 |
|
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
728 |
contents = [record_list] |
2455
a023b71ce125
fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents:
2448
diff
changeset
|
729 |
|
2576
7a1138f8a0e2
Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents:
2560
diff
changeset
|
730 |
return self._list(request, list_params, contents, page_name, context) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
731 |
|
2751
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
732 |
def _getResultsViewRecordFields(self, survey, allowed_to_read): |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
733 |
"""Retrieves the Results View filter for SurveyRecords. |
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
734 |
|
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
735 |
Args: |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
736 |
survey: Survey instance for which the Records need to be shown |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
737 |
allowed_to_read: specifies if the current User has read access |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
738 |
|
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
739 |
Returns: |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
740 |
Returns the dictionary containing the fields to filter on |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
741 |
""" |
2751
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
742 |
|
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
743 |
# only show records for the retrieved survey |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
744 |
fields = {'survey': survey} |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
745 |
|
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
746 |
if not allowed_to_read: |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
747 |
# this user is not allowed to view all the Records so only show their own |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
748 |
fields['user'] = user_logic.getForCurrentAccount() |
e8a98669ec8c
_getResultsViewRecordFields does not need fields argument anymore.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2750
diff
changeset
|
749 |
|
2731
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
750 |
return fields |
4d143278f9a0
The Survey Results view now only list Records of interest to the current user.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2727
diff
changeset
|
751 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
752 |
@decorators.merge_params |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
753 |
@decorators.check_access |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
754 |
def viewRecord(self, request, access_type, page_name=None, |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
755 |
params=None, **kwargs): |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
756 |
"""View that allows the user to see the contents of a single SurveyRecord. |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
757 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
758 |
For params see base.View.public() |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
759 |
""" |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
760 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
761 |
survey_logic = params['logic'] |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
762 |
record_logic = survey_logic.getRecordLogic() |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
763 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
764 |
try: |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
765 |
survey_entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
766 |
except out_of_band.Error, error: |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
767 |
return responses.errorResponse( |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
768 |
error, request, template=params['error_public']) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
769 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
770 |
get_dict = request.GET |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
771 |
record_id = get_dict.get('id') |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
772 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
773 |
if record_id and record_id.isdigit(): |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
774 |
record_id = int(record_id) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
775 |
record_entity = record_logic.getFromIDOr404(record_id) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
776 |
else: |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
777 |
raise out_of_band.Error('No valid Record ID given') |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
778 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
779 |
if record_entity.survey.key() != survey_entity.key(): |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
780 |
# record does not match the retrieved survey |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
781 |
raise out_of_band.Error('Record ID does not match the given survey') |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
782 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
783 |
# get the context for this webpage |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
784 |
context = responses.getUniversalContext(request) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
785 |
responses.useJavaScript(context, params['js_uses_all']) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
786 |
context['page_name'] = "%s titled '%s'" %(page_name, survey_entity.title) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
787 |
context['entity'] = survey_entity |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
788 |
context['record'] = record_entity |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
789 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
790 |
# store the read only survey form in the context |
2798
ec1857f0d0c7
Added SurveyRecordForm for viewing a SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2766
diff
changeset
|
791 |
survey_form = params['survey_record_form']( |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
792 |
survey_content=survey_entity.survey_content, |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
793 |
survey_record=record_entity, |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
794 |
survey_logic=self._params['logic'], |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
795 |
read_only=True) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
796 |
survey_form.getFields() |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
797 |
context['survey_form'] = survey_form |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
798 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
799 |
template = params['record_template'] |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
800 |
return responses.respond(request, template, context) |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
801 |
|
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
802 |
@decorators.merge_params |
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
803 |
@decorators.check_access |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
804 |
def exportSerialized(self, request, access_type, page_name=None, |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
805 |
params=None, **kwargs): |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
806 |
"""Exports Surveys in JSON format. |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
807 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
808 |
For args see base.View.public(). |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
809 |
""" |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
810 |
|
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
811 |
survey_logic = params['logic'] |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
812 |
|
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
813 |
try: |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
814 |
sur = survey_logic.getFromKeyFieldsOr404(kwargs) |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
815 |
except out_of_band.Error, error: |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
816 |
return responses.errorResponse( |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
817 |
error, request, template=params['error_public']) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
818 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
819 |
json = sur.toDict() |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
820 |
json.update(dict((f, str(getattr(sur, f))) for f in DEF_PLAIN.split())) |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
821 |
static = ((f, str(getattr(sur, f).link_id)) for f in DEF_FIELDS.split()) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
822 |
json.update(dict(static)) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
823 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
824 |
dynamic = sur.survey_content.dynamic_properties() |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
825 |
content = ((prop, getattr(sur.survey_content, prop)) for prop in dynamic) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
826 |
json['survey_content'] = dict(content) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
827 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
828 |
schema = sur.survey_content.schema |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
829 |
json['survey_content']['schema'] = eval(sur.survey_content.schema) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
830 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
831 |
data = simplejson.dumps(json, indent=2) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
832 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
833 |
return self.json(request, data=json) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
834 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
835 |
def importSerialized(self, request, fields, user): |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
836 |
"""Import Surveys in JSON format. |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
837 |
|
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
838 |
TODO: have this method do a proper import |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
839 |
|
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
840 |
Args: |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
841 |
request: Django Requset object |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
842 |
fields: ??? |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
843 |
user: ??? |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
844 |
|
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
845 |
Returns: |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
846 |
Keywords, the survey's schema and the survey content. |
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
847 |
""" |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
848 |
json = request.POST['serialized'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
849 |
json = simplejson.loads(json)['data'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
850 |
survey_content = json.pop('survey_content') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
851 |
schema = survey_content.pop('schema') |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
852 |
del json['author'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
853 |
del json['created'] |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
854 |
del json['modified'] |
2658
34b414a80d42
Several style fixes and code cleaning for surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2593
diff
changeset
|
855 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
856 |
# keywords can't be unicode |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
857 |
keywords = {} |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
858 |
for key, val in json.items(): |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
859 |
keywords[str(key)] = val |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
860 |
if 'is_featured' in keywords: |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
861 |
keywords['is_featured'] = eval(keywords['is_featured']) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
862 |
return keywords, schema, survey_content |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
863 |
|
2543
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
864 |
def getMenusForScope(self, entity, params, id, user): |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
865 |
"""List featured surveys if after the survey_start date |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
866 |
and before survey_end an iff the current user has the right taking access. |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
867 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
868 |
Args: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
869 |
entity: entity which is the scope for a Survey |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
870 |
params: params from the requesting View |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
871 |
id: GAE user instance for the current user |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
872 |
user: User entity from the current user |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
873 |
""" |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
874 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
875 |
# only list surveys for registered users |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
876 |
if not user: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
877 |
return [] |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
878 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
879 |
survey_params = self.getParams().copy() |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
880 |
survey_logic = survey_params['logic'] |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
881 |
record_logic = survey_logic.getRecordLogic() |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
882 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
883 |
# filter all featured surveys for the given entity |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
884 |
filter = { |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
885 |
'prefix' : params['url_name'], |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
886 |
'scope_path': entity.key().id_or_name(), |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
887 |
'is_featured': True, |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
888 |
} |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
889 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
890 |
survey_entities = survey_logic.getForFields(filter) |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
891 |
submenus = [] |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
892 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
893 |
# get the rights checker |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
894 |
rights = self._params['rights'] |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
895 |
rights.setCurrentUser(id, user) |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
896 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
897 |
# cache ACL |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
898 |
survey_rights = {} |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
899 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
900 |
# add a link to all featured active surveys the user can take |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
901 |
for survey_entity in survey_entities: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
902 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
903 |
if survey_entity.taking_access not in survey_rights: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
904 |
# we have not determined if this user has the given type of access |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
905 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
906 |
# check if the current user is allowed to visit the take Survey page |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
907 |
allowed_to_take = False |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
908 |
|
2546
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
909 |
try: |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
910 |
rights.checkIsSurveyTakeable( |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
911 |
{'key_name': survey_entity.key().name(), |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
912 |
'prefix': survey_entity.prefix, |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
913 |
'scope_path': survey_entity.scope_path, |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
914 |
'link_id': survey_entity.link_id, |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
915 |
'user': user}, |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
916 |
survey_logic, |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
917 |
check_time=False) |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
918 |
allowed_to_take = True |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
919 |
except: |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
920 |
pass |
df7e4291c23c
Ensure that accessViolations for Survey menu items get captured.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2543
diff
changeset
|
921 |
|
2543
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
922 |
# cache ACL for a given entity.taking_access |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
923 |
survey_rights[survey_entity.taking_access] = allowed_to_take |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
924 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
925 |
if not allowed_to_take: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
926 |
# not allowed to take this survey |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
927 |
continue |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
928 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
929 |
elif not survey_rights[survey_entity.taking_access]: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
930 |
# we already determined that the user doens't have access to this type |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
931 |
continue |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
932 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
933 |
if not timeline.isActivePeriod(survey_entity, 'survey'): |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
934 |
# this survey is not active right now |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
935 |
continue |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
936 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
937 |
# check if any SurveyRecord is available for this survey |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
938 |
filter = {'survey': survey_entity, |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
939 |
'user': user} |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
940 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
941 |
survey_record = record_logic.getForFields(filter, unique=True) |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
942 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
943 |
if survey_record: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
944 |
taken_status = "" |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
945 |
else: |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
946 |
# no SurveyRecord available so we mark the survey as new |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
947 |
taken_status = "(new)" |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
948 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
949 |
submenu = (redirects.getTakeSurveyRedirect(survey_entity, survey_params), |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
950 |
'Survey ' + taken_status + ': ' + survey_entity.short_name, |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
951 |
'show') |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
952 |
|
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
953 |
submenus.append(submenu) |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
954 |
return submenus |
4c95d717a976
Added Menu items for all three kinds of Surveys to the program menu.
James Levy <jamesalexanderlevy@gmail.com>
parents:
2542
diff
changeset
|
955 |
|
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
956 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
957 |
view = View() |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
958 |
|
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
959 |
admin = decorators.view(view.admin) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
960 |
create = decorators.view(view.create) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
961 |
edit = decorators.view(view.edit) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
962 |
export = decorators.view(view.export) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
963 |
delete = decorators.view(view.delete) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
964 |
json = decorators.view(view.exportSerialized) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
965 |
list = decorators.view(view.list) |
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
966 |
public = decorators.view(view.public) |
2722
1ec0af4ddd72
Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2659
diff
changeset
|
967 |
record = decorators.view(view.viewRecord) |
2435
dd16e9b3c2d0
Added View for Surveys.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
968 |
results = decorators.view(view.viewResults) |
2475
dfb9249d91b6
Added skeleton for the take view and its template.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2474
diff
changeset
|
969 |
take = decorators.view(view.take) |