Added support for mutliple edit forms based on entity type
This makes it possible to have different edit forms in timeline based
on which workflow type is used.
Patch by: Sverre Rabbelier
--- a/app/gsoc/logic/models/timeline.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/gsoc/logic/models/timeline.py Wed Jan 07 21:58:43 2009 +0000
@@ -23,9 +23,9 @@
from soc.logic.models import timeline as timeline_logic
-from soc.logic.models import program as program_logic
import gsoc.models.timeline
+import soc.models.timeline
class Logic(timeline_logic.Logic):
@@ -33,7 +33,8 @@
"""
def __init__(self, model=gsoc.models.timeline.Timeline,
- base_model=None, scope_logic=program_logic):
+ base_model=soc.models.timeline.Timeline,
+ scope_logic=None):
"""Defines the name, key_name and model for this entity.
"""
--- a/app/soc/logic/models/program.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/soc/logic/models/program.py Wed Jan 07 21:58:43 2009 +0000
@@ -26,6 +26,8 @@
from soc.logic.models import base
from soc.logic.models import sponsor as sponsor_logic
+import gsoc.logic.models.timeline
+import soc.logic.models.timeline
import soc.models.program
@@ -33,6 +35,9 @@
"""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):
"""Defines the name, key_name and model for this entity.
--- a/app/soc/logic/models/timeline.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/soc/logic/models/timeline.py Wed Jan 07 21:58:43 2009 +0000
@@ -23,7 +23,6 @@
from soc.logic.models import base
-from soc.logic.models import program as program_logic
import soc.models.timeline
@@ -33,7 +32,7 @@
"""
def __init__(self, model=soc.models.timeline.Timeline,
- base_model=None, scope_logic=program_logic):
+ base_model=None, scope_logic=None):
"""Defines the name, key_name and model for this entity.
"""
--- a/app/soc/views/helper/params.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/soc/views/helper/params.py Wed Jan 07 21:58:43 2009 +0000
@@ -68,6 +68,8 @@
from the cleaning module.
"""
+ logic = params['logic']
+
rights = {}
rights['unspecified'] = []
rights['any_access'] = [access.checkIsLoggedIn]
@@ -82,7 +84,7 @@
new_params = {}
new_params['rights'] = rights
- new_params['scope_logic'] = params['logic'].getScopeLogic()
+ new_params['scope_logic'] = logic.getScopeLogic()
# Do not expand edit_redirect to allow it to be overriden without suffix
new_params['edit_redirect'] = '/%(url_name)s/edit/%(suffix)s'
@@ -158,7 +160,7 @@
new_params['dynabase'] = helper.forms.BaseForm
create_dynafields = {
- 'clean_link_id': cleaning.clean_new_link_id(params['logic']),
+ 'clean_link_id': cleaning.clean_new_link_id(logic),
'clean_feed_url': cleaning.clean_feed_url,
}
create_dynafields.update(params.get('create_extra_dynafields', {}))
@@ -183,10 +185,10 @@
# These need to be constructed separately, because they require
# parameters that can be defined either in params, or new_params.
if not 'create_form' in params:
- params['create_form'] = getCreateForm(params)
+ params['create_form'] = getCreateForm(params, logic.getModel())
if not 'edit_form' in params:
- params['edit_form'] = getEditForm(params)
+ params['edit_form'] = getEditForm(params, params['create_form'])
if not 'key_fields_pattern' in params:
params['key_fields_pattern'] = getKeyFieldsPattern(params)
@@ -194,7 +196,7 @@
return params
-def getCreateForm(params):
+def getCreateForm(params, model):
"""Constructs a new CreateForm using params.
Params usage:
@@ -208,7 +210,7 @@
create_form = dynaform.newDynaForm(
dynabase = params['dynabase'],
- dynamodel = params['logic'].getModel(),
+ dynamodel = model,
dynainclude = params['create_dynainclude'],
dynaexclude = params['create_dynaexclude'],
dynafields = params['create_dynafields'],
@@ -217,7 +219,7 @@
return create_form
-def getEditForm(params):
+def getEditForm(params, base_form):
"""Constructs a new EditForm using params.
Params usage:
@@ -229,7 +231,7 @@
"""
edit_form = dynaform.extendDynaForm(
- dynaform = params['create_form'],
+ dynaform = base_form,
dynainclude = params['edit_dynainclude'],
dynaexclude = params['edit_dynaexclude'],
dynafields = params['edit_dynafields'],
--- a/app/soc/views/models/program.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/soc/views/models/program.py Wed Jan 07 21:58:43 2009 +0000
@@ -27,17 +27,16 @@
from soc.logic import cleaning
from soc.logic import dicts
+from soc.logic.models import program as program_logic
from soc.views import helper
from soc.views.helper import access
from soc.views.helper import redirects
+from soc.views.helper import widgets
from soc.views.models import base
from soc.views.models import document as document_view
from soc.views.models import sponsor as sponsor_view
from soc.views.sitemap import sidebar
-import gsoc.models.timeline
-import soc.models.timeline
-
import soc.logic.models.program
@@ -82,6 +81,11 @@
'clean_link_id': cleaning.clean_link_id,
}
+ new_params['edit_extra_dynafields'] = {
+ 'workflow': forms.CharField(widget=widgets.ReadOnlyInput(),
+ required=True),
+ }
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -101,12 +105,9 @@
"""Creates and stores a timeline model for the given type of program.
"""
- timelines = {'gsoc' : gsoc.logic.models.timeline.logic,
- 'ghop' : soc.logic.models.timeline.logic,}
-
workflow = fields['workflow']
- timeline_logic = timelines[workflow]
+ timeline_logic = program_logic.logic.TIMELINE_LOGIC[workflow]
key_fields = self._logic.getKeyFieldsFromDict(fields)
key_name = self._logic.getKeyNameForFields(key_fields)
--- a/app/soc/views/models/timeline.py Wed Jan 07 21:57:48 2009 +0000
+++ b/app/soc/views/models/timeline.py Wed Jan 07 21:58:43 2009 +0000
@@ -25,6 +25,8 @@
from django import forms
from soc.logic import dicts
+from soc.logic.models import program as program_logic
+from soc.views.helper import params as params_helper
from soc.views.models import base
import soc.logic.models.timeline
@@ -62,6 +64,24 @@
super(View, self).__init__(params=params)
+ for name, value in program_logic.logic.TIMELINE_LOGIC.iteritems():
+ create_form = params_helper.getCreateForm(self._params, value.getModel())
+ edit_form = params_helper.getEditForm(self._params, create_form)
+ self._params['edit_form_%s' % name] = edit_form
+
+ def edit(self, request, access_type,
+ page_name=None, params=None, seed=None, **kwargs):
+ """See base.View.edit
+ """
+
+ params = dicts.merge(params, self._params)
+
+ program = program_logic.logic.getFromKeyName(kwargs['scope_path'])
+ params['edit_form'] = params["edit_form_%s" % program.workflow]
+
+ return super(View, self).edit(request, access_type, page_name=page_name,
+ params=params, seed=seed, **kwargs)
+
view = View()