app/soc/views/models/project_survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 06 Aug 2009 10:48:44 +0200
changeset 2734 f35f6f05c8c4
parent 2725 09b5bfc5707f
child 2740 4b8aa5b9cb23
permissions -rw-r--r--
Added and enabled new access check for viewing ProjectSurvey records. Org Admins, project Mentors and project Students are now allowed to see their own ProjectSurveyRecords. Note however that Students and Mentors have no interface yet to find the whereabouts of their records. Fixes Issue 659.
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']
2734
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    56
    rights['record'] = [('checkHasAny', [
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    57
        [('checkIsAllowedToViewProjectSurveyRecordAs',
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    58
          [project_survey_logic, 'student', 'id']),
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    59
        ('checkIsSurveyReadable', [project_survey_logic]),
f35f6f05c8c4 Added and enabled new access check for viewing ProjectSurvey records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2725
diff changeset
    60
        ]])]
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
    61
    rights['results'] = ['checkIsDeveloper'] # TODO: proper access check
2536
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    62
    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
    63
                      ('checkIsAllowedToTakeProjectSurveyAs',
9f1b7aba026f Added access checks for taking a Project(Grading)Survey.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2535
diff changeset
    64
                       [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
    65
    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
    66
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    67
    new_params = {}
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['logic'] = project_survey_logic
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    new_params['rights'] = rights
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params['name'] = "Project Survey"
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
2478
985fd974e095 Clean up and other fixes for Survey modules.
Daniel Diniz <ajaksu@gmail.com>
parents: 2452
diff changeset
    73
    new_params['extra_dynaexclude'] = ['taking_access']
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    75
    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
    76
         (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
    77
          '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
    78
         '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
    79
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    80
    # used for sending reminders
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
    81
    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
    82
    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
    83
    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
    84
        '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
    85
    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
    86
        '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
    87
2510
a85484d1f441 Ensure that the params from subclasses get merged properly with ProjectSurvey view.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2508
diff changeset
    88
    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
    89
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
    super(View, self).__init__(params=params)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    92
  @decorators.merge_params
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    93
  @decorators.check_access
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    94
  def take(self, request, access_type, page_name=None,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    95
           params=None, **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
    96
    """View for taking a Survey.
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
    For Args see base.View().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
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   101
    survey_logic = params['logic']
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   102
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   103
    try:
2499
62e8f6e45d9a Removed unnecessary variable in ProjectSurvey take method.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2498
diff changeset
   104
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   105
    except out_of_band.Error, error:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   106
      return responses.errorResponse(
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   107
          error, request, template=params['error_public'])
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
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   110
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   111
    if not 'project' in get_dict:
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   112
      # get the fields needed to filter projects on
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   113
      fields = self._constructFilterForProjectSelection(entity, params)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   114
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   115
      # show project selection screen using the given filter
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   116
      return self._selectProjects(request, page_name, params, entity, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   117
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   118
    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
   119
                                  params=params, **kwargs)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   120
2498
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   121
  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
   122
    """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
   123
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   124
    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
   125
    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
   126
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   127
    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
   128
    """
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
    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
   131
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   132
    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
   133
    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
   134
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   135
    # 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
   136
    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
   137
    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
   138
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   139
    filter = {'survey': survey,
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   140
              'project': project_entity}
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   141
fd51f2159bff Overwrite _getSurveyRecordFor in ProjectSurvey view to take StudentProject into account.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2494
diff changeset
   142
    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
   143
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   144
  def _takeGet(self, request, template, context, params, entity, record,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   145
              **kwargs):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   146
    """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
   147
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   148
    For params see survey.View._takeGet().
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
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   151
    # the form action should contain the requested project
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   152
    context['form_action'] = "?project=%s" %(request.GET['project'])
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
  def _takePost(self, request, params, entity, record, properties):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   155
    """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
   156
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   157
    This is used to ensure the right StudentProject gets stored
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
    For params see survey.View._takePost().
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   160
    """
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   161
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   162
    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
   163
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   164
    # 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
   165
    get_dict = request.GET
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   166
    project_entity = student_project_logic.getFromKeyName(get_dict['project'])
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   167
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   168
    # 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
   169
    properties.update(project=project_entity, org=project_entity.scope)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   170
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   171
  def _constructFilterForProjectSelection(self, survey, params):
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   172
    """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
   173
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
   174
    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
   175
    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
   176
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   177
    Args:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   178
      survey: a Survey entity
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   179
      params: the params dict for the requesting view
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   180
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   181
    Returns:
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   182
      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
   183
    """
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   184
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   185
    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
   186
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   187
    survey_logic = params['logic']
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
    user_entity = user_logic.getForCurrentAccount()
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
    # 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
   192
    fields = {'user': user_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   193
              'scope': survey_logic.getScope(survey),
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   194
              'status': 'active'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   195
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   196
    student_entity = student_logic.getForFields(fields, unique=True)
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   197
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   198
    fields = {'student': student_entity,
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   199
              'status': 'accepted'}
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   200
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   201
    return fields
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   202
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   203
  def _selectProjects(self, request, page_name, params, survey, fields):
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   204
    """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
   205
    the ProjectSurvey for.
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
    Args:
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   208
      survey: a Survey entity
2531
855ee76c16a2 Refactored filter construction to _constructFilterForProjectSelection.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2510
diff changeset
   209
      fields: the filter to use on the Project List
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   210
      rest: see base.View.public()
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
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   213
    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
   214
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   215
    student_project_params = student_project_view.getParams().copy()
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   216
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   217
    redirect_dict = {'survey': survey,
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   218
                     'params': params}
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   219
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   220
    student_project_params['list_action'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   221
        redirects.getTakeProjectSurveyRedirect, redirect_dict)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   222
    student_project_params['list_description'] = (
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   223
        "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
   224
            student_project_params['name'], params['name'], survey.title))
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   225
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   226
    content = lists.getListContent(request, student_project_params, fields)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   227
    contents = [content]
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   228
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   229
    return self._list(request, student_project_params, contents, page_name)
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   230
2596
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   231
  @decorators.merge_params
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   232
  @decorators.check_access
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   233
  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
   234
                   params=None, **kwargs):
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   235
    """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
   236
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   237
    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
   238
    """
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   239
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   240
    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
   241
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   242
    from django import http
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   243
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   244
    survey_logic = params['logic']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   245
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   246
    try:
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   247
      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
   248
    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
   249
      return responses.errorResponse(
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   250
          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
   251
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   252
    # 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
   253
    context = responses.getUniversalContext(request)
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   254
    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
   255
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   256
    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
   257
      # 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
   258
      task_params = {
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   259
          '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
   260
          '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
   261
          '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
   262
      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
   263
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   264
      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
   265
      new_task.add()
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   266
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   267
      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
   268
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   269
    template = params['reminder_template']
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   270
    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
   271
56924ec61cd2 Added a view to start sending out a reminder.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2591
diff changeset
   272
2448
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   273
view = View()
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   274
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   275
create = decorators.view(view.create)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   276
edit = decorators.view(view.edit)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   277
delete = decorators.view(view.delete)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   278
list = decorators.view(view.list)
325e08ee9d25 Added skeleton view for ProjectSurvey and GradingProjectSurvey.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   279
public = decorators.view(view.public)
2722
1ec0af4ddd72 Added view for showing Survey Records.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2686
diff changeset
   280
record = decorators.view(view.viewRecord)
2576
7a1138f8a0e2 Removed results list from Survey edit.
Daniel Diniz <ajaksu@gmail.com>
parents: 2563
diff changeset
   281
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
   282
send_reminder = decorators.view(view.sendReminder)
2494
c312f1b1939c Implemented taking ProjectSurveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2478
diff changeset
   283
take = decorators.view(view.take)