Moved createTimelineForType to Program Logic.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Wed, 26 Aug 2009 18:37:35 +0200
changeset 2812 9280179e34fd
parent 2811 c8901482dc9c
child 2813 6f7af233b5b0
Moved createTimelineForType to Program Logic. Using polymorphism and the timeline_logic keyword argument the TIMELINE_LOGIC collection can now be removed. Reviewed by: Lennard de Rijk
app/soc/logic/models/program.py
app/soc/views/models/program.py
--- a/app/soc/logic/models/program.py	Wed Aug 26 18:31:19 2009 +0200
+++ b/app/soc/logic/models/program.py	Wed Aug 26 18:37:35 2009 +0200
@@ -18,6 +18,7 @@
 """
 
 __authors__ = [
+    '"Madhusudan.C.S" <madhusudancs@gmail.com>',
     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
     '"Lennard de Rijk" <ljvderijk@gmail.com>',
   ]
@@ -26,7 +27,6 @@
 from soc.logic.models import presence_with_tos
 from soc.logic.models import sponsor as sponsor_logic
 
-import soc.logic.models.timeline
 import soc.models.program
 
 from gsoc.logic.models.timeline import logic as gsoc_timeline_logic
@@ -36,10 +36,6 @@
   """Logic methods for the Program model.
   """
 
-  TIMELINE_LOGIC = {'gsoc' : gsoc.logic.models.timeline.logic,
-                    'ghop' : soc.logic.models.timeline.logic}
-
-
   def __init__(self, model=soc.models.program.Program, 
                base_model=None, scope_logic=sponsor_logic,
                timeline_logic=gsoc_timeline_logic):
@@ -51,5 +47,18 @@
     super(Logic, self).__init__(model=model, base_model=base_model,
                                 scope_logic=scope_logic)
 
+  def createTimelineForType(self, fields):
+    """Creates and stores a timeline model for the given type of program.
+    """
+
+    properties = self.timeline_logic.getKeyFieldsFromFields(fields)
+    key_name = self.timeline_logic.getKeyNameFromFields(properties)
+
+    properties['scope'] = fields['scope']
+
+    timeline = self.timeline_logic.updateOrCreateFromKeyName(properties,
+                                                             key_name)
+    return timeline
+
 
 logic = Logic()
--- a/app/soc/views/models/program.py	Wed Aug 26 18:31:19 2009 +0200
+++ b/app/soc/views/models/program.py	Wed Aug 26 18:37:35 2009 +0200
@@ -18,6 +18,7 @@
 """
 
 __authors__ = [
+    '"Madhusudan.C.S" <madhusudancs@gmail.com>',
     '"Daniel Hans" <daniel.m.hans@gmail.com>',
     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
     '"Lennard de Rijk" <ljvderijk@gmail.com>',
@@ -586,29 +587,13 @@
 
     super(View, self)._editPost(request, entity, fields)
 
-    if not entity:
+    if entity:
       # there is no existing entity so create a new timeline
-      fields['timeline'] = self._createTimelineForType(fields)
+      fields['timeline'] = self._params['logic'].createTimelineForType(fields)
     else:
       # use the timeline from the entity
       fields['timeline'] = entity.timeline
 
-  def _createTimelineForType(self, fields):
-    """Creates and stores a timeline model for the given type of program.
-    """
-
-    workflow = fields['workflow']
-
-    timeline_logic = program_logic.logic.TIMELINE_LOGIC[workflow]
-
-    properties = timeline_logic.getKeyFieldsFromFields(fields)
-    key_name = timeline_logic.getKeyNameFromFields(properties)
-
-    properties['scope'] = fields['scope']
-
-    timeline = timeline_logic.updateOrCreateFromKeyName(properties, key_name)
-    return timeline
-
   @decorators.merge_params
   def getExtraMenus(self, id, user, params=None):
     """Returns the extra menu's for this view.