Make base.View.create lookup the scope if appropriate
Also re-introduce the custom description of the list selection for
the redirection.
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/base.py Wed Dec 03 23:49:10 2008 +0000
+++ b/app/soc/views/models/base.py Thu Dec 04 10:09:38 2008 +0000
@@ -55,6 +55,9 @@
' <a href="%(create)s">Create '
'a New %(entity_type)s</a> page.')
+ DEF_CREATE_INSTRUCTION_MSG_FMT = ugettext_lazy(
+ 'Please select a %s for the new %s.')
+
def __init__(self, params=None):
"""
@@ -137,7 +140,15 @@
kwargs: not used for create()
"""
- params = dicts.merge(params, self._params)
+ new_params = dicts.merge(params, self._params)
+
+ if ('scope_view' in new_params) and ('scope_path' not in kwargs):
+ view = new_params['scope_view'].view
+ redirect = new_params['scope_redirect']
+ return self.select(request, view, redirect,
+ params=params, page_name=page_name, **kwargs)
+
+ params = new_params
# Create page is an edit page with no key fields
empty_kwargs = {}
@@ -479,6 +490,8 @@
params = dicts.merge(params, view.getParams())
params = dicts.merge(params, self._params)
params['list_action'] = (redirect, self._params)
+ params['list_description'] = self.DEF_CREATE_INSTRUCTION_MSG_FMT % (
+ params['name'], self._params['name'])
content = helper.lists.getListContent(request, params)
contents = [content]
--- a/app/soc/views/models/program.py Wed Dec 03 23:49:10 2008 +0000
+++ b/app/soc/views/models/program.py Thu Dec 04 10:09:38 2008 +0000
@@ -75,29 +75,12 @@
(r'^%(url_name)s/create/(?P<scope_path>%(ulnp)s)$',
'soc.views.models.%(module_name)s.create', 'Create %(name_short)s')]
+ new_params['scope_redirect'] = redirects.getCreateRedirect
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
- def create(self, request, **kwargs):
- """Specialized create view to enforce needing a scope_path
-
- This view simply gives control to the base.View.create if the
- scope_path is specified in kwargs. If it is not present, it
- instead displays the result of self.select. Refer to the
- respective docstrings on what they do.
-
- Args:
- see base.View.create
- """
-
- if 'scope_path' in kwargs:
- return super(View, self).create(request, **kwargs)
-
- view = sponsor_view.view
- redirect = redirects.getCreateRedirect
- return self.select(request, view, redirect, **kwargs)
-
view = View()
--- a/app/soc/views/models/role.py Wed Dec 03 23:49:10 2008 +0000
+++ b/app/soc/views/models/role.py Thu Dec 04 10:09:38 2008 +0000
@@ -87,30 +87,12 @@
'Invite %(name_short)s')]
new_params['extra_django_patterns'] = patterns
+ new_params['scope_redirect'] = redirects.getInviteRedirect
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
- def create(self, request, **kwargs):
- """Specialized create view to enforce needing a scope_path
-
- This view simply gives control to the base.View.create if the
- scope_path is specified in kwargs. If it is not present, it
- instead displays the result of self.select. Refer to the
- respective docstrings on what they do.
-
- Args:
- see base.View.create
- """
-
- if 'scope_path' in kwargs:
- return super(View, self).create(request, **kwargs)
-
- view = sponsor_view.view
- redirect = redirects.getInviteRedirect
- return self.select(request, view, redirect, **kwargs)
-
def invite(self, request, page_name=None, params=None, **kwargs):
"""Displays the request promotion to Role page.
"""