app/soc/views/helper/list_info.py
changeset 2685 506cda0463e8
parent 2206 4daf85a152ca
child 2687 1e2bcc7f6d3a
equal deleted inserted replaced
2684:08ec7ca16dce 2685:506cda0463e8
    29     ranking: dict with a mapping from Student Proposal key to rank
    29     ranking: dict with a mapping from Student Proposal key to rank
    30     proposals_keys: list of proposal keys assigned a slot
    30     proposals_keys: list of proposal keys assigned a slot
    31   """
    31   """
    32 
    32 
    33   def wrapper(item, _):
    33   def wrapper(item, _):
    34     """Decorator wrapper method.
    34     """Wrapper method.
    35     """
    35     """
    36     info = {'rank': ranking[item.key()]}
    36     info = {'rank': ranking[item.key()]}
    37 
    37 
    38     if item.key() in proposals_keys:
    38     if item.key() in proposals_keys:
    39       info['item_class'] =  'selected'
    39       info['item_class'] =  'selected'
    40     else:
    40     else:
    41       info['item_class'] =  'normal'
    41       info['item_class'] =  'normal'
    42 
    42 
    43     return info
    43     return info
    44   return wrapper
    44   return wrapper
       
    45 
       
    46 
       
    47 def getStudentProjectSurveyInfo(program_entity):
       
    48   """Returns a function that returns information used in a Student Project
       
    49   table to show how many evaluations have been available and how
       
    50   many have been taken.
       
    51 
       
    52   Args:
       
    53     program_entity: the program to check the total amount of
       
    54                     (Grading)ProjctSurveys for
       
    55   """
       
    56 
       
    57   from soc.logic.models.survey import grading_logic as grading_survey_logic
       
    58   from soc.logic.models.survey import project_logic as project_survey_logic
       
    59 
       
    60   fields = {'scope_path': program_entity.key().id_or_name()}
       
    61 
       
    62   # count the number of have been active ProjectSurveys
       
    63   project_surveys = project_survey_logic.getForFields(fields)
       
    64   project_survey_count = len(project_surveys)
       
    65 
       
    66   for project_survey in project_surveys:
       
    67     if not project_survey_logic.hasAtLeastOneRecord(project_survey):
       
    68       project_survey_count = project_survey_count - 1
       
    69 
       
    70   # count the number of have been active GradingProjectSurveys
       
    71   grading_surveys = grading_survey_logic.getForFields(fields)
       
    72   grading_survey_count = len(grading_surveys)
       
    73 
       
    74   for grading_survey in grading_surveys:
       
    75     if not grading_survey_logic.hasAtLeastOneRecord(grading_survey):
       
    76       grading_survey_count = grading_survey_count - 1
       
    77 
       
    78   def wrapper(item, _):
       
    79     """Wrapper method.
       
    80     """
       
    81 
       
    82     from soc.logic.models.survey_record import grading_logic
       
    83     from soc.logic.models.survey_record import project_logic
       
    84 
       
    85     fields = {'project': item}
       
    86 
       
    87     # count the amount of records we have on store for this project
       
    88     project_record_count = project_logic.getQueryForFields(fields).count()
       
    89     grading_record_count = grading_logic.getQueryForFields(fields).count()
       
    90 
       
    91     info = {'project_surveys_total': project_survey_count,
       
    92             'project_surveys_completed': project_record_count,
       
    93             'grading_project_surveys_total': grading_survey_count,
       
    94             'grading_project_surveys_completed': grading_record_count}
       
    95 
       
    96     return info
       
    97   return wrapper