author | Daniel Diniz <ajaksu@gmail.com> |
Fri, 10 Jul 2009 12:06:29 +0200 | |
changeset 2585 | 37584af2420e |
parent 2580 | cd3b42f52b21 |
child 2586 | 283bb903b216 |
permissions | -rw-r--r-- |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Views for GradingSurveyGroup. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
21 |
'"Daniel Diniz" <ajaksu@gmail.com>', |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
26 |
import time |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
27 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
28 |
from google.appengine.ext.db import djangoforms |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
29 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
31 |
from soc.logic.models.program import logic as program_logic |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
32 |
from soc.logic.models.survey import grading_logic |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
33 |
from soc.logic.models.survey import project_logic |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
34 |
from soc.logic.models.user import logic as user_logic |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
35 |
from soc.logic.models.grading_survey_group import logic as survey_group_logic |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
36 |
from soc.models.grading_survey_group import GradingSurveyGroup |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
37 |
from soc.models.grading_project_survey import GradingProjectSurvey |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
38 |
from soc.models.project_survey import ProjectSurvey |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
from soc.views.helper import access |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
40 |
from soc.views.helper import decorators |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
41 |
from soc.views.helper import redirects |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
from soc.views.models import base |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
44 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
45 |
class GroupForm(djangoforms.ModelForm): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
46 |
"""Form for creating a GradingSurveyGroup. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
47 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
48 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
49 |
grading_survey = djangoforms.ModelChoiceField(GradingProjectSurvey) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
50 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
51 |
student_survey = djangoforms.ModelChoiceField(ProjectSurvey, required=False) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
52 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
53 |
def __init__(self, *args, **kwargs): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
54 |
"""Process field names for readable display and initialize form. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
55 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
56 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
57 |
# use survey titles in drop-downs |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
58 |
self.choiceTitles('grading_survey', grading_logic) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
59 |
self.choiceTitles('student_survey', project_logic) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
60 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
61 |
super(GroupForm, self).__init__(*args, **kwargs) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
62 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
63 |
def choiceTitles(self, field, logic): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
64 |
"""Fetch entity titles for choice field entries. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
65 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
66 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
67 |
# TODO(ajaksu): subclass ModelChoiceField so we don't need this method |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
68 |
choice_list = [] |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
69 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
70 |
model = logic.getModel() |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
71 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
72 |
for value, text in tuple(self.base_fields[field].choices): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
73 |
if value: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
74 |
entity = model.get(value) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
75 |
text = entity.title |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
76 |
choice_list.append((value,text)) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
77 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
78 |
choices = tuple(choice_list) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
79 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
80 |
self.base_fields[field].choices = choices |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
81 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
82 |
class Meta: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
83 |
"""Inner Meta class for fetching fields from model. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
84 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
85 |
model = GradingSurveyGroup |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
86 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
87 |
# exclude the necessary fields from the form |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
88 |
exclude = ['link_id', 'scope', 'scope_path', 'last_update_started', |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
89 |
'last_update_complete'] |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
90 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
91 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
92 |
class View(base.View): |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
93 |
"""View methods for the GradingSurveyGroup model. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
94 |
""" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
95 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
96 |
def __init__(self, params=None): |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
97 |
"""Defines the fields and methods required for the base View class |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
98 |
to provide the user with list, public, create, edit and delete views. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
99 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
100 |
Params: |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
101 |
params: a dict with params for this View |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
102 |
""" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
103 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
104 |
rights = access.Checker(params) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
105 |
rights['create'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
106 |
rights['edit'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
107 |
rights['delete'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
108 |
rights['show'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
109 |
rights['list'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
110 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
111 |
new_params = {} |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
112 |
new_params['logic'] = survey_group_logic |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
113 |
new_params['rights'] = rights |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
114 |
new_params['name'] = "Grading Survey Group" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
115 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
116 |
new_params['no_admin'] = True |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
117 |
new_params['no_create_raw'] = True |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
118 |
new_params['no_create_with_key_fields'] = True |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
119 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
120 |
new_params['create_form'] = GroupForm |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
121 |
new_params['edit_form'] = GroupForm |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
122 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
123 |
params = dicts.merge(params, new_params) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
124 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
125 |
super(View, self).__init__(params=params) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
126 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
127 |
@decorators.merge_params |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
128 |
@decorators.check_access |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
129 |
def create(self, request, access_type, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
130 |
page_name=None, params=None, **kwargs): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
131 |
"""Pass the correct survey queries to GroupForm. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
132 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
133 |
For params see base.View.create(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
134 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
135 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
136 |
self.setQueries(kwargs['scope_path'], params) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
137 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
138 |
return super(View, self).create(request, access_type, page_name=page_name, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
139 |
params=params, **kwargs) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
140 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
141 |
@decorators.merge_params |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
142 |
@decorators.check_access |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
143 |
def edit(self, request, access_type, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
144 |
page_name=None, params=None, seed=None, **kwargs): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
145 |
"""Pass the correct survey queries to GroupForm. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
146 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
147 |
For params see base.View.edit(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
148 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
149 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
150 |
self.setQueries(kwargs['scope_path'], params) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
151 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
152 |
return super(View, self).edit(request, access_type, page_name=page_name, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
153 |
params=params, seed=seed, **kwargs) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
154 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
155 |
def _editPost(self, request, entity, fields): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
156 |
"""See base.View._editPost(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
157 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
158 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
159 |
if not entity: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
160 |
# generate a unique link_id |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
161 |
fields['link_id'] = 't%i' % (int(time.time()*100)) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
162 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
163 |
# TODO: seriously redesign _editPost to pass along kwargs |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
164 |
fields['scope_path'] = fields['grading_survey'].scope_path |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
165 |
else: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
166 |
fields['link_id'] = entity.link_id |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
167 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
168 |
# fill in the scope via call to super |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
169 |
super(View, self)._editPost(request, entity, fields) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
170 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
171 |
def setQueries(self, program, params): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
172 |
"""Add program filtering queries to the GroupForm. |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
173 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
174 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
175 |
# fetch the program |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
176 |
program = program_logic.getFromKeyNameOr404(program) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
177 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
178 |
# filter grading surveys by program and use title for display |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
179 |
grading_query = grading_logic.getQueryForFields(filter={'scope':program}) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
180 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
181 |
# filter project surveys by program and use title for display |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
182 |
student_query = project_logic.getQueryForFields(filter={'scope':program}) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
183 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
184 |
if params.get('edit_form'): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
185 |
params['edit_form'].base_fields['student_survey'].query = student_query |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
186 |
params['edit_form'].base_fields['grading_survey'].query = grading_query |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
187 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
188 |
if params.get('create_form'): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
189 |
params['create_form'].base_fields['student_survey'].query = student_query |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
190 |
params['create_form'].base_fields['grading_survey'].query = grading_query |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
191 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
192 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
193 |
view = View() |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
194 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
195 |
create = decorators.view(view.create) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
196 |
edit = decorators.view(view.edit) |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
197 |
delete = decorators.view(view.delete) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
198 |
list = decorators.view(view.list) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
199 |
public = decorators.view(view.public) |