|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2009 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """Tasks conversion starter. |
|
18 """ |
|
19 |
|
20 __authors__ = [ |
|
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
|
22 ] |
|
23 |
|
24 |
|
25 from django import http |
|
26 from django.template import loader |
|
27 |
|
28 |
|
29 def getDjangoURLPatterns(): |
|
30 """Returns the URL patterns for the view in this module. |
|
31 """ |
|
32 |
|
33 |
|
34 patterns = [(r'tasks/convert/([a-z]+)$', 'soc.tasks.convert.runner')] |
|
35 |
|
36 return patterns |
|
37 |
|
38 |
|
39 class TaskRunner(object): |
|
40 """Runs one of the supported task starters. |
|
41 """ |
|
42 |
|
43 def __init__(self): |
|
44 """Initializes the TaskRunner. |
|
45 """ |
|
46 |
|
47 self.options = { |
|
48 'program': self.startProgramConversion, |
|
49 'organization': self.startOrganizationConversion, |
|
50 'student': self.startStudentConversion, |
|
51 } |
|
52 |
|
53 def getOptions(self): |
|
54 """Returns the supported option types. |
|
55 """ |
|
56 |
|
57 return self.options.keys() |
|
58 |
|
59 def __call__(self, request, option): |
|
60 """Starts the specified task. |
|
61 """ |
|
62 |
|
63 context = { |
|
64 'page_name': 'Start conversion job', |
|
65 } |
|
66 |
|
67 fun = self.options.get(option) |
|
68 if not fun: |
|
69 template = 'soc/error.html' |
|
70 context['message'] = 'Uknown option "%s".' % option |
|
71 else: |
|
72 template = 'soc/tasks/convert.html' |
|
73 context['option'] = option |
|
74 context['success'] = fun(request) |
|
75 |
|
76 content = loader.render_to_string(template, dictionary=context) |
|
77 return http.HttpResponse(content) |
|
78 |
|
79 def startProgramConversion(self, request): |
|
80 """ |
|
81 """ |
|
82 |
|
83 # TODO(ljvderijk): implement this |
|
84 |
|
85 return False |
|
86 |
|
87 def startOrganizationConversion(self, request): |
|
88 """ |
|
89 """ |
|
90 |
|
91 # TODO(ljvderijk): implement this |
|
92 |
|
93 return False |
|
94 |
|
95 def startStudentConversion(self, request): |
|
96 """ |
|
97 """ |
|
98 |
|
99 # TODO(ljvderijk): implement this |
|
100 |
|
101 return False |
|
102 |
|
103 |
|
104 runner = TaskRunner() |