author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 27 Sep 2009 17:46:43 +0200 | |
changeset 2979 | ba4aeaaad0a1 |
parent 2730 | d1cfed8da027 |
permissions | -rw-r--r-- |
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Helpers used for list info functions. |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
2692
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
25 |
from django.utils.translation import ugettext |
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
26 |
|
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
27 |
from soc.views.helper import redirects |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
28 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
29 |
|
2692
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
30 |
DEF_NO_RECORD_AVAILABLE_MESSAGE = ugettext('No Record Available') |
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
31 |
|
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
32 |
|
2202
f6a1c141f51e
Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2077
diff
changeset
|
33 |
def getStudentProposalInfo(ranking, proposals_keys): |
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
"""Returns a function that returns information about the rank and assignment. |
2206
4daf85a152ca
White space fix in list_info module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2202
diff
changeset
|
35 |
|
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
Args: |
2202
f6a1c141f51e
Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2077
diff
changeset
|
37 |
ranking: dict with a mapping from Student Proposal key to rank |
f6a1c141f51e
Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2077
diff
changeset
|
38 |
proposals_keys: list of proposal keys assigned a slot |
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
""" |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
|
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
def wrapper(item, _): |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
42 |
"""Wrapper method. |
2077
fd2e83a297c7
Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1926
diff
changeset
|
43 |
""" |
2202
f6a1c141f51e
Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2077
diff
changeset
|
44 |
info = {'rank': ranking[item.key()]} |
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
|
2202
f6a1c141f51e
Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2077
diff
changeset
|
46 |
if item.key() in proposals_keys: |
1926
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
info['item_class'] = 'selected' |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
else: |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
info['item_class'] = 'normal' |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
|
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
return info |
d73fe91beeeb
Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
return wrapper |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
53 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
54 |
|
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
55 |
def setStudentProjectSurveyInfo(list_content, program_entity): |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
56 |
"""Sets the list info to a method that returns information used in a Student |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
57 |
Project table to show how many evaluations have been available and how |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
58 |
many have been taken. |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
59 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
60 |
Args: |
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
61 |
list_content: list content for which to set the info |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
62 |
program_entity: the Program to check the total amount of |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
63 |
(Grading)ProjctSurveys for |
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
64 |
|
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
65 |
Returns: |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
66 |
The original list_content with info set |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
67 |
""" |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
68 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
69 |
from soc.logic.models.survey import grading_logic as grading_survey_logic |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
70 |
from soc.logic.models.survey import project_logic as project_survey_logic |
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
71 |
from soc.logic.models.survey_record import grading_logic |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
72 |
from soc.logic.models.survey_record import project_logic |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
73 |
|
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
74 |
if not list_content: |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
75 |
# this can happen because of the need_content parameter for getListContent |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
76 |
return list_content |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
77 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
78 |
fields = {'scope_path': program_entity.key().id_or_name()} |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
79 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
80 |
# count the number of have been active ProjectSurveys |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
81 |
project_surveys = project_survey_logic.getForFields(fields) |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
82 |
project_survey_count = len(project_surveys) |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
83 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
84 |
for project_survey in project_surveys: |
2689
18d8486fd411
Renamed hasAtLeastOneRecord to hasRecord.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2687
diff
changeset
|
85 |
if not project_survey_logic.hasRecord(project_survey): |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
86 |
project_survey_count = project_survey_count - 1 |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
87 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
88 |
# count the number of have been active GradingProjectSurveys |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
89 |
grading_surveys = grading_survey_logic.getForFields(fields) |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
90 |
grading_survey_count = len(grading_surveys) |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
91 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
92 |
for grading_survey in grading_surveys: |
2689
18d8486fd411
Renamed hasAtLeastOneRecord to hasRecord.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2687
diff
changeset
|
93 |
if not grading_survey_logic.hasRecord(grading_survey): |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
94 |
grading_survey_count = grading_survey_count - 1 |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
95 |
|
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
96 |
# Pre-store the needed info since Django calls the wrapper method for every |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
97 |
# info call. |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
98 |
info_storage = {} |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
99 |
|
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
100 |
for item in list_content['data']: |
2685
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
101 |
fields = {'project': item} |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
102 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
103 |
# count the amount of records we have on store for this project |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
104 |
project_record_count = project_logic.getQueryForFields(fields).count() |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
105 |
grading_record_count = grading_logic.getQueryForFields(fields).count() |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
106 |
|
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
107 |
info = {'project_surveys_total': project_survey_count, |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
108 |
'project_surveys_completed': project_record_count, |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
109 |
'grading_project_surveys_total': grading_survey_count, |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
110 |
'grading_project_surveys_completed': grading_record_count} |
506cda0463e8
Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2206
diff
changeset
|
111 |
|
2691
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
112 |
info_storage[item.key()] = info |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
113 |
|
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
114 |
def wrapper(item, _): |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
115 |
"""Wrapper method. |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
116 |
""" |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
117 |
return info_storage[item.key()] |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
118 |
|
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
119 |
list_content['info'] = (wrapper, None) |
f8e0a007d99b
Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2689
diff
changeset
|
120 |
return list_content |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
121 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
122 |
|
2730
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
123 |
def setProjectSurveyInfoForProject(list_content, project_entity, |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
124 |
survey_params): |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
125 |
"""Sets the list info to a function for the given list. |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
126 |
|
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
127 |
This function contains the information used for showing ProjectSurvey |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
128 |
records on the StudentProject manage page. |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
129 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
130 |
Args: |
2730
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
131 |
list_content: list content for which to set the info |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
132 |
project_entity: a StudentProject entity |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
133 |
survey_params: params for the view of the type of Survey that is listed |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
134 |
""" |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
135 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
136 |
survey_logic = survey_params['logic'] |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
137 |
record_logic = survey_logic.getRecordLogic() |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
138 |
|
2730
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
139 |
# store the needed info since Django calls the wrapper method for every |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
140 |
# info call. |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
141 |
info_storage = {} |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
142 |
|
2730
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
143 |
for survey_entity in list_content['data']: |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
144 |
# try to retrieve the SurveyRecord for the given Survey and Project |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
145 |
fields = {'survey': survey_entity, |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
146 |
'project': project_entity} |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
147 |
record_entity = record_logic.getForFields(fields, unique=True) |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
148 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
149 |
info = {'record': record_entity} |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
150 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
151 |
if record_entity: |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
152 |
# SurveyRecord has been found store the import data in info |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
153 |
info['taken_by'] = record_entity.user.name |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
154 |
info['taken_on'] = record_entity.modified |
2729
f7d4e2c3b697
Added redirect to the StudentProject manage page for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2692
diff
changeset
|
155 |
info['record_url'] = redirects.getViewSurveyRecordRedirect(record_entity, |
f7d4e2c3b697
Added redirect to the StudentProject manage page for viewing SurveyRecords.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2692
diff
changeset
|
156 |
survey_params) |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
157 |
else: |
2692
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
158 |
info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE |
b57572c43b32
Factored out the "No Record Available" message.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2691
diff
changeset
|
159 |
info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE |
2687
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
160 |
|
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
161 |
take_redirect_info = {'survey': survey_entity, |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
162 |
'params': survey_params} |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
163 |
info['take_url'] = redirects.getTakeProjectSurveyRedirect( |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
164 |
project_entity, take_redirect_info) |
1e2bcc7f6d3a
Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2685
diff
changeset
|
165 |
|
2730
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
166 |
info_storage[survey_entity.key()] = info |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
167 |
|
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
168 |
def wrapper(item, _): |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
169 |
"""Wrapper method. |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
170 |
""" |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
171 |
return info_storage[item.key()] |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
172 |
|
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
173 |
list_content['info'] = (wrapper, None) |
d1cfed8da027
Redone the list_info function for the Project's manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2729
diff
changeset
|
174 |
return list_content |