app/soc/views/helper/list_info.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 30 Jul 2009 09:29:36 +0200
changeset 2686 ada26cef0b06
parent 2685 506cda0463e8
child 2687 1e2bcc7f6d3a
permissions -rw-r--r--
Added new table templates for showing Suryves on the Project manage page. Note that a system for showing SurveyRecords still needs to be committed.
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
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    25
def getStudentProposalInfo(ranking, proposals_keys):
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
  """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
    27
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
  Args:
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    29
    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
    30
    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
    31
  """
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
  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
    34
    """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
    35
    """
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    36
    info = {'rank': ranking[item.key()]}
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
2202
f6a1c141f51e Use proposal key instead of raw proposal
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2077
diff changeset
    38
    if item.key() in proposals_keys:
1926
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
      info['item_class'] =  'selected'
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
    else:
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
      info['item_class'] =  'normal'
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
    return info
d73fe91beeeb Added list_info helper module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
  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
    45
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    46
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    47
def getStudentProjectSurveyInfo(program_entity):
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
  """Returns a function that returns information used in a Student 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
    49
  table to show how many evaluations have been available and how
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    50
  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
    51
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    52
  Args:
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
    program_entity: the program to check the total amount of
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
                    (Grading)ProjctSurveys for
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
  """
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    56
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    57
  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
    58
  from soc.logic.models.survey import project_logic as project_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
    59
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    60
  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
    61
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
  # 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
    63
  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
    64
  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
    65
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    66
  for project_survey in 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
    67
    if not project_survey_logic.hasAtLeastOneRecord(project_survey):
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    68
      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
    69
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    70
  # 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
    71
  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
    72
  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
    73
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
  for grading_survey in 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
    75
    if not grading_survey_logic.hasAtLeastOneRecord(grading_survey):
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
      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
    77
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
  def wrapper(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
    79
    """Wrapper method.
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    80
    """
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
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
    from soc.logic.models.survey_record import grading_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
    83
    from soc.logic.models.survey_record import project_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
    84
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
    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
    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
    # 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
    88
    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
    89
    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
    90
506cda0463e8 Added columns to the manage project page that show the amount of evaluations.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2206
diff changeset
    91
    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
    92
            '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
    93
            '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
    94
            '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
    95
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
    return info
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
  return wrapper