app/soc/views/helper/list_info.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 30 Jul 2009 10:49:19 +0200
changeset 2691 f8e0a007d99b
parent 2689 18d8486fd411
child 2692 b57572c43b32
permissions -rw-r--r--
Pre-storing the information for setStudentProjectSurveyInfo. This is a rename from getStudentProjectSurveyInfo because it now sets the info directly in the list content. This is done because Django queries the wrapper method every time the info is called in the template.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Helpers used for list info functions.
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
2687
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
    25
from soc.views.helper import redirects
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
    26
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
    27
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    28
def getStudentProposalInfo(ranking, proposals_keys):
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
  """Returns a function that returns information about the rank and assignment.
2206
4daf85a152ca White space fix in list_info module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2202
diff changeset
    30
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
  Args:
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    32
    ranking: dict with a mapping from Student Proposal key to rank
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    33
    proposals_keys: list of proposal keys assigned a slot
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
  """
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
  def wrapper(item, _):
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    37
    """Wrapper method.
2077
fd2e83a297c7 Style fixes, add missing docstring, fix some wrong calls to super classes and removal of unused imports in soc.views.helper.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1926
diff changeset
    38
    """
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    39
    info = {'rank': ranking[item.key()]}
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    41
    if item.key() in proposals_keys:
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
      info['item_class'] =  'selected'
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
    else:
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
      info['item_class'] =  'normal'
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    return info
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
  return wrapper
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    48
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    49
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    50
def setStudentProjectSurveyInfo(list_content, program_entity):
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    51
  """Sets the list info to a method that returns information used in a Student
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    52
  Project table to show how many evaluations have been available and how
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    53
  many have been taken.
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    54
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    55
  Args:
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    56
    list_content: list content for which to set the info
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    57
    program_entity: the Program to check the total amount of
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    58
                    (Grading)ProjctSurveys for
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    59
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    60
  Returns:
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    61
    The original list_content with info set
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    62
  """
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    63
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    64
  from soc.logic.models.survey import grading_logic as grading_survey_logic
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    65
  from soc.logic.models.survey import project_logic as project_survey_logic
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    66
  from soc.logic.models.survey_record import grading_logic
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    67
  from soc.logic.models.survey_record import project_logic
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    68
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    69
  if not list_content:
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    70
    # this can happen because of the need_content parameter for getListContent
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    71
    return list_content
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    72
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    73
  fields = {'scope_path': program_entity.key().id_or_name()}
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    74
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    75
  # count the number of have been active ProjectSurveys
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    76
  project_surveys = project_survey_logic.getForFields(fields)
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    77
  project_survey_count = len(project_surveys)
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    78
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    79
  for project_survey in project_surveys:
2689
18d8486fd411 Renamed hasAtLeastOneRecord to hasRecord.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2687
diff changeset
    80
    if not project_survey_logic.hasRecord(project_survey):
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    81
      project_survey_count = project_survey_count - 1
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    82
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    83
  # count the number of have been active GradingProjectSurveys
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    84
  grading_surveys = grading_survey_logic.getForFields(fields)
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    85
  grading_survey_count = len(grading_surveys)
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    86
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    87
  for grading_survey in grading_surveys:
2689
18d8486fd411 Renamed hasAtLeastOneRecord to hasRecord.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2687
diff changeset
    88
    if not grading_survey_logic.hasRecord(grading_survey):
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    89
      grading_survey_count = grading_survey_count - 1
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    90
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    91
  # Pre-store the needed info since Django calls the wrapper method for every
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    92
  # info call.
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    93
  info_storage = {}
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    94
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
    95
  for item in list_content['data']:
2685
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    96
    fields = {'project': item}
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    97
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    98
    # count the amount of records we have on store for this project
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    99
    project_record_count = project_logic.getQueryForFields(fields).count()
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   100
    grading_record_count = grading_logic.getQueryForFields(fields).count()
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   101
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   102
    info = {'project_surveys_total': project_survey_count,
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   103
            'project_surveys_completed': project_record_count,
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   104
            'grading_project_surveys_total': grading_survey_count,
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   105
            'grading_project_surveys_completed': grading_record_count}
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
   106
2691
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   107
    info_storage[item.key()] = info
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   108
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   109
  def wrapper(item, _):
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   110
    """Wrapper method.
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   111
    """
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   112
    return info_storage[item.key()]
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   113
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   114
  list_content['info'] = (wrapper, None)
f8e0a007d99b Pre-storing the information for setStudentProjectSurveyInfo.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2689
diff changeset
   115
  return list_content
2687
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   116
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   117
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   118
def getProjectSurveyInfoForProject(project_entity, survey_params):
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   119
  """Returns a function that returns info for listing Surveys and if possible
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   120
  their accompanying record.
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   121
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   122
  Args:
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   123
    project_entity: a StudentProject entity
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   124
    survey_params: params for the view of the type of Survey that is listed
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   125
  """
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   126
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   127
  survey_logic = survey_params['logic']
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   128
  record_logic = survey_logic.getRecordLogic()
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   129
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   130
  def wrapper(survey_entity, _):
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   131
    """Wrapper method.
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   132
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   133
    Args:
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   134
      survey_entity: a ProjectSurvey (or subclass) entity
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   135
    """
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   136
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   137
    # try to retrieve the SurveyRecord for the given Survey and Project
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   138
    fields = {'survey': survey_entity,
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   139
              'project': project_entity}
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   140
    record_entity = record_logic.getForFields(fields, unique=True)
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   141
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   142
    info = {'record': record_entity}
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   143
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   144
    if record_entity:
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   145
      # SurveyRecord has been found store the import data in info
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   146
      info['taken_by'] = record_entity.user.name
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   147
      info['taken_on'] = record_entity.modified
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   148
    else:
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   149
      info['taken_by'] = 'No Record Available'
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   150
      info['taken_on'] = 'No Record Available'
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   151
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   152
    take_redirect_info = {'survey': survey_entity,
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   153
                          'params': survey_params}
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   154
    info['take_url'] = redirects.getTakeProjectSurveyRedirect(
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   155
        project_entity, take_redirect_info)
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   156
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   157
    return info
1e2bcc7f6d3a Added getProjectSurveyInfoForProject to list_info helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2685
diff changeset
   158
  return wrapper