app/soc/views/models/grading_project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 11 Aug 2009 10:22:01 -0700
changeset 2754 efbce6839e90
parent 2745 c45dc8a5d64e
child 2755 e8b599ba7b37
permissions -rw-r--r--
Project Survey results view now doesn't list all for plain users.
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
        ]])]
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
    63
    rights['results'] = ['checkIsDeveloper'] # TODO: proper access check
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
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   119
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   120
class GradeSurveyTakeForm(surveys.SurveyTakeForm):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   121
  """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
   122
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   123
  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
   124
  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
   125
  """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   126
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   127
  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
   128
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   129
  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
   130
    """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
   131
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   132
    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
   133
    """
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   134
2564
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   135
    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
   136
        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
   137
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   138
    if post_dict:
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   139
      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
   140
81b36f56d61a Ensure that the Grade field data stays in clean_data.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2542
diff changeset
   141
    return clean_data
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   142
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   143
  def clean_grade(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   144
    """Validate the grade field.
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   145
    """
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   146
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   147
    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
   148
    # map to bool
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   149
    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
   150
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   151
    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
   152
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   153
  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
   154
    """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
   155
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   156
    Args:
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   157
        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
   158
    """
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   159
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   160
    # 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
   161
    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
   162
    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
   163
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   164
    # 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
   165
    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
   166
      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
   167
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   168
    # 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
   169
    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
   170
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   171
    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
   172
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   173
    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
   174
2527
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   175
  def insertFields(self):
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   176
    """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
   177
    """
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   178
ce657149b90a Add a grade field to the Grading Project Survey form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2513
diff changeset
   179
    # 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
   180
    fields = super(GradeSurveyTakeForm, self).insertFields()
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
    # add empty option to choices
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   183
    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
   184
2744
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   185
    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
   186
                                          required=True,
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   187
                                          widget=forms.Select(),
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   188
                                          initial=self.data.get('grade'))
6f5e303f64b5 Removed the grade_choices keyword argument from GradeSurveyTakeForm.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2734
diff changeset
   189
    # 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
   190
    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
   191
2542
a9dec4763c6b POST data always overwrites survey_record data when used to populate form.
Daniel Diniz <ajaksu@gmail.com>
parents: 2536
diff changeset
   192
    return fields
2511
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   193
0e53ad183df9 Added rudimentary grade field to GradingProjectSurvey take View.
James Levy <jamesalexanderlevy@gmail.com>
parents: 2478
diff changeset
   194
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   195
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   196
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   197
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   198
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   199
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   200
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   201
public = decorators.view(view.public)
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
   202
record = decorators.view(view.viewRecord)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2564
diff changeset
   203
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
   204
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
   205
take = decorators.view(view.take)