app/soc/views/models/project_survey.py
author Sverre Rabbelier <sverre@rabbelier.nl>
Sat, 01 Aug 2009 16:22:10 -0700
changeset 2707 ffabb3576744
parent 2686 ada26cef0b06
child 2722 1ec0af4ddd72
permissions -rw-r--r--
Fix for copy/paste fail
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'
2686
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2598
diff changeset
    78
    new_params['manage_student_project_heading'] = \
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2598
diff changeset
    79
        'soc/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: 2598
diff changeset
    80
    new_params['manage_student_project_row'] = \
ada26cef0b06 Added new table templates for showing Suryves on the Project manage page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2598
diff changeset
    81
        'soc/project_survey/list/row_manage_student_project.html'
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    82
2510
a85484d1f441 Ensure that the params from subclasses get merged properly with ProjectSurvey view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2508
diff changeset
    83
    params = dicts.merge(params, new_params, sub_merge=True)
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    84
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    85
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    86
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    87
  @decorators.merge_params
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    88
  @decorators.check_access
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    89
  def take(self, request, access_type, page_name=None,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    90
           params=None, **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    91
    """View for taking a Survey.
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
    For Args see base.View().public().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    94
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    95
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    96
    survey_logic = params['logic']
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    97
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    98
    try:
2499
62e8f6e45d9a Removed unnecessary variable in ProjectSurvey take method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2498
diff changeset
    99
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   100
    except out_of_band.Error, error:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   101
      return responses.errorResponse(
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   102
          error, request, template=params['error_public'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   103
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   104
    get_dict = request.GET
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
    if not 'project' in get_dict:
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   107
      # get the fields needed to filter projects on
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   108
      fields = self._constructFilterForProjectSelection(entity, params)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   109
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   110
      # show project selection screen using the given filter
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   111
      return self._selectProjects(request, page_name, params, entity, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   112
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   113
    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
   114
                                  params=params, **kwargs)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   115
2498
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   116
  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
   117
    """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
   118
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   119
    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
   120
    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
   121
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   122
    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
   123
    """
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
    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
   126
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   127
    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
   128
    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
   129
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   130
    # 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
   131
    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
   132
    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
   133
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   134
    filter = {'survey': survey,
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   135
              'project': project_entity}
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   136
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   137
    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
   138
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   139
  def _takeGet(self, request, template, context, params, entity, record,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   140
              **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   141
    """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
   142
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   143
    For params see survey.View._takeGet().
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
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   146
    # the form action should contain the requested project
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   147
    context['form_action'] = "?project=%s" %(request.GET['project'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   148
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   149
  def _takePost(self, request, params, entity, record, properties):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   150
    """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
   151
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   152
    This is used to ensure the right StudentProject gets stored
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   153
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   154
    For params see survey.View._takePost().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   155
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   156
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   157
    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
   158
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   159
    # 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
   160
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   161
    project_entity = student_project_logic.getFromKeyName(get_dict['project'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   162
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   163
    # 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
   164
    properties.update(project=project_entity, org=project_entity.scope)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   165
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   166
  def _constructFilterForProjectSelection(self, survey, params):
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   167
    """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
   168
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
   169
    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
   170
    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
   171
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   172
    Args:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   173
      survey: a Survey entity
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   174
      params: the params dict for the requesting view
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
    Returns:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   177
      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
   178
    """
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
    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
   181
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   182
    survey_logic = params['logic']
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   183
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   184
    user_entity = user_logic.getForCurrentAccount()
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   185
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   186
    # 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
   187
    fields = {'user': user_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   188
              'scope': survey_logic.getScope(survey),
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   189
              'status': 'active'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   190
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   191
    student_entity = student_logic.getForFields(fields, unique=True)
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
    # TODO(ljvderijk) transform StudentProject to handle multiple surveys
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   194
    fields = {'student': student_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   195
              'status': 'accepted'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   196
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   197
    return fields
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   198
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   199
  def _selectProjects(self, request, page_name, params, survey, fields):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   200
    """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
   201
    the ProjectSurvey for.
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   202
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   203
    Args:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   204
      survey: a Survey entity
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   205
      fields: the filter to use on the Project List
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   206
      rest: see base.View.public()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   207
    """
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
    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
   210
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   211
    student_project_params = student_project_view.getParams().copy()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   212
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   213
    redirect_dict = {'survey': survey,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   214
                     'params': params}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   215
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   216
    student_project_params['list_action'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   217
        redirects.getTakeProjectSurveyRedirect, redirect_dict)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   218
    student_project_params['list_description'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   219
        "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
   220
            student_project_params['name'], params['name'], survey.title))
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   221
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   222
    content = lists.getListContent(request, student_project_params, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   223
    contents = [content]
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   224
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   225
    return self._list(request, student_project_params, contents, page_name)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   226
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   227
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   228
  @decorators.merge_params
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   229
  @decorators.check_access
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   230
  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
   231
                   params=None, **kwargs):
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   232
    """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
   233
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   234
    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
   235
    """
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
    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
   238
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   239
    from django import http
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   240
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   241
    survey_logic = params['logic']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   242
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   243
    try:
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   244
      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
   245
    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
   246
      return responses.errorResponse(
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   247
          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
   248
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   249
    # 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
   250
    context = responses.getUniversalContext(request)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   251
    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
   252
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   253
    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
   254
      # 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
   255
      task_params = {
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   256
          '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
   257
          '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
   258
          '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
   259
      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
   260
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   261
      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
   262
      new_task.add()
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   263
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   264
      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
   265
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   266
    template = params['reminder_template']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   267
    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
   268
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   269
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   270
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   271
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   272
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   273
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   274
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   275
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   276
public = decorators.view(view.public)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2563
diff changeset
   277
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
   278
send_reminder = decorators.view(view.sendReminder)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   279
take = decorators.view(view.take)