# HG changeset patch # User Lennard de Rijk # Date 1248939795 -7200 # Node ID 1e2bcc7f6d3a1ad587a0ada81e807fe6a8f8dd79 # Parent ada26cef0b068c45759bb19d1fca19be52b0efcb Added getProjectSurveyInfoForProject to list_info helper. diff -r ada26cef0b06 -r 1e2bcc7f6d3a app/soc/views/helper/list_info.py --- a/app/soc/views/helper/list_info.py Thu Jul 30 09:29:36 2009 +0200 +++ b/app/soc/views/helper/list_info.py Thu Jul 30 09:43:15 2009 +0200 @@ -22,6 +22,9 @@ ] +from soc.views.helper import redirects + + def getStudentProposalInfo(ranking, proposals_keys): """Returns a function that returns information about the rank and assignment. @@ -95,3 +98,46 @@ return info return wrapper + + +def getProjectSurveyInfoForProject(project_entity, survey_params): + """Returns a function that returns info for listing Surveys and if possible + their accompanying record. + + Args: + project_entity: a StudentProject entity + survey_params: params for the view of the type of Survey that is listed + """ + + survey_logic = survey_params['logic'] + record_logic = survey_logic.getRecordLogic() + + def wrapper(survey_entity, _): + """Wrapper method. + + Args: + survey_entity: a ProjectSurvey (or subclass) entity + """ + + # try to retrieve the SurveyRecord for the given Survey and Project + fields = {'survey': survey_entity, + 'project': project_entity} + record_entity = record_logic.getForFields(fields, unique=True) + + info = {'record': record_entity} + + if record_entity: + # SurveyRecord has been found store the import data in info + info['taken_by'] = record_entity.user.name + info['taken_on'] = record_entity.modified + else: + info['taken_by'] = 'No Record Available' + info['taken_on'] = 'No Record Available' + + take_redirect_info = {'survey': survey_entity, + 'params': survey_params} + info['take_url'] = redirects.getTakeProjectSurveyRedirect( + project_entity, take_redirect_info) + + return info + return wrapper