app/soc/views/helper/list_info.py
changeset 2687 1e2bcc7f6d3a
parent 2685 506cda0463e8
child 2689 18d8486fd411
equal deleted inserted replaced
2686:ada26cef0b06 2687:1e2bcc7f6d3a
    18 """
    18 """
    19 
    19 
    20 __authors__ = [
    20 __authors__ = [
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    21   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    22   ]
    22   ]
       
    23 
       
    24 
       
    25 from soc.views.helper import redirects
    23 
    26 
    24 
    27 
    25 def getStudentProposalInfo(ranking, proposals_keys):
    28 def getStudentProposalInfo(ranking, proposals_keys):
    26   """Returns a function that returns information about the rank and assignment.
    29   """Returns a function that returns information about the rank and assignment.
    27 
    30 
    93             'grading_project_surveys_total': grading_survey_count,
    96             'grading_project_surveys_total': grading_survey_count,
    94             'grading_project_surveys_completed': grading_record_count}
    97             'grading_project_surveys_completed': grading_record_count}
    95 
    98 
    96     return info
    99     return info
    97   return wrapper
   100   return wrapper
       
   101 
       
   102 
       
   103 def getProjectSurveyInfoForProject(project_entity, survey_params):
       
   104   """Returns a function that returns info for listing Surveys and if possible
       
   105   their accompanying record.
       
   106 
       
   107   Args:
       
   108     project_entity: a StudentProject entity
       
   109     survey_params: params for the view of the type of Survey that is listed
       
   110   """
       
   111 
       
   112   survey_logic = survey_params['logic']
       
   113   record_logic = survey_logic.getRecordLogic()
       
   114 
       
   115   def wrapper(survey_entity, _):
       
   116     """Wrapper method.
       
   117 
       
   118     Args:
       
   119       survey_entity: a ProjectSurvey (or subclass) entity
       
   120     """
       
   121 
       
   122     # try to retrieve the SurveyRecord for the given Survey and Project
       
   123     fields = {'survey': survey_entity,
       
   124               'project': project_entity}
       
   125     record_entity = record_logic.getForFields(fields, unique=True)
       
   126 
       
   127     info = {'record': record_entity}
       
   128 
       
   129     if record_entity:
       
   130       # SurveyRecord has been found store the import data in info
       
   131       info['taken_by'] = record_entity.user.name
       
   132       info['taken_on'] = record_entity.modified
       
   133     else:
       
   134       info['taken_by'] = 'No Record Available'
       
   135       info['taken_on'] = 'No Record Available'
       
   136 
       
   137     take_redirect_info = {'survey': survey_entity,
       
   138                           'params': survey_params}
       
   139     info['take_url'] = redirects.getTakeProjectSurveyRedirect(
       
   140         project_entity, take_redirect_info)
       
   141 
       
   142     return info
       
   143   return wrapper