author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Mon, 05 Oct 2009 19:09:58 +0200 | |
changeset 3015 | ad05c8063e37 |
parent 3004 | 8485ae85de54 |
permissions | -rw-r--r-- |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
17 |
"""Version update Tasks runner. |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
] |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
from django import http |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
from django.template import loader |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from django.utils.translation import ugettext |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
|
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
30 |
from soc.tasks.helper import error_handler |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
31 |
from soc.tasks.updates import student_school_type |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
from soc.views.helper import responses |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
def getDjangoURLPatterns(): |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
"""Returns the URL patterns for the views in this module. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
|
2925
d1de20978875
Moved the updater to its own module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2911
diff
changeset
|
39 |
patterns = [ |
d1de20978875
Moved the updater to its own module.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2911
diff
changeset
|
40 |
(r'tasks/update/start$', 'soc.tasks.updates.start_update.startTasks'), |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
41 |
(r'tasks/update/start/([0-9_a-z]+)$', |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
42 |
'soc.tasks.updates.start_update.start_task'), |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
43 |
(r'tasks/update/run/([0-9_a-z]+)$', |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
44 |
'soc.tasks.updates.start_update.run_task')] |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
return patterns |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
def startTasks(request): |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
"""Presents a view that allows the user to start update tasks. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
template = 'soc/tasks/start_update.html' |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
context = responses.getUniversalContext(request) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
|
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
57 |
options = task_runner.getOptions() |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
sorted_keys = [] |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
for key, option in options.iteritems(): |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
option['name'] = key |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
sorted_keys.append( |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
(option['from_version'], option['in_version_order'], key)) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
# sort the keys |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
sorted_keys.sort() |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
# store only the true option |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
sorted_options = [] |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
for key_tuple in sorted_keys: |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
option_key = key_tuple[2] |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
sorted_options.append(options[option_key]) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
context.update( |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
page_name='Update Tasks starter', |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
options=sorted_options, |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
80 |
content = loader.render_to_string(template, dictionary=context) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
return http.HttpResponse(content) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
class TaskRunner(object): |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
85 |
"""Runs one of the supported tasks. |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
|
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
88 |
STUDENT_SCHOOL_TYPE = { |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
89 |
'from_version': '0-5-20090914', |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
90 |
'in_version_order': 1, |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
91 |
'description': ugettext( |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
92 |
'Updates due to changes in the Student model. Sets all school_type ' |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
93 |
'entries to University since that was the first type of Student that ' |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
94 |
'was supported.'), |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
95 |
'starter': student_school_type.startSchoolTypeUpdate, |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
96 |
'runner': student_school_type.runSchoolTypeUpdate, |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
97 |
} |
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
98 |
|
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
99 |
|
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
100 |
def __init__(self): |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
101 |
"""Initializes the TaskRunner. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
102 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
103 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
104 |
self.options = { |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
105 |
'student_school_type': self.STUDENT_SCHOOL_TYPE, |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
106 |
} |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
107 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
108 |
def getOptions(self): |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
109 |
"""Returns the supported options. |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
110 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
111 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
112 |
return self.options |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
113 |
|
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
114 |
def startTask(self, request, option_name): |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
115 |
"""Starts the specified Task for the given option. |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
116 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
117 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
118 |
context = responses.getUniversalContext(request) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
119 |
context['page_name'] = 'Start Update Task' |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
120 |
|
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
121 |
option = self.options.get(option_name) |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
122 |
if not option: |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
123 |
template = 'soc/error.html' |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
124 |
context['message'] = 'Uknown option "%s".' % option_name |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
125 |
else: |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
126 |
template = 'soc/tasks/run_update.html' |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
127 |
context['option'] = option |
2932
666d31bd43bd
Fixed the Student update to properly find its own URL.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2931
diff
changeset
|
128 |
context['success'] = option['starter'](request, |
666d31bd43bd
Fixed the Student update to properly find its own URL.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2931
diff
changeset
|
129 |
self._getRunUpdateURL(option_name)) |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
130 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
131 |
content = loader.render_to_string(template, dictionary=context) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
132 |
return http.HttpResponse(content) |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
133 |
|
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
134 |
def _getRunUpdateURL(self, option): |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
135 |
"""Returns the URL to run a specific update. |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
136 |
|
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
137 |
Args: |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
138 |
option: the update option for which the URL should returned |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
139 |
""" |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
140 |
return '/tasks/update/run/%s' % option |
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
141 |
|
3004
8485ae85de54
Also pass along the args when running an update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2932
diff
changeset
|
142 |
def runTask(self, request, option_name, *args, **kwargs): |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
143 |
"""Runs the specified Task for the given option. |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
144 |
""" |
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
145 |
|
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
146 |
option = self.options.get(option_name) |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
147 |
|
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
148 |
if not option: |
2931
e89022c0657f
Enabled the Student School type updater.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2928
diff
changeset
|
149 |
error_handler('Uknown Updater option "%s".' % option_name) |
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
150 |
else: |
3004
8485ae85de54
Also pass along the args when running an update.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2932
diff
changeset
|
151 |
return option['runner'](request, *args, **kwargs) |
2911
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
152 |
|
2ddd386d1dbd
Changed the conversion starter system to an update starter system.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
153 |
|
2928
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
154 |
task_runner = TaskRunner() |
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
155 |
start_task = task_runner.startTask |
76d5782542dd
Changed the TaskRunner to start and run update tasks.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2925
diff
changeset
|
156 |
run_task = task_runner.runTask |