app/soc/views/models/grading_project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Mon, 24 Aug 2009 18:44:41 +0200
changeset 2793 8c88226b27e7
parent 2765 b1c591bb2e87
child 2798 ec1857f0d0c7
permissions -rw-r--r--
Set default taking access for GradingProjectSurvey to org. This will allow Mentors and Org Admins to take GradingProjectSurveys in case that an Org Admin has no Mentor roles.
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__ = [
2528
9de8348890d8 Added Daniel Diniz to authors for Grading Project Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2527
diff changeset
    21
  '"Daniel Diniz" <ajaksu@gmail.com>',
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
    22
  '"James Levy" <jamesalexanderlevy@gmail.com>',
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
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
2528
9de8348890d8 Added Daniel Diniz to authors for Grading Project Survey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2527
diff changeset
    26
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
    27
from django import forms
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
from soc.logic.models.survey import grading_logic as grading_survey_logic
2532
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    31
from soc.logic.models.user import logic as user_logic
2452
4abc27894b61 Added two missing imports to the Project and Grading Surveys views.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2448
diff changeset
    32
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
    33
from soc.views.helper import decorators
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
    34
from soc.views.helper import surveys
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
from soc.views.models import project_survey
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
class View(project_survey.View):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
  """View methods for the GradingProjectSurvey model.
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """
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
  def __init__(self, params=None):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
    """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
    44
    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
    45
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
    Params:
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
      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
    48
    """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    rights = access.Checker(params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights['any_access'] = ['allow']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['show'] = [('checkIsSurveyReadable', grading_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights['create'] = ['checkIsUser']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['edit'] = [('checkIsSurveyWritable', grading_survey_logic)]
2534
c880489123fc Fixed basic Survey access check.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2532
diff changeset
    55
    rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    rights['list'] = ['checkDocumentList']
2734
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    57
    rights['record'] = [('checkHasAny', [
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    58
        [('checkIsAllowedToViewProjectSurveyRecordAs',
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    59
          [grading_survey_logic, 'mentor', 'id']),
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    60
        ('checkIsSurveyReadable', [grading_survey_logic]),
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    61
        ]])]
2755
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
    62
    rights['results'] = ['checkIsUser']
2536
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    63
    rights['take'] = [('checkIsSurveyTakeable', grading_survey_logic),
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    64
                      ('checkIsAllowedToTakeProjectSurveyAs',
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    65
                       [grading_survey_logic, 'mentor', 'project'])]
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['logic'] = grading_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params['name'] = "Grading Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
2745
c45dc8a5d64e Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2744
diff changeset
    73
    new_params['survey_take_form'] = GradeSurveyTakeForm
c45dc8a5d64e Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2744
diff changeset
    74
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
    75
    # used for sending reminders
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
    76
    new_params['survey_type'] = 'grading'
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
    77
2686
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    78
    new_params['manage_student_project_heading'] = \
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    79
        'soc/grading_project_survey/list/heading_manage_student_project.html'
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    80
    new_params['manage_student_project_row'] = \
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    81
        'soc/grading_project_survey/list/row_manage_student_project.html'
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    82
2512
2e8ccec037a9 Sub_merge params for GradingProjectSurvey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2511
diff changeset
    83
    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
    84
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
2532
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    87
  def _constructFilterForProjectSelection(self, survey, params):
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    88
    """Returns the filter needed for the Project selection view.
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    89
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    90
    Constructs a filter that returns all valid projects for which the current
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    91
    user is the mentor. Only for the projects in the program given by the
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    92
    survey's scope of course.
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    93
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    94
    For args see project_survey.View._constructFilterForProjectSelection().
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    95
    """
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    96
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    97
    from soc.logic.models.mentor import logic as mentor_logic
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    98
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
    99
    survey_logic = params['logic']
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   100
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   101
    user_entity = user_logic.getForCurrentAccount()
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   102
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   103
    # get the mentor entities for the current user and program
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   104
    fields = {'user': user_entity,
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   105
              'program': survey_logic.getScope(survey),
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   106
              'status': 'active'}
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   107
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   108
    mentor_entities = mentor_logic.getForFields(fields)
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   109
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   110
    # TODO: Ensure that this doesn't break when someone is a mentor for
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   111
    # a lot of organizations.
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   112
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   113
    fields = {'mentor': mentor_entities,
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   114
              'status': 'accepted'}
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   115
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   116
    return fields
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   117
2755
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   118
  def _getResultsViewRecordFields(self, survey, allowed_to_read):
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   119
    """Get the Results View filter for ProjectSurveyRecords.
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   120
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   121
    For args see survey.View()._getResultsViewRecordFields()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   122
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   123
    Returns:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   124
      Returns the dictionary containing the fields to filter on
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   125
    """
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   126
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   127
    from soc.logic.models.mentor import logic as mentor_logic
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   128
    from soc.logic.models.org_admin import logic as org_admin_logic
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   129
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   130
    if allowed_to_read:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   131
      return super(View, self)._getResultsViewRecordFields(survey,
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   132
                                                           allowed_to_read)
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   133
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   134
    fields = {'survey': survey}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   135
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   136
    user_entity = user_logic.getForCurrentAccount()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   137
    program_entity = survey.scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   138
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   139
    role_fields = {'user': user_entity,
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   140
                   'program': program_entity,
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   141
                   'status': ['active', 'inactive']}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   142
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   143
    org_admins = org_admin_logic.getForFields(role_fields)
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   144
    mentors = mentor_logic.getForFields(role_fields)
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   145
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   146
    organizations = {}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   147
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   148
    if org_admins:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   149
      for org_admin in org_admins:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   150
        # for each org admin store the organization
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   151
        org_scope = org_admin.scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   152
        org_key_name = org_scope.key().id_or_name()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   153
        organizations[org_key_name] = org_scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   154
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   155
    if mentors:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   156
      for mentor in mentors:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   157
        # for each mentor store the organization
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   158
        # This will allow the user to view the GradingProjectSurvey Records
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   159
        # listing for projects which he might have no further access to.
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   160
        org_scope = mentor.scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   161
        org_key_name = org_scope.key().id_or_name()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   162
        organizations[org_key_name] = org_scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   163
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   164
    if organizations:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   165
      # filter on all the found organizations
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   166
      fields['org'] = organizations.values()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   167
    else:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   168
      # This user is no org admin or mentor and should only see
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   169
      # his/her own records.
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   170
      fields['user'] = user_entity
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   171
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   172
    return fields
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   173
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   174
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   175
class GradeSurveyTakeForm(surveys.SurveyTakeForm):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   176
  """Extends SurveyTakeForm by adding a grade field.
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   177
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   178
  The grade field logic is dependent on the kwarg 'grade_choices' (behavior
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   179
  should be the same as the base class's if this argument is missing).
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   180
  """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   181
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   182
  DEF_GRADE_CHOICES = (('pass', 'Pass'), ('fail', 'Fail'))
2564
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   183
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   184
  def setCleaners(self, post_dict=None):
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   185
    """Ensures that the grade field is added to the clean data.
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   186
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   187
    For args see surveys.SurveyTakeForm.setCleaners().
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   188
    """
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   189
2564
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   190
    clean_data = super(GradeSurveyTakeForm, self).setCleaners(
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   191
        post_dict=post_dict)
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   192
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   193
    if post_dict:
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   194
      clean_data['grade'] = post_dict.get('grade', None)
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   195
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   196
    return clean_data
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   197
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   198
  def clean_grade(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   199
    """Validate the grade field.
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   200
    """
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   201
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   202
    grade = self.cleaned_data['grade']
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   203
    # map to bool
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   204
    grade_vals = {'pass': True, 'fail': False, '': ''}
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   205
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   206
    return grade_vals.get(grade, None)
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   207
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   208
  def getFields(self, post_dict=None):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   209
    """Add the extra grade field's value from POST or survey_record.
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   210
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   211
    Args:
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   212
        post_dict: dict with POST data if exists
2513
c6de2d3eae90 Style fixes to the GradingProjectSurvey View module.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2512
diff changeset
   213
    """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   214
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   215
    # fetch value from post_dict if it's there
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   216
    post_dict = post_dict or {}
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   217
    grade = post_dict.get('grade', None)
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   218
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   219
    # otherwise, try to fetch from survey_record
2564
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   220
    if grade == None and hasattr(self.survey_record, 'grade'):
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   221
      grade = self.survey_record.grade
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   222
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   223
    # remap bool to string values as the ChoiceField validates on 'choices'.
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   224
    vals_grade = {True: 'pass', False: 'fail'}
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   225
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   226
    self.data['grade'] = vals_grade.get(grade, None) or grade
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   227
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   228
    return super(GradeSurveyTakeForm, self).getFields(post_dict)
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   229
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   230
  def insertFields(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   231
    """Add ordered fields to self.fields, add grade field with grade choices.
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   232
    """
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   233
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   234
    # add common survey fields
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   235
    fields = super(GradeSurveyTakeForm, self).insertFields()
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   236
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   237
    # add empty option to choices
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   238
    grade_choices = (('', "Choose a Grade"),) + tuple(self.DEF_GRADE_CHOICES)
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   239
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   240
    gradeField = forms.fields.ChoiceField(choices=grade_choices,
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   241
                                          required=True,
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   242
                                          widget=forms.Select(),
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   243
                                          initial=self.data.get('grade'))
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   244
    # add the grade field at the form's bottom
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   245
    fields.insert(len(fields) + 1, 'grade', gradeField)
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   246
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   247
    return fields
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   248
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   249
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   250
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   251
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   252
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   253
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   254
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   255
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   256
public = decorators.view(view.public)
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
   257
record = decorators.view(view.viewRecord)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2564
diff changeset
   258
results = decorators.view(view.viewResults)
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
   259
send_reminder = decorators.view(view.sendReminder)
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   260
take = decorators.view(view.take)