Changed the conversion starter system to an update starter system.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 12 Sep 2009 21:33:52 +0200
changeset 2911 2ddd386d1dbd
parent 2910 60d56cf01b54
child 2912 55adeea795ab
Changed the conversion starter system to an update starter system. Also increased the usability of the update page by adding more information abou t each update that can be done and for which version number this applies.
app/soc/modules/soc_core/callback.py
app/soc/tasks/convert.py
app/soc/tasks/start.py
app/soc/tasks/start_update.py
app/soc/templates/soc/tasks/convert.html
app/soc/templates/soc/tasks/run_update.html
app/soc/templates/soc/tasks/start.html
app/soc/templates/soc/tasks/start_update.html
--- a/app/soc/modules/soc_core/callback.py	Sat Sep 12 21:27:17 2009 +0200
+++ b/app/soc/modules/soc_core/callback.py	Sat Sep 12 21:33:52 2009 +0200
@@ -22,9 +22,8 @@
 
 
 from soc.tasks import grading_survey_group as grading_group_tasks
-from soc.tasks import start as start_tasks
+from soc.tasks import start_update
 from soc.tasks import surveys as survey_tasks
-from soc.tasks import convert as convert_tasks
 from soc.views.models import club
 from soc.views.models import club_app
 from soc.views.models import club_admin
@@ -109,9 +108,8 @@
     self.core.registerSitemapEntry(user.view.getDjangoURLPatterns())
 
     # register task URL's
-    self.core.registerSitemapEntry(convert_tasks.getDjangoURLPatterns())
     self.core.registerSitemapEntry(grading_group_tasks.getDjangoURLPatterns())
-    self.core.registerSitemapEntry(start_tasks.getDjangoURLPatterns())
+    self.core.registerSitemapEntry(start_update.getDjangoURLPatterns())
     self.core.registerSitemapEntry(survey_tasks.getDjangoURLPatterns())
 
   def registerWithSidebar(self):
--- a/app/soc/tasks/convert.py	Sat Sep 12 21:27:17 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-#!/usr/bin/python2.5
-#
-# Copyright 2009 the Melange authors.
-#
-# 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.
-
-"""Tasks conversion starter.
-"""
-
-__authors__ = [
-  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
-  ]
-
-
-from django import http
-from django.template import loader
-
-
-def getDjangoURLPatterns():
-  """Returns the URL patterns for the view in this module.
-  """
-
-
-  patterns = [(r'tasks/convert/([a-z]+)$', 'soc.tasks.convert.runner')]
-
-  return patterns
-
-
-class TaskRunner(object):
-  """Runs one of the supported task starters.
-  """
-
-  def __init__(self):
-    """Initializes the TaskRunner.
-    """
-
-    self.options = {
-        'program': self.startProgramConversion,
-        'organization': self.startOrganizationConversion,
-        'student': self.startStudentConversion,
-    }
-
-  def getOptions(self):
-    """Returns the supported option types.
-    """
-
-    return self.options.keys()
-
-  def __call__(self, request, option):
-    """Starts the specified task.
-    """
-
-    context = {
-        'page_name': 'Start conversion job',
-    }
-
-    fun = self.options.get(option)
-    if not fun:
-      template = 'soc/error.html'
-      context['message'] = 'Uknown option "%s".' % option
-    else:
-      template = 'soc/tasks/convert.html'
-      context['option'] = option
-      context['success'] = fun(request)
-
-    content = loader.render_to_string(template, dictionary=context)
-    return http.HttpResponse(content)
-
-  def startProgramConversion(self, request):
-    """
-    """
-
-    # TODO(ljvderijk): implement this
-
-    return False
-
-  def startOrganizationConversion(self, request):
-    """
-    """
-
-    # TODO(ljvderijk): implement this
-
-    return False
-
-  def startStudentConversion(self, request):
-    """
-    """
-
-    # TODO(ljvderijk): implement this
-
-    return False
-
-
-runner = TaskRunner()
--- a/app/soc/tasks/start.py	Sat Sep 12 21:27:17 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-#!/usr/bin/python2.5
-#
-# Copyright 2009 the Melange authors.
-#
-# 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.
-
-"""Tasks conversion starter.
-"""
-
-__authors__ = [
-  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
-  ]
-
-
-from django import http
-from django.template import loader
-
-from soc.tasks import convert
-
-
-def getDjangoURLPatterns():
-  """Returns the URL patterns for the view in this module.
-  """
-
-  patterns = [(r'tasks/start$',
-               'soc.tasks.start.startTasks')]
-
-  return patterns
-
-
-def startTasks(request):
-  """Presents a view that allows the user to start conversion tasks.
-  """
-
-  template = 'soc/tasks/start.html'
-
-  context = {
-      'page_name': 'Task starter',
-      'options': convert.runner.getOptions(),
-    }
-
-  content = loader.render_to_string(template, dictionary=context)
-  return http.HttpResponse(content)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/tasks/start_update.py	Sat Sep 12 21:33:52 2009 +0200
@@ -0,0 +1,166 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# 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.
+
+"""Version update Tasks starters.
+"""
+
+__authors__ = [
+  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+  ]
+
+
+from django import http
+from django.template import loader
+from django.utils.translation import ugettext
+
+from soc.views.helper import responses
+
+
+def getDjangoURLPatterns():
+  """Returns the URL patterns for the views in this module.
+  """
+
+  patterns = [(r'tasks/update/start$', 'soc.tasks.start_update.startTasks'),
+              (r'tasks/update/([a-z]+)$', 'soc.tasks.start_update.runner')]
+
+  return patterns
+
+
+def startTasks(request):
+  """Presents a view that allows the user to start update tasks.
+  """
+
+  template = 'soc/tasks/start_update.html'
+
+  context = responses.getUniversalContext(request)
+
+  options = runner.getOptions()
+
+  sorted_keys = []
+  for key, option in options.iteritems():
+    option['name'] = key
+    sorted_keys.append(
+        (option['from_version'], option['in_version_order'], key))
+
+  # sort the keys
+  sorted_keys.sort()
+
+  # store only the true option
+  sorted_options = []
+
+  for key_tuple in sorted_keys:
+    option_key = key_tuple[2]
+    sorted_options.append(options[option_key])
+
+  context.update(
+      page_name='Update Tasks starter',
+      options=sorted_options,
+      )
+
+  content = loader.render_to_string(template, dictionary=context)
+  return http.HttpResponse(content)
+
+
+class TaskRunner(object):
+  """Runs one of the supported task starters.
+  """
+
+  def __init__(self):
+    """Initializes the TaskRunner.
+    """
+
+    self.options = {
+        'program': self.programConversion(),
+        'student': self.studentConversion(),
+        'organization': self.orgConversion(),
+    }
+
+  def getOptions(self):
+    """Returns the supported options.
+    """
+
+    return self.options
+
+  def __call__(self, request, option):
+    """Starts the specified task.
+    """
+
+    context = responses.getUniversalContext(request)
+    context['page_name'] = 'Start Update Task'
+
+    option = self.options.get(option)
+    if not option:
+      template = 'soc/error.html'
+      context['message'] = 'Uknown option "%s".' % option
+    else:
+      template = 'soc/tasks/run_update.html'
+      context['option'] = option
+      context['success'] = option['updater'](request)
+
+    content = loader.render_to_string(template, dictionary=context)
+    return http.HttpResponse(content)
+
+  def programConversion(self):
+    """
+    """
+
+    description = ugettext('This converts the Program models to contain X,Y,Z. '
+                           'Note that this conversion will only work after Q')
+
+    # TODO(ljvderijk): implement this
+    updater = lambda x:False
+
+    conversion_information = {'from_version': 'V-1',
+                              'in_version_order': 2,
+                              'description': description,
+                              'updater': updater}
+
+    return conversion_information
+
+  def studentConversion(self):
+    """
+    """
+
+    description = ugettext('This converts the Student models to contain X,Y,Z.')
+
+    # TODO(ljvderijk): implement this
+    updater = lambda x:False
+
+    conversion_information = {'from_version': 'V-1',
+                              'in_version_order': 1,
+                              'description': description,
+                              'updater': updater}
+
+    return conversion_information
+
+  def orgConversion(self):
+    """
+    """
+
+    description = ugettext('This converts the Organization models to contain X,Y,Z.')
+
+    # TODO(ljvderijk): implement this
+    updater = lambda x:False
+
+    conversion_information = {'from_version': 'V-2',
+                              'in_version_order': 1,
+                              'description': description,
+                              'updater': updater}
+
+    return conversion_information
+
+runner = TaskRunner()
--- a/app/soc/templates/soc/tasks/convert.html	Sat Sep 12 21:27:17 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-{% 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 %}
-Started conversion job {{ option }}. <br />
-Job starter was {% if not success %}not {% endif %} successfull. <br />
-
-{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/tasks/run_update.html	Sat Sep 12 21:33: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 %}
+<p>
+Trying to start the update Task with the following description:<br /> 
+{{ option.description }}. <br />
+</p>
+
+The Task was {% if not success %}not {% endif %} successfully started. <br />
+Click <a href="/tasks/update/start">here</a> to go back to the list of possible update tasks.
+
+{% endblock %}
--- a/app/soc/templates/soc/tasks/start.html	Sat Sep 12 21:27:17 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-{% 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 %}
-{% for option in options %}
-Start <a target="_blank" href="/tasks/convert/{{ option }}">
-convert {{ option }}</a> job. <br/>
-{% endfor %}
-
-{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/tasks/start_update.html	Sat Sep 12 21:33:52 2009 +0200
@@ -0,0 +1,27 @@
+{% 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 %}
+
+The updates are sorted per version.
+
+{% for option in options %}
+<p>
+If you are updating from version <b>{{ option.from_version }}</b> or earlier.
+Please click <a href="/tasks/update/{{option.name}}">here</a> to run the following update:<br />
+{{option.description}}
+</p>
+{% endfor %}
+
+{% endblock %}