author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 12 Jul 2009 14:03:35 +0200 | |
changeset 2610 | 95949d4c45d9 |
parent 2589 | 2ecd4df2c9c7 |
child 2612 | 216002ba6b86 |
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 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
30 |
from django import forms |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
31 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic import dicts |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
from soc.views.helper import decorators |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
43 |
from soc.views.helper import redirects |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
from soc.views.models import base |
2610
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
45 |
from soc.views.models import program as program_view |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
47 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
class View(base.View): |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
"""View methods for the GradingSurveyGroup model. |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
""" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
def __init__(self, params=None): |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
"""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
|
54 |
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
|
55 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
Params: |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
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
|
58 |
""" |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
rights = access.Checker(params) |
2610
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
61 |
rights['create'] = ['checkIsHostForProgramInScope'] |
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
62 |
rights['edit'] = ['checkIsHostForProgramInScope'] |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
rights['delete'] = ['checkIsDeveloper'] |
2610
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
64 |
rights['show'] = ['checkIsHostForProgramInScope'] |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
rights['list'] = ['checkIsDeveloper'] |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
new_params = {} |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
68 |
new_params['logic'] = survey_group_logic |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
new_params['rights'] = rights |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
new_params['name'] = "Grading Survey Group" |
2586
283bb903b216
Added GradingSurveyGroup to the sitemap and sidebar.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2585
diff
changeset
|
71 |
new_params['sidebar_grouping'] = "Surveys" |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
|
2610
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
73 |
new_params['scope_view'] = program_view |
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
74 |
new_params['scope_redirect'] = redirects.getCreateRedirect |
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
75 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
new_params['no_admin'] = True |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
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
|
78 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
79 |
new_params['create_extra_dynaproperties'] = { |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
80 |
'grading_survey': djangoforms.ModelChoiceField( |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
81 |
GradingProjectSurvey, required=True), |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
82 |
'student_survey': djangoforms.ModelChoiceField(ProjectSurvey, |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
83 |
required=False), |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
84 |
} |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
85 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
86 |
new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path', |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
87 |
'last_update_started', |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
88 |
'last_update_complete'] |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
89 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
90 |
new_params['edit_extra_dynaproperties'] = { |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
91 |
'link_id': forms.CharField(widget=forms.HiddenInput), |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
92 |
} |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
93 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
94 |
params = dicts.merge(params, new_params) |
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 |
super(View, self).__init__(params=params) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
97 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
98 |
@decorators.merge_params |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
99 |
@decorators.check_access |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
100 |
def create(self, request, access_type, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
101 |
page_name=None, params=None, **kwargs): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
102 |
"""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
|
103 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
104 |
For params see base.View.create(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
105 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
106 |
|
2610
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
107 |
if kwargs.get('scope_path'): |
95949d4c45d9
Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2589
diff
changeset
|
108 |
self.setQueries(kwargs['scope_path'], params['create_form']) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
109 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
110 |
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
|
111 |
params=params, **kwargs) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
112 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
113 |
@decorators.merge_params |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
114 |
@decorators.check_access |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
115 |
def edit(self, request, access_type, |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
116 |
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
|
117 |
"""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
|
118 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
119 |
For params see base.View.edit(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
120 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
121 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
122 |
self.setQueries(kwargs['scope_path'], params['edit_form']) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
123 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
124 |
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
|
125 |
params=params, seed=seed, **kwargs) |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
126 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
127 |
def _editGet(self, request, entity, form): |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
128 |
"""Performs any required processing on the form to get its edit page. |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
129 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
130 |
Args: |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
131 |
request: the django request object |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
132 |
entity: the entity to get |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
133 |
form: the django form that will be used for the page |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
134 |
""" |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
135 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
136 |
form.fields['link_id'].initial = entity.link_id |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
137 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
138 |
return super(View,self)._editGet(request, entity,form) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
139 |
|
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
140 |
def _editPost(self, request, entity, fields): |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
141 |
"""See base.View._editPost(). |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
142 |
""" |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
143 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
144 |
if not entity: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
145 |
# generate a unique link_id |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
146 |
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
|
147 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
148 |
# 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
|
149 |
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
|
150 |
else: |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
151 |
fields['link_id'] = entity.link_id |
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
152 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
153 |
# fill in the scope via call to super |
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
154 |
return super(View, self)._editPost(request, entity, fields) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
155 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
156 |
def setQueries(self, program_keyname, group_form): |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
157 |
"""Add program filtering queries to the GroupForm. |
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
158 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
159 |
Args: |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
160 |
program_keyname: keyname of the program to filter on |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
161 |
group_form: DynaForm instance to set the queries for |
2585
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 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
164 |
# fetch the program |
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
165 |
program = program_logic.getFromKeyNameOr404(program_keyname) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
166 |
|
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
167 |
# filter grading surveys by program and use title for display |
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
168 |
grading_query = grading_logic.getQueryForFields( |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
169 |
filter={'scope_path':program_keyname}) |
2585
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 |
# filter project surveys by program and use title for display |
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
172 |
student_query = project_logic.getQueryForFields( |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
173 |
filter={'scope_path':program_keyname}) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
174 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
175 |
group_form.base_fields['grading_survey'].query = grading_query |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
176 |
group_form.base_fields['student_survey'].query = student_query |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
177 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
178 |
# use survey titles in drop-downs |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
179 |
self.choiceTitles(group_form, 'grading_survey', grading_logic) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
180 |
self.choiceTitles(group_form, 'student_survey', project_logic) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
181 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
182 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
183 |
def choiceTitles(self, group_form, field, logic): |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
184 |
"""Fetch entity titles for choice field entries. |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
185 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
186 |
Args: |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
187 |
group_form: The form to set the choice field entries for |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
188 |
field: the field_name to set the choice entries for |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
189 |
logic: the logic for the model to set the choice entries for |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
190 |
""" |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
191 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
192 |
# TODO(ajaksu): subclass ModelChoiceField so we don't need this method |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
193 |
choice_list = [] |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
194 |
|
2589
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
195 |
model = logic.getModel() |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
196 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
197 |
for value, text in tuple(group_form.base_fields[field].choices): |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
198 |
if value: |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
199 |
entity = model.get(value) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
200 |
text = '%s (%s)' % (entity.title, entity.link_id) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
201 |
choice_list.append((value,text)) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
202 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
203 |
choices = tuple(choice_list) |
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
204 |
|
2ecd4df2c9c7
GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2586
diff
changeset
|
205 |
group_form.base_fields[field].choices = choices |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
206 |
|
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
207 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
208 |
view = View() |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
209 |
|
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
210 |
create = decorators.view(view.create) |
2585
37584af2420e
Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents:
2580
diff
changeset
|
211 |
edit = decorators.view(view.edit) |
2580
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
212 |
delete = decorators.view(view.delete) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
213 |
list = decorators.view(view.list) |
cd3b42f52b21
Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
214 |
public = decorators.view(view.public) |