app/soc/views/helper/list_info.py
changeset 2730 d1cfed8da027
parent 2729 f7d4e2c3b697
equal deleted inserted replaced
2729:f7d4e2c3b697 2730:d1cfed8da027
   118 
   118 
   119   list_content['info'] = (wrapper, None)
   119   list_content['info'] = (wrapper, None)
   120   return list_content
   120   return list_content
   121 
   121 
   122 
   122 
   123 def getProjectSurveyInfoForProject(project_entity, survey_params):
   123 def setProjectSurveyInfoForProject(list_content, project_entity,
   124   """Returns a function that returns info for listing Surveys and if possible
   124                                    survey_params):
   125   their accompanying record.
   125   """Sets the list info to a function for the given list.
       
   126   
       
   127   This function contains the information used for showing ProjectSurvey
       
   128   records on the StudentProject manage page.
   126 
   129 
   127   Args:
   130   Args:
       
   131     list_content: list content for which to set the info
   128     project_entity: a StudentProject entity
   132     project_entity: a StudentProject entity
   129     survey_params: params for the view of the type of Survey that is listed
   133     survey_params: params for the view of the type of Survey that is listed
   130   """
   134   """
   131 
   135 
   132   survey_logic = survey_params['logic']
   136   survey_logic = survey_params['logic']
   133   record_logic = survey_logic.getRecordLogic()
   137   record_logic = survey_logic.getRecordLogic()
   134 
   138 
   135   def wrapper(survey_entity, _):
   139   # store the needed info since Django calls the wrapper method for every
   136     """Wrapper method.
   140   # info call.
       
   141   info_storage = {}
   137 
   142 
   138     Args:
   143   for survey_entity in list_content['data']:
   139       survey_entity: a ProjectSurvey (or subclass) entity
       
   140     """
       
   141 
       
   142     # try to retrieve the SurveyRecord for the given Survey and Project
   144     # try to retrieve the SurveyRecord for the given Survey and Project
   143     fields = {'survey': survey_entity,
   145     fields = {'survey': survey_entity,
   144               'project': project_entity}
   146               'project': project_entity}
   145     record_entity = record_logic.getForFields(fields, unique=True)
   147     record_entity = record_logic.getForFields(fields, unique=True)
   146 
   148 
   159     take_redirect_info = {'survey': survey_entity,
   161     take_redirect_info = {'survey': survey_entity,
   160                           'params': survey_params}
   162                           'params': survey_params}
   161     info['take_url'] = redirects.getTakeProjectSurveyRedirect(
   163     info['take_url'] = redirects.getTakeProjectSurveyRedirect(
   162         project_entity, take_redirect_info)
   164         project_entity, take_redirect_info)
   163 
   165 
   164     return info
   166     info_storage[survey_entity.key()] = info
   165   return wrapper
   167 
       
   168   def wrapper(item, _):
       
   169     """Wrapper method.
       
   170     """
       
   171     return info_storage[item.key()]
       
   172 
       
   173   list_content['info'] = (wrapper, None)
       
   174   return list_content