app/soc/views/models/grading_project_survey.py
author Daniel Diniz <ajaksu@gmail.com>
Fri, 03 Jul 2009 21:06:22 +0200
changeset 2517 97117d341f62
parent 2513 c6de2d3eae90
child 2527 ce657149b90a
permissions -rw-r--r--
Split SurveyForm into SurveyTakeForm and SurveyEditForm. This allows for a more cleaner implementation of the Form code. And this will make it easier to break free from the getFields method in the future. Also the getRoleSpecifcFields method and the this_user and project variables have been removed. They are deemed obsolete. Reviewed by: Lennard de Rijk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for GradingProjectSurveys.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    21
  '"James Levy" <jamesalexanderlevy@gmail.com>',
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
  ]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from soc.logic import dicts
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    27
from soc.logic.models.survey import GRADES
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
from soc.logic.models.survey import grading_logic as grading_survey_logic
2452
4abc27894b61 Added two missing imports to the Project and Grading Surveys views.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2448
diff changeset
    29
from soc.views.helper import access
4abc27894b61 Added two missing imports to the Project and Grading Surveys views.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2448
diff changeset
    30
from soc.views.helper import decorators
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
from soc.views.models import project_survey
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
class View(project_survey.View):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
  """View methods for the GradingProjectSurvey model.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
  """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
  def __init__(self, params=None):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
    """Defines the fields and methods required for the base View class
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
    to provide the user with list, public, create, edit and delete views.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
    Params:
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
      params: a dict with params for this View
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    rights = access.Checker(params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    rights['any_access'] = ['allow']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
    rights['show'] = [('checkIsSurveyReadable', grading_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    rights['create'] = ['checkIsUser']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    rights['edit'] = [('checkIsSurveyWritable', grading_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights['delete'] = [('checkIsSurveyWritable', grading_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['list'] = ['checkDocumentList']
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    53
    rights['take'] = ['checkIsDeveloper'] # TODO(ljvderijk) add Project check
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    new_params['logic'] = grading_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    new_params['name'] = "Grading Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
2512
2e8ccec037a9 Sub_merge params for GradingProjectSurvey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2511
diff changeset
    61
    params = dicts.merge(params, new_params, sub_merge=True)
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    65
  # TODO: work on grade activation
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    66
  def activate(self, request, **kwargs):
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    67
    """This is a hack to support the 'Enable grades' button.
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    68
    """
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    69
    self.activateGrades(request)
2513
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
    70
    redirect_path = request.path.replace('/activate/', '/edit/') + (
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
    71
        '?activate=1')
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    72
    return http.HttpResponseRedirect(redirect_path)
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    73
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    74
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    75
  def activateGrades(self, request, **kwargs):
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    76
    """Updates SurveyRecord's grades for a given Survey.
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    77
    """
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    78
    survey_key_name = survey_logic.getKeyNameFromPath(request.path)
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    79
    survey = Survey.get_by_key_name(survey_key_name)
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    80
    survey_logic.activateGrades(survey)
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    81
    return
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    82
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    83
  def _takeGet(self, request, template, context, params, entity, record,
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    84
              **kwargs):
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    85
    """Hook for the GET request for the Survey's take page.
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    86
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    87
    This method is called just before the GET page is shown.
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    88
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    89
    Args:
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    90
        template: the template used for this view
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    91
        entity: the Survey entity
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    92
        record: a SurveyRecord entity
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    93
        rest: see base.View.public()
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    94
    """
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    95
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    96
    gradeField = self.addGradeField(entity, record)
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    97
    field_count = len(eval(entity.survey_content.schema).items())
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    98
    context['survey_form'].fields.insert(field_count + 1, 'grade', gradeField)
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    99
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   100
    return super(View, self)._takeGet(request, template, context,
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   101
                                      params, entity, record, **kwargs)
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   102
2513
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
   103
  def addGradeField(self, survey, survey_record):
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
   104
    """Adds a Grade Field to Survey.
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   105
2513
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
   106
    Used for mentor evaluations.
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   107
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   108
    params:
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   109
      survey: the survey being taken
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   110
      survey_record: an existing survey record for a user-project-survey combo,
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   111
        or None
2513
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
   112
    """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   113
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   114
    # Add a grade field determining if student passes or fails.
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   115
    # Activate grades handler should determine whether new status
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   116
    # is midterm_passed, final_passed, etc.
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   117
    grade_choices = (('pass', 'Pass'), ('fail', 'Fail'))
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   118
    grade_vals = { 'pass': True, 'fail': False }
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   119
    from django import forms
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   120
    gradeField = forms.fields.ChoiceField(choices=grade_choices,
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   121
                                           required=True,
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   122
                                           widget=forms.Select())
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   123
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   124
    gradeField.choices.insert(0, (None, "Choose a Grade")  )
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   125
    if survey_record:
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   126
      for g in grade_choices:
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   127
        if grade_vals[g[0]] == survey_record.grade:
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   128
          gradeField.choices.insert(0, (g[0],g[1] + " (Saved)")   )
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   129
          gradeField.choices.remove(g)
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   130
          break;
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   131
      gradeField.show_hidden_initial = True
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   132
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   133
    return gradeField
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   134
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   135
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   136
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   137
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   138
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   139
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   140
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   141
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
public = decorators.view(view.public)
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   143
take = decorators.view(view.take)