app/soc/views/models/project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 03 Jul 2009 18:20:33 +0200
changeset 2510 a85484d1f441
parent 2508 17caa9f1c683
child 2531 855ee76c16a2
permissions -rw-r--r--
Ensure that the params from subclasses get merged properly with ProjectSurvey view.
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 ProjectSurveys.
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__ = [
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from soc.logic import dicts
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
from soc.logic.models.survey import project_logic as project_survey_logic
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    27
from soc.logic.models.user import logic as user_logic
2508
17caa9f1c683 Added missing import to ProjectSurvey View.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2499
diff changeset
    28
from soc.views import out_of_band
2452
4abc27894b61 Added two missing imports to the Project and Grading Surveys views.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2448
diff changeset
    29
from soc.views.helper import access
4abc27894b61 Added two missing imports to the Project and Grading Surveys views.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2448
diff changeset
    30
from soc.views.helper import decorators
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    31
from soc.views.helper import lists
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    32
from soc.views.helper import redirects
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
from soc.views.models import survey
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
class View(survey.View):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
  """View methods for the ProjectSurvey model.
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
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  def __init__(self, params=None):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
    """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
    42
    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
    43
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
    Params:
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
      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
    46
    """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
    rights = access.Checker(params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    rights['any_access'] = ['allow']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    rights['show'] = [('checkIsSurveyReadable', project_survey_logic)]
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    51
    rights['create'] = ['checkIsDeveloper'] # TODO(ljvderijk) proper access check
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    rights['edit'] = [('checkIsSurveyWritable', project_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights['delete'] = [('checkIsSurveyWritable', project_survey_logic)]
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
    rights['list'] = ['checkDocumentList']
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    55
    rights['take'] = ['checkIsDeveloper'] # TODO(ljvderijk) add Project check
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
    new_params['logic'] = project_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    new_params['name'] = "Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    63
    new_params['extra_dynaexclude'] = ['taking_access']
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
2510
a85484d1f441 Ensure that the params from subclasses get merged properly with ProjectSurvey view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2508
diff changeset
    65
    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
    66
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    69
  @decorators.merge_params
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    70
  @decorators.check_access
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    71
  def take(self, request, access_type, page_name=None,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    72
           params=None, **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    73
    """View for taking a Survey.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    74
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    75
    For Args see base.View().public().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    76
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    77
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    78
    from soc.logic.models.student import logic as student_logic
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    79
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    80
    survey_logic = params['logic']
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    81
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    82
    try:
2499
62e8f6e45d9a Removed unnecessary variable in ProjectSurvey take method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2498
diff changeset
    83
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    84
    except out_of_band.Error, error:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    85
      return responses.errorResponse(
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    86
          error, request, template=params['error_public'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    87
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    88
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    89
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    90
    if not 'project' in get_dict:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    91
      user_entity = user_logic.getForCurrentAccount()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    92
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    93
      fields = {'user': user_entity,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    94
                'scope': survey_logic.getScope(entity),
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    95
                'status': 'active'}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    96
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    97
      student_entity = student_logic.getForFields(fields, unique=True)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    98
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    99
      # TODO(ljvderijk) transform StudentProject to handle multiple surveys
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   100
      fields = {'student': student_entity,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   101
                'status': 'accepted'}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   102
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   103
      # show project selection screen
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   104
      return self._selectProjects(request, page_name, params, entity, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   105
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   106
    return super(View, self).take(request, 'any_access', page_name=page_name,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   107
                                  params=params, **kwargs)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   108
2498
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   109
  def _getSurveyRecordFor(self, survey, request, params):
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   110
    """Returns the SurveyRecord for the given Survey and request.
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   111
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   112
    This method also take the StudentProject specified as GET param into
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   113
    account when querying for the SurveyRecord.
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   114
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   115
    For params see base.View._getSurveyRecordFor().
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   116
    """
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   117
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   118
    from soc.logic.models.student_project import logic as student_project_logic
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   119
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   120
    survey_logic = params['logic']
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   121
    record_logic = survey_logic.getRecordLogic()
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   122
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   123
    user_entity = user_logic.getForCurrentAccount()
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   124
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   125
    # get the StudentProject specified in the GET params
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   126
    project_key_name = request.GET['project']
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   127
    project_entity = student_project_logic.getFromKeyName(project_key_name)
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   128
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   129
    filter = {'survey': survey,
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   130
              'user': user_entity,
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   131
              'project': project_entity}
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   132
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   133
    return record_logic.getForFields(filter, unique=True)
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   134
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   135
  def _takeGet(self, request, template, context, params, entity, record,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   136
              **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   137
    """Hooking into the view for the take's page GET request.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   138
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   139
    For params see survey.View._takeGet().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   140
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   141
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   142
    # the form action should contain the requested project
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   143
    context['form_action'] = "?project=%s" %(request.GET['project'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   144
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   145
  def _takePost(self, request, params, entity, record, properties):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   146
    """Hook into the view for the take's page POST request.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   147
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   148
    This is used to ensure the right StudentProject gets stored
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   149
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   150
    For params see survey.View._takePost().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   151
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   152
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   153
    from soc.logic.models.student_project import logic as student_project_logic
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   154
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   155
    # retrieve the project using the key name in the GET param
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   156
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   157
    project_entity = student_project_logic.getFromKeyName(get_dict['project'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   158
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   159
    # update the properties that will be stored with the referenced project
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   160
    properties.update(project=project_entity)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   161
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   162
  def _selectProjects(self, request, page_name, params, survey, fields):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   163
    """Shows a view upon which a User can select a Student Project to fill in
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   164
    the ProjectSurvey for.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   165
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   166
    Args:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   167
      survey: a Survey entity
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   168
      fields: the filter to use on the Project List.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   169
      rest: see base.View.public()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   170
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   171
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   172
    from soc.views.models.student_project import view as student_project_view
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   173
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   174
    student_project_params = student_project_view.getParams().copy()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   175
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   176
    redirect_dict = {'survey': survey,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   177
                     'params': params}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   178
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   179
    student_project_params['list_action'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   180
        redirects.getTakeProjectSurveyRedirect, redirect_dict)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   181
    student_project_params['list_description'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   182
        "Select a %s for which to fill in the %s named %s" %(
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   183
            student_project_params['name'], params['name'], survey.title))
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   184
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   185
    content = lists.getListContent(request, student_project_params, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   186
    contents = [content]
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   187
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   188
    return self._list(request, student_project_params, contents, page_name)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   189
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   190
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   191
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   192
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   193
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   194
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   195
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   196
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   197
public = decorators.view(view.public)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   198
take = decorators.view(view.take)