45 |
45 |
46 return info |
46 return info |
47 return wrapper |
47 return wrapper |
48 |
48 |
49 |
49 |
50 def getStudentProjectSurveyInfo(program_entity): |
50 def setStudentProjectSurveyInfo(list_content, program_entity): |
51 """Returns a function that returns information used in a Student Project |
51 """Sets the list info to a method that returns information used in a Student |
52 table to show how many evaluations have been available and how |
52 Project table to show how many evaluations have been available and how |
53 many have been taken. |
53 many have been taken. |
54 |
54 |
55 Args: |
55 Args: |
56 program_entity: the program to check the total amount of |
56 list_content: list content for which to set the info |
|
57 program_entity: the Program to check the total amount of |
57 (Grading)ProjctSurveys for |
58 (Grading)ProjctSurveys for |
|
59 |
|
60 Returns: |
|
61 The original list_content with info set |
58 """ |
62 """ |
59 |
63 |
60 from soc.logic.models.survey import grading_logic as grading_survey_logic |
64 from soc.logic.models.survey import grading_logic as grading_survey_logic |
61 from soc.logic.models.survey import project_logic as project_survey_logic |
65 from soc.logic.models.survey import project_logic as project_survey_logic |
|
66 from soc.logic.models.survey_record import grading_logic |
|
67 from soc.logic.models.survey_record import project_logic |
|
68 |
|
69 if not list_content: |
|
70 # this can happen because of the need_content parameter for getListContent |
|
71 return list_content |
62 |
72 |
63 fields = {'scope_path': program_entity.key().id_or_name()} |
73 fields = {'scope_path': program_entity.key().id_or_name()} |
64 |
74 |
65 # count the number of have been active ProjectSurveys |
75 # count the number of have been active ProjectSurveys |
66 project_surveys = project_survey_logic.getForFields(fields) |
76 project_surveys = project_survey_logic.getForFields(fields) |
76 |
86 |
77 for grading_survey in grading_surveys: |
87 for grading_survey in grading_surveys: |
78 if not grading_survey_logic.hasRecord(grading_survey): |
88 if not grading_survey_logic.hasRecord(grading_survey): |
79 grading_survey_count = grading_survey_count - 1 |
89 grading_survey_count = grading_survey_count - 1 |
80 |
90 |
81 def wrapper(item, _): |
91 # Pre-store the needed info since Django calls the wrapper method for every |
82 """Wrapper method. |
92 # info call. |
83 """ |
93 info_storage = {} |
84 |
94 |
85 from soc.logic.models.survey_record import grading_logic |
95 for item in list_content['data']: |
86 from soc.logic.models.survey_record import project_logic |
|
87 |
|
88 fields = {'project': item} |
96 fields = {'project': item} |
89 |
97 |
90 # count the amount of records we have on store for this project |
98 # count the amount of records we have on store for this project |
91 project_record_count = project_logic.getQueryForFields(fields).count() |
99 project_record_count = project_logic.getQueryForFields(fields).count() |
92 grading_record_count = grading_logic.getQueryForFields(fields).count() |
100 grading_record_count = grading_logic.getQueryForFields(fields).count() |
94 info = {'project_surveys_total': project_survey_count, |
102 info = {'project_surveys_total': project_survey_count, |
95 'project_surveys_completed': project_record_count, |
103 'project_surveys_completed': project_record_count, |
96 'grading_project_surveys_total': grading_survey_count, |
104 'grading_project_surveys_total': grading_survey_count, |
97 'grading_project_surveys_completed': grading_record_count} |
105 'grading_project_surveys_completed': grading_record_count} |
98 |
106 |
99 return info |
107 info_storage[item.key()] = info |
100 return wrapper |
108 |
|
109 def wrapper(item, _): |
|
110 """Wrapper method. |
|
111 """ |
|
112 return info_storage[item.key()] |
|
113 |
|
114 list_content['info'] = (wrapper, None) |
|
115 return list_content |
101 |
116 |
102 |
117 |
103 def getProjectSurveyInfoForProject(project_entity, survey_params): |
118 def getProjectSurveyInfoForProject(project_entity, survey_params): |
104 """Returns a function that returns info for listing Surveys and if possible |
119 """Returns a function that returns info for listing Surveys and if possible |
105 their accompanying record. |
120 their accompanying record. |