# HG changeset patch # User Lennard de Rijk # Date 1247347132 -7200 # Node ID 56924ec61cd2c6fc77fc4cf11a3b2c38b7f9a4f1 # Parent 4c00831ef55c7f586d80157ef1eef60af774830f Added a view to start sending out a reminder. Note that this view is currently developer-only. diff -r 4c00831ef55c -r 56924ec61cd2 app/soc/templates/soc/project_survey/reminder.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/templates/soc/project_survey/reminder.html Sat Jul 11 23:18:52 2009 +0200 @@ -0,0 +1,24 @@ +{% extends "soc/base.html" %} +{% comment %} +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{% endcomment %} + +{% block body %} + + {{ message }} + +
+ +
+ +{% endblock %} diff -r 4c00831ef55c -r 56924ec61cd2 app/soc/views/models/grading_project_survey.py --- a/app/soc/views/models/grading_project_survey.py Sat Jul 11 23:18:14 2009 +0200 +++ b/app/soc/views/models/grading_project_survey.py Sat Jul 11 23:18:52 2009 +0200 @@ -66,6 +66,9 @@ new_params['name'] = "Grading Project Survey" + # used for sending reminders + new_params['survey_type'] = 'grading' + params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) @@ -234,4 +237,5 @@ list = decorators.view(view.list) public = decorators.view(view.public) results = decorators.view(view.viewResults) +send_reminder = decorators.view(view.sendReminder) take = decorators.view(view.take) diff -r 4c00831ef55c -r 56924ec61cd2 app/soc/views/models/project_survey.py --- a/app/soc/views/models/project_survey.py Sat Jul 11 23:18:14 2009 +0200 +++ b/app/soc/views/models/project_survey.py Sat Jul 11 23:18:52 2009 +0200 @@ -57,6 +57,7 @@ rights['take'] = [('checkIsSurveyTakeable', project_survey_logic), ('checkIsAllowedToTakeProjectSurveyAs', [project_survey_logic, 'student', 'project'])] + rights['send_reminder'] = ['checkIsDeveloper'] #TODO: proper access check new_params = {} new_params['logic'] = project_survey_logic @@ -66,6 +67,15 @@ new_params['extra_dynaexclude'] = ['taking_access'] + new_params['extra_django_patterns'] = [ + (r'^%(url_name)s/(?Psend_reminder)/start/%(key_fields)s$', + 'soc.views.models.%(module_name)s.send_reminder', + 'Send Reminder for %(name)s')] + + # used for sending reminders + new_params['survey_type'] = 'project' + new_params['reminder_template'] = 'soc/project_survey/reminder.html' + params = dicts.merge(params, new_params, sub_merge=True) super(View, self).__init__(params=params) @@ -211,6 +221,48 @@ return self._list(request, student_project_params, contents, page_name) + @decorators.merge_params + @decorators.check_access + def sendReminder(self, request, access_type, page_name=None, + params=None, **kwargs): + """Starts the task to send out reminders for the Survey given in kwargs. + + For args see base.View.public(). + """ + + from google.appengine.api.labs import taskqueue + + from django import http + + survey_logic = params['logic'] + + try: + entity = survey_logic.getFromKeyFieldsOr404(kwargs) + except out_of_band.Error, error: + return responses.errorResponse( + error, request, template=params['error_public']) + + # get the context for this webpage + context = responses.getUniversalContext(request) + context['page_name'] = page_name + + if request.POST and request.POST.get('start'): + # button has been pressed start the task + task_params = { + 'program_key': survey_logic.getScope(entity).key().id_or_name(), + 'survey_key': entity.key().id_or_name(), + 'survey_type': params['survey_type']} + task_url = '/tasks/surveys/projects/send_reminder/spawn' + + new_task = taskqueue.Task(params=task_params, url=task_url) + new_task.add() + + context['message'] = "Task successfully started!" + + template = params['reminder_template'] + return responses.respond(request, template, context) + + view = View() create = decorators.view(view.create) @@ -219,4 +271,5 @@ list = decorators.view(view.list) public = decorators.view(view.public) results = decorators.view(view.viewResults) +send_reminder = decorators.view(view.sendReminder) take = decorators.view(view.take)