app/soc/views/models/grading_project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 11 Aug 2009 10:54:56 -0700
changeset 2755 e8b599ba7b37
parent 2745 c45dc8a5d64e
child 2765 b1c591bb2e87
permissions -rw-r--r--
Completed the proper filter for the GradingProjectSurvey results view. Also set the access check to checkIsUser.
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
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    30
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
    31
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
    32
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
    33
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
    34
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
    35
from soc.views.helper import surveys
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
from soc.views.models import project_survey
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
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
class View(project_survey.View):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  """View methods for the GradingProjectSurvey model.
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
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  def __init__(self, params=None):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    """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
    45
    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
    46
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
    Params:
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
      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
    49
    """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights = access.Checker(params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['any_access'] = ['allow']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights['show'] = [('checkIsSurveyReadable', grading_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['create'] = ['checkIsUser']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    rights['edit'] = [('checkIsSurveyWritable', grading_survey_logic)]
2534
c880489123fc Fixed basic Survey access check.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2532
diff changeset
    56
    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
    57
    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
    58
    rights['record'] = [('checkHasAny', [
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    59
        [('checkIsAllowedToViewProjectSurveyRecordAs',
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    60
          [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
    61
        ('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
    62
        ]])]
2755
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
    63
    rights['results'] = ['checkIsUser']
2536
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    64
    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
    65
                      ('checkIsAllowedToTakeProjectSurveyAs',
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    66
                       [grading_survey_logic, 'mentor', 'project'])]
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['logic'] = grading_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['name'] = "Grading Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
2745
c45dc8a5d64e Made the specific SurveyTakeForm used in a View part of params.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2744
diff changeset
    74
    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
    75
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
    76
    # used for sending reminders
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2576
diff changeset
    77
    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
    78
2686
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    79
    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
    80
        '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
    81
    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
    82
        '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
    83
2512
2e8ccec037a9 Sub_merge params for GradingProjectSurvey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2511
diff changeset
    84
    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
    85
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    87
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
    88
  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
    89
    """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
    90
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
    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
    92
    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
    93
    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
    94
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
    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
    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
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
    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
    99
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
    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
   101
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
    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
   103
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
    # 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
   105
    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
   106
              '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
   107
              '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
   108
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
    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
   110
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
    # 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
   112
    # 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
   113
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
    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
   115
              '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
   116
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2528
diff changeset
   117
    return fields
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   118
2755
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   119
  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
   120
    """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
   121
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   122
    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
   123
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   124
    Returns:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   125
      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
   126
    """
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   127
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.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
   129
    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
   130
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   131
    if allowed_to_read:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   132
      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
   133
                                                           allowed_to_read)
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   134
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   135
    fields = {'survey': survey}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   136
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   137
    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
   138
    program_entity = survey.scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   139
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   140
    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
   141
                   'program': program_entity,
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   142
                   'status': ['active', 'inactive']}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   143
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   144
    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
   145
    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
   146
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   147
    organizations = {}
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   148
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   149
    if org_admins:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   150
      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
   151
        # 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
   152
        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
   153
        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
   154
        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
   155
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   156
    if mentors:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   157
      for mentor in mentors:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   158
        # 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
   159
        # 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
   160
        # 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
   161
        org_scope = mentor.scope
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   162
        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
   163
        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
   164
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   165
    if organizations:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   166
      # 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
   167
      fields['org'] = organizations.values()
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   168
    else:
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   169
      # 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
   170
      # his/her own records.
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   171
      fields['user'] = user_entity
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   172
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   173
    return fields
e8b599ba7b37 Completed the proper filter for the GradingProjectSurvey results view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2745
diff changeset
   174
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   175
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   176
class GradeSurveyTakeForm(surveys.SurveyTakeForm):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   177
  """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
   178
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   179
  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
   180
  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
   181
  """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   182
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   183
  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
   184
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   185
  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
   186
    """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
   187
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   188
    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
   189
    """
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   190
2564
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   191
    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
   192
        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
   193
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   194
    if post_dict:
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   195
      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
   196
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   197
    return clean_data
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   198
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   199
  def clean_grade(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   200
    """Validate the grade field.
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
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   203
    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
   204
    # map to bool
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   205
    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
   206
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   207
    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
   208
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   209
  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
   210
    """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
   211
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   212
    Args:
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   213
        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
   214
    """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   215
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   216
    # 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
   217
    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
   218
    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
   219
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   220
    # 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
   221
    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
   222
      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
   223
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   224
    # 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
   225
    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
   226
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   227
    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
   228
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   229
    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
   230
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   231
  def insertFields(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   232
    """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
   233
    """
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   234
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   235
    # 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
   236
    fields = super(GradeSurveyTakeForm, self).insertFields()
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   237
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   238
    # add empty option to choices
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   239
    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
   240
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   241
    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
   242
                                          required=True,
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   243
                                          widget=forms.Select(),
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   244
                                          initial=self.data.get('grade'))
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   245
    # 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
   246
    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
   247
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   248
    return fields
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   249
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   250
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   251
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   252
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   253
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   254
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   255
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   256
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   257
public = decorators.view(view.public)
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
   258
record = decorators.view(view.viewRecord)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2564
diff changeset
   259
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
   260
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
   261
take = decorators.view(view.take)