app/soc/views/models/project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 15 Jul 2009 11:48:43 +0200
changeset 2656 25210120d67b
parent 2598 59ebf718c6a4
child 2686 ada26cef0b06
permissions -rw-r--r--
Added validation to email fields where needed. Apparently Django did not generate an email field when it was required. Fixes issue 623.
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
2563
eec0d98b38a1 Add missing import to Project Survey view.
Daniel Diniz <ajaksu@gmail.com>
parents: 2549
diff changeset
    33
from soc.views.helper import responses
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
from soc.views.models import survey
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
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
class View(survey.View):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
  """View methods for the ProjectSurvey model.
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
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  def __init__(self, params=None):
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
    """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
    43
    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
    44
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
    Params:
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
      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
    47
    """
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
    rights = access.Checker(params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
    rights['any_access'] = ['allow']
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
    rights['show'] = [('checkIsSurveyReadable', project_survey_logic)]
2537
990a44b6310b Returned ProjectSurvey create to checkIsUser.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2536
diff changeset
    52
    rights['create'] = ['checkIsUser']
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    rights['edit'] = [('checkIsSurveyWritable', project_survey_logic)]
2534
c880489123fc Fixed basic Survey access check.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2532
diff changeset
    54
    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
    55
    rights['list'] = ['checkDocumentList']
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2563
diff changeset
    56
    rights['results'] = [('checkIsSurveyWritable', project_survey_logic)]
2536
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    57
    rights['take'] = [('checkIsSurveyTakeable', project_survey_logic),
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    58
                      ('checkIsAllowedToTakeProjectSurveyAs',
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    59
                       [project_survey_logic, 'student', 'project'])]
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    60
    rights['send_reminder'] = ['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
    61
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    new_params['logic'] = project_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params['name'] = "Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    68
    new_params['extra_dynaexclude'] = ['taking_access']
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    70
    new_params['extra_django_patterns'] = [
2598
59ebf718c6a4 Changed URL pattern for starting sending out survey reminders.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2596
diff changeset
    71
         (r'^%(url_name)s/(?P<access_type>send_reminder)/%(key_fields)s$',
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    72
          'soc.views.models.%(module_name)s.send_reminder',
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    73
         'Send Reminder for %(name)s')]
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    74
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    75
    # used for sending reminders
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    76
    new_params['survey_type'] = 'project'
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    77
    new_params['reminder_template'] = 'soc/project_survey/reminder.html'
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    78
2510
a85484d1f441 Ensure that the params from subclasses get merged properly with ProjectSurvey view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2508
diff changeset
    79
    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
    80
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    83
  @decorators.merge_params
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    84
  @decorators.check_access
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    85
  def take(self, request, access_type, page_name=None,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    86
           params=None, **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    87
    """View for taking a Survey.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    88
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    89
    For Args see base.View().public().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    90
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    91
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    92
    survey_logic = params['logic']
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    93
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    94
    try:
2499
62e8f6e45d9a Removed unnecessary variable in ProjectSurvey take method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2498
diff changeset
    95
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    96
    except out_of_band.Error, error:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    97
      return responses.errorResponse(
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    98
          error, request, template=params['error_public'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    99
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   100
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   101
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   102
    if not 'project' in get_dict:
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   103
      # get the fields needed to filter projects on
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   104
      fields = self._constructFilterForProjectSelection(entity, params)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   105
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   106
      # show project selection screen using the given filter
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   107
      return self._selectProjects(request, page_name, params, entity, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   108
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   109
    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
   110
                                  params=params, **kwargs)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   111
2498
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   112
  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
   113
    """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
   114
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   115
    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
   116
    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
   117
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   118
    For params see survey.View._getSurveyRecordFor().
2498
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
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   121
    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
   122
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   123
    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
   124
    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
   125
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   126
    # 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
   127
    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
   128
    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
   129
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   130
    filter = {'survey': survey,
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
2591
6c57c482f913 Add Organization reference property to ProjectSurveyRecord.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2576
diff changeset
   160
    properties.update(project=project_entity, org=project_entity.scope)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   161
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   162
  def _constructFilterForProjectSelection(self, survey, params):
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   163
    """Returns the filter needed for the Project selection view.
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   164
2532
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2531
diff changeset
   165
    Returns a filter for all the valid projects for which the current user
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2531
diff changeset
   166
    is a student. Of course only in the survey's scope.
0b4dbe4b3fb7 Fixed showing the correct list of projects for taking a Grading Project Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2531
diff changeset
   167
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   168
    Args:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   169
      survey: a Survey entity
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   170
      params: the params dict for the requesting view
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   171
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   172
    Returns:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   173
      Dictionary that can be used as a input for a query.
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   174
    """
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   175
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   176
    from soc.logic.models.student import logic as student_logic
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   177
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   178
    survey_logic = params['logic']
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   179
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   180
    user_entity = user_logic.getForCurrentAccount()
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   181
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   182
    # get the student entity for the current user and program
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   183
    fields = {'user': user_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   184
              'scope': survey_logic.getScope(survey),
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   185
              'status': 'active'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   186
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   187
    student_entity = student_logic.getForFields(fields, unique=True)
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   188
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   189
    # TODO(ljvderijk) transform StudentProject to handle multiple surveys
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   190
    fields = {'student': student_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   191
              'status': 'accepted'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   192
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   193
    return fields
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   194
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   195
  def _selectProjects(self, request, page_name, params, survey, fields):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   196
    """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
   197
    the ProjectSurvey for.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   198
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   199
    Args:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   200
      survey: a Survey entity
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   201
      fields: the filter to use on the Project List
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   202
      rest: see base.View.public()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   203
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   204
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   205
    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
   206
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   207
    student_project_params = student_project_view.getParams().copy()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   208
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   209
    redirect_dict = {'survey': survey,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   210
                     'params': params}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   211
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   212
    student_project_params['list_action'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   213
        redirects.getTakeProjectSurveyRedirect, redirect_dict)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   214
    student_project_params['list_description'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   215
        "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
   216
            student_project_params['name'], params['name'], survey.title))
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   217
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   218
    content = lists.getListContent(request, student_project_params, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   219
    contents = [content]
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   220
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   221
    return self._list(request, student_project_params, contents, page_name)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   222
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   223
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   224
  @decorators.merge_params
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   225
  @decorators.check_access
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   226
  def sendReminder(self, request, access_type, page_name=None,
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   227
                   params=None, **kwargs):
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   228
    """Starts the task to send out reminders for the Survey given in kwargs.
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   229
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   230
    For args see base.View.public().
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   231
    """
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   232
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   233
    from google.appengine.api.labs import taskqueue
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   234
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   235
    from django import http
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   236
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   237
    survey_logic = params['logic']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   238
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   239
    try:
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   240
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   241
    except out_of_band.Error, error:
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   242
      return responses.errorResponse(
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   243
          error, request, template=params['error_public'])
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   244
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   245
    # get the context for this webpage
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   246
    context = responses.getUniversalContext(request)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   247
    context['page_name'] = page_name
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   248
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   249
    if request.POST and request.POST.get('start'):
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   250
      # button has been pressed start the task
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   251
      task_params = {
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   252
          'program_key': survey_logic.getScope(entity).key().id_or_name(),
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   253
          'survey_key': entity.key().id_or_name(),
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   254
          'survey_type': params['survey_type']}
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   255
      task_url = '/tasks/surveys/projects/send_reminder/spawn'
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   256
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   257
      new_task = taskqueue.Task(params=task_params, url=task_url)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   258
      new_task.add()
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   259
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   260
      context['message'] = "Task successfully started!"
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   261
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   262
    template = params['reminder_template']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   263
    return responses.respond(request, template, context)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   264
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   265
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   266
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   267
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   268
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   269
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   270
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   271
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   272
public = decorators.view(view.public)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2563
diff changeset
   273
results = decorators.view(view.viewResults)
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   274
send_reminder = decorators.view(view.sendReminder)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   275
take = decorators.view(view.take)