author | Daniel Hans <Daniel.M.Hans@gmail.com> |
Wed, 11 Nov 2009 21:04:13 +0100 | |
changeset 3086 | f3031537547a |
parent 3005 | fbdf957cb3a3 |
permissions | -rw-r--r-- |
2817
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
# |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
# |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
# |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
# |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
"""Appengine Tasks related to GHOP Task handling. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
""" |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
'"Madhusudan.C.S" <madhusudancs@gmail.com>' |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
] |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
import logging |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
from google.appengine.api.labs import taskqueue |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
from google.appengine.ext import db |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
from django import http |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
from django.utils.translation import ugettext |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
|
2879
cb0f9b4646aa
Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2871
diff
changeset
|
33 |
from soc.logic import system |
2817
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
from soc.tasks.helper import error_handler |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
from soc.views.helper import redirects |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
from soc.modules.ghop.logic.models import task as ghop_task_logic |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
DEF_TASK_UPDATE_SUBJECT_FMT = ugettext('[GHOP Task Update] %(title)s') |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
def getDjangoURLPatterns(): |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
"""Returns the URL patterns for the tasks in this module. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
""" |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
patterns = [ |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
(r'^tasks/ghop/task/update$', |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
'soc.modules.ghop.tasks.task_update.updateGHOPTask'), |
2826
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
50 |
(r'^tasks/ghop/task/mail/create$', |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
51 |
'soc.modules.ghop.tasks.task_update.createNotificationMail'), |
2817
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
(r'^tasks/ghop/task/update/student_status$', |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
'soc.modules.ghop.tasks.task_update.updateTasksPostStudentSignUp')] |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
return patterns |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
def spawnUpdateTask(entity): |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
"""Spawns a task to update the state of the task. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
""" |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
update_params = { |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
'ghop_task_key': entity.key().name(), |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
} |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
update_url = '/tasks/ghop/task/update' |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
new_task = taskqueue.Task(eta=entity.deadline, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
params=update_params, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
url=update_url) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
new_task.add('ghop-update') |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
def updateGHOPTask(request, *args, **kwargs): |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
"""Method executed by Task Queue API to update a GHOP Task to |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
relevant state. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
Expects the ghop_task_key entry to be present in the POST dict. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
Args: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
request: the standard Django HTTP request object |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
""" |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
post_dict = request.POST |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
84 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
85 |
key_name = post_dict.get('ghop_task_key') |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
87 |
if not key_name: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
# invalid task data, log and return OK |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |
return error_handler.logErrorAndReturnOK( |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
90 |
'Invalid updateGHOPTask data: %s' % post_dict) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
91 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
92 |
entity = ghop_task_logic.logic.getFromKeyNameOr404(key_name) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
93 |
|
3005
fbdf957cb3a3
Removed obsolete value to unpack in the updateGHOPTask Task.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2879
diff
changeset
|
94 |
entity, comment_entity = ghop_task_logic.logic.updateTaskStatus(entity) |
2817
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
95 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
96 |
if entity: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
97 |
# TODO(madhusudan): does this really mean an unsuccessful update? |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
98 |
# return OK |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
99 |
return http.HttpResponse() |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
100 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
101 |
|
2826
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
102 |
def spawnCreateNotificationMail(entity): |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
103 |
"""Spawns a task to send mail to the user who has subscribed to the specific |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
104 |
task. |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
105 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
106 |
Args: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
107 |
entity: The Comment entity for which mails must be sent |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
108 |
""" |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
109 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
110 |
task_params = { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
111 |
'comment_key': entity.key().id_or_name(), |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
112 |
'task_key': entity.parent_key().id_or_name(), |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
113 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
114 |
task_url = '/tasks/ghop/task/mail/create' |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
115 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
116 |
new_task = taskqueue.Task(params=task_params, url=task_url) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
117 |
new_task.add('mail') |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
118 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
119 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
120 |
def createNotificationMail(request, *args, **kwargs): |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
121 |
"""Appengine task that sends mail to the subscribed users. |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
122 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
123 |
Expects the following to be present in the POST dict: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
124 |
comment_key: Specifies the comment id for which to send the notifications |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
125 |
task_key: Specifies the task key name for which the comment belongs to |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
126 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
127 |
Args: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
128 |
request: Django Request object |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
129 |
""" |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
130 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
131 |
from soc.modules.ghop.logic.helper import notifications as ghop_notifications |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
132 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
133 |
from soc.modules.ghop.logic.models import comment as ghop_comment_logic |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
134 |
from soc.modules.ghop.logic.models import task_subscription as \ |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
135 |
ghop_task_subscription_logic |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
136 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
137 |
# set default batch size |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
138 |
batch_size = 10 |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
139 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
140 |
post_dict = request.POST |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
141 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
142 |
comment_key = post_dict.get('comment_key') |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
143 |
task_key = post_dict.get('task_key') |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
144 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
145 |
if not (comment_key and task_key): |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
146 |
# invalid task data, log and return OK |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
147 |
return error_handler.logErrorAndReturnOK( |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
148 |
'Invalid createNotificationMail data: %s' % post_dict) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
149 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
150 |
comment_key = long(comment_key) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
151 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
152 |
# get the task entity under which the specified comment was made |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
153 |
task_entity = ghop_task_logic.logic.getFromKeyName(task_key) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
154 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
155 |
# get the comment for the given id |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
156 |
comment_entity = ghop_comment_logic.logic.getFromID( |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
157 |
comment_key, task_entity) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
158 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
159 |
if not comment_entity: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
160 |
# invalid comment specified, log and return OK |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
161 |
return error_handler.logErrorAndReturnOK( |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
162 |
'Invalid comment specified: %s/%s' % (comment_key, task_key)) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
163 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
164 |
# check and retrieve the subscriber_start_key that has been done last |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
165 |
if 'subscriber_start_index' in post_dict: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
166 |
subscriber_start_index = post_dict['subscriber_start_index'] |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
167 |
else: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
168 |
subscriber_start_index = 0 |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
169 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
170 |
# get all subscribers to GHOP task |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
171 |
fields = { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
172 |
'task': task_entity, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
173 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
174 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
175 |
ts_entity = ghop_task_subscription_logic.logic.getForFields( |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
176 |
fields, unique=True) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
177 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
178 |
subscribers = db.get(ts_entity.subscribers[ |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
179 |
subscriber_start_index:subscriber_start_index+batch_size]) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
180 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
181 |
task_url = "http://%(host)s%(task)s" % { |
2879
cb0f9b4646aa
Revert "revert wrong head"
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2871
diff
changeset
|
182 |
'host': system.getHostname(), |
2826
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
183 |
'task': redirects.getPublicRedirect( |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
184 |
task_entity, {'url_name': 'ghop/task'}), |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
185 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
186 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
187 |
# create the data for the mail to be sent |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
188 |
message_properties = { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
189 |
'task_url': task_url, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
190 |
'redirect_url': "%(task_url)s#c%(cid)d" % { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
191 |
'task_url': task_url, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
192 |
'cid': comment_entity.key().id_or_name() |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
193 |
}, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
194 |
'comment_entity': comment_entity, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
195 |
'task_entity': task_entity, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
196 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
197 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
198 |
subject = DEF_TASK_UPDATE_SUBJECT_FMT % { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
199 |
'title': task_entity.title, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
200 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
201 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
202 |
for subscriber in subscribers: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
203 |
ghop_notifications.sendTaskUpdate(entity, subject, message_properties) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
204 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
205 |
if len(subscribers) == batch_size: |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
206 |
# spawn task for sending out notifications to next set of subscribers |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
207 |
next_start = subscriber_start_index + batch_size |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
208 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
209 |
task_params = { |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
210 |
'comment_key': comment_key, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
211 |
'task_key': task_key, |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
212 |
'subscriber_start_index': next_start |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
213 |
} |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
214 |
task_url = '/tasks/ghop/task/mail/create' |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
215 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
216 |
new_task = taskqueue.Task(params=task_params, url=task_url) |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
217 |
new_task.add('mail') |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
218 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
219 |
# return OK |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
220 |
return http.HttpResponse() |
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
221 |
|
211783aa20d5
Added Task for sending out emails to subscribed users about a Comment.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
2817
diff
changeset
|
222 |
|
2817
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
223 |
def updateTasksPostStudentSignUp(request, *args, **kwargs): |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
224 |
"""Appengine task that updates the GHOP Tasks after the student signs up. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
225 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
226 |
Expects the following to be present in the POST dict: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
227 |
student_key: Specifies the student key name who registered |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
228 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
229 |
Args: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
230 |
request: Django Request object |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
231 |
""" |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
232 |
from soc.modules.ghop.logic.models import student as ghop_student_logic |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
233 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
234 |
post_dict = request.POST |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
235 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
236 |
student_key = post_dict.get('student_key') |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
237 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
238 |
if not student_key: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
239 |
# invalid student data, log and return OK |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
240 |
return error_handler.logErrorAndReturnOK( |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
241 |
'Invalid Student data: %s' % post_dict) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
242 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
243 |
student_entity = ghop_student_logic.logic.getFromKeyNameOr404(student_key) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
244 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
245 |
# retrieve all tasks currently assigned to the user |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
246 |
task_fields = { |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
247 |
'user': student_entity.user, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
248 |
} |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
249 |
task_entities = ghop_task_logic.logic.getForFields(task_fields) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
250 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
251 |
# TODO(madhusudan) move this to the Task Logic |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
252 |
# Make sure the tasks store references to the student as well as |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
253 |
# closing all tasks that are AwaitingRegistration. |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
254 |
for task_entity in task_entities: |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
255 |
task_entity.student = student_entity |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
256 |
if task_entity.status == 'AwaitingRegistration': |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
257 |
task_entities.remove(task_entity) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
258 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
259 |
properties = {'status': 'Closed'} |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
260 |
changes = [ugettext('User-MelangeAutomatic'), |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
261 |
ugettext('Action-Student registered'), |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
262 |
ugettext('Status-%s' % (properties['status']))] |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
263 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
264 |
comment_properties = { |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
265 |
'parent': task_entity, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
266 |
'scope_path': task_entity.key().name(), |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
267 |
'created_by': None, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
268 |
'changes': changes, |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
269 |
'content': ugettext( |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
270 |
'(The Melange Automated System has detected that the student ' |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
271 |
'has signed up for the program and hence has closed this task.'), |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
272 |
} |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
273 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
274 |
ghop_task_logic.logic.updateEntityPropertiesWithCWS( |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
275 |
task_entity, properties, comment_properties) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
276 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
277 |
db.put(task_entities) |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
278 |
|
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
279 |
# return OK |
c31428f08daa
Added GAE tasks that are related to updating GHOP Tasks.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
280 |
return http.HttpResponse() |