Enabled the Student School type updater.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 16 Sep 2009 13:38:18 +0200
changeset 2931 e89022c0657f
parent 2930 74d4875b4922
child 2932 666d31bd43bd
Enabled the Student School type updater. The updater now passes along the runner URL to the starter function. Also fixed the TaskRunner to display correct error messages when a invalid option has been specified.
app/soc/tasks/updates/start_update.py
--- a/app/soc/tasks/updates/start_update.py	Wed Sep 16 13:35:53 2009 +0200
+++ b/app/soc/tasks/updates/start_update.py	Wed Sep 16 13:38:18 2009 +0200
@@ -28,6 +28,7 @@
 from django.utils.translation import ugettext
 
 from soc.tasks.helper import error_handler
+from soc.tasks.updates import student_school_type
 from soc.views.helper import responses
 
 
@@ -37,9 +38,9 @@
 
   patterns = [
       (r'tasks/update/start$', 'soc.tasks.updates.start_update.startTasks'),
-      (r'tasks/update/start/([a-z]+)$',
+      (r'tasks/update/start/([0-9_a-z]+)$',
        'soc.tasks.updates.start_update.start_task'),
-      (r'tasks/update/run/([a-z]+)$',
+      (r'tasks/update/run/([0-9_a-z]+)$',
        'soc.tasks.updates.start_update.run_task')]
 
   return patterns
@@ -84,12 +85,15 @@
   """Runs one of the supported tasks.
   """
 
-  ORG_CONVERSION = {
-      'from_version': 'V-2',
+  STUDENT_SCHOOL_TYPE = {
+      'from_version': '0-5-20090914',
       'in_version_order': 1,
-      'description': ugettext('This converts the Organization models to contain X,Y,Z.'),
-      'starter': lambda x:False,
-      'runner': lambda x,**kwargs:http.HttpResponse('TEST OK'),
+      'description': ugettext(
+          'Updates due to changes in the Student model. Sets all school_type '
+          'entries to University since that was the first type of Student that '
+          'was supported.'),
+      'starter': student_school_type.startSchoolTypeUpdate,
+      'runner': student_school_type.runSchoolTypeUpdate,
       }
 
 
@@ -98,7 +102,7 @@
     """
 
     self.options = {
-        'organization': self.ORG_CONVERSION,
+        'student_school_type': self.STUDENT_SCHOOL_TYPE,
     }
 
   def getOptions(self):
@@ -107,33 +111,41 @@
 
     return self.options
 
-  def startTask(self, request, option):
+  def startTask(self, request, option_name):
     """Starts the specified Task for the given option.
     """
 
     context = responses.getUniversalContext(request)
     context['page_name'] = 'Start Update Task'
 
-    option = self.options.get(option)
+    option = self.options.get(option_name)
     if not option:
       template = 'soc/error.html'
-      context['message'] = 'Uknown option "%s".' % option
+      context['message'] = 'Uknown option "%s".' % option_name
     else:
       template = 'soc/tasks/run_update.html'
       context['option'] = option
-      context['success'] = option['starter'](request)
+      context['success'] = option['starter'](request, self._getRunUpdateURL(option_name))
 
     content = loader.render_to_string(template, dictionary=context)
     return http.HttpResponse(content)
 
-  def runTask(self, request, option, **kwargs):
+  def _getRunUpdateURL(self, option):
+    """Returns the URL to run a specific update.
+
+    Args:
+      option: the update option for which the URL should returned
+    """
+    return '/tasks/update/run/%s' % option
+
+  def runTask(self, request, option_name, **kwargs):
     """Runs the specified Task for the given option.
     """
 
-    option = self.options.get(option)
+    option = self.options.get(option_name)
 
     if not option:
-      error_handler('Uknown Updater option "%s".' % option)
+      error_handler('Uknown Updater option "%s".' % option_name)
     else:
       return option['runner'](request, **kwargs)