Remove redundant dicts for URL patterns and sidebar menu text, and use the
existing params dict instead. Add a sidebar_heading customization to params.
Better differentiate the 'User (self)' and 'Users' sidebar menus. Remove
the redundant Site settings menu items now that the Site entity is a singleton.
Patch by: Todd Larsen
--- a/app/soc/views/models/base.py Sat Nov 22 01:55:19 2008 +0000
+++ b/app/soc/views/models/base.py Sat Nov 22 03:13:59 2008 +0000
@@ -55,7 +55,7 @@
DEF_SUBMIT_MSG_PARAM_NAME = 's'
DEF_SUBMIT_MSG_PROFILE_SAVED = 0
- DEF_CREATE_NEW_ENTITY_MSG = ugettext_lazy(
+ DEF_CREATE_NEW_ENTITY_MSG_FMT = ugettext_lazy(
' You can create a new %(entity_type)s by visiting'
' <a href="%(create)s">Create '
'a New %(entity_type)s</a> page.')
@@ -83,7 +83,10 @@
save_message: the message to display when the entity is saved
edit_params: the params to use when editing
sidebar: the sidebar menu items for this view
- sidebar_defaults: a dictionary with defaults for the sidebar
+ sidebar_defaults: a dictionary with defaults for the sidebar; each
+ value in the dict is a two-tuple:
+ (url_format, # supplied a single positional url_name
+ menu_text_format) # supplied the params dict
"""
rights = {}
@@ -102,24 +105,25 @@
new_params['sidebar'] = None
new_params['sidebar_defaults'] = [
('/%s/create', 'New %(name)s'),
- ('/%s/list', 'List %(plural)s'),
+ ('/%s/list', 'List %(name_plural)s'),
]
new_params['sidebar_additional'] = []
+ new_params['sidebar_heading'] = None
new_params['key_fields_prefix'] = []
new_params['django_patterns'] = None
new_params['django_patterns_defaults'] = [
(r'^%(url_name)s/show/%(key_fields)s$',
- 'soc.views.models.%s.public', 'Show %(name)s'),
+ 'soc.views.models.%s.public', 'Show %(name_short)s'),
(r'^%(url_name)s/create$',
- 'soc.views.models.%s.create', 'Create %(name)s'),
+ 'soc.views.models.%s.create', 'Create %(name_short)s'),
(r'^%(url_name)s/create/%(key_fields)s$',
- 'soc.views.models.%s.create', 'Create %(name)s'),
+ 'soc.views.models.%s.create', 'Create %(name_short)s'),
(r'^%(url_name)s/delete/%(key_fields)s$',
- 'soc.views.models.%s.delete', 'Delete %(name)s'),
+ 'soc.views.models.%s.delete', 'Delete %(name_short)s'),
(r'^%(url_name)s/edit/%(key_fields)s$',
- 'soc.views.models.%s.edit', 'Edit %(name)s'),
+ 'soc.views.models.%s.edit', 'Edit %(name_short)s'),
(r'^%(url_name)s/list$',
'soc.views.models.%s.list', 'List %(name_plural)s'),
]
@@ -234,7 +238,7 @@
except soc.logic.out_of_band.ErrorResponse, error:
if not seed:
template = params['public_template']
- error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
+ error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
'entity_type_lower' : params['name'].lower(),
'entity_type' : params['name'],
'create' : params['missing_redirect']
@@ -396,7 +400,7 @@
entity = self._logic.getIfFields(key_fields)
except soc.logic.out_of_band.ErrorResponse, error:
template = params['edit_template']
- error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG % {
+ error.message = error.message + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
'entity_type_lower' : params['name'].lower(),
'entity_type' : params['name'],
'create' : params['missing_redirect']
@@ -560,15 +564,9 @@
result = []
- for url, title in defaults:
+ for url, menu_text in defaults:
url = url % params['url_name'].lower()
-
- title = title % {
- 'name': params['name'],
- 'plural': params['name_plural']
- }
-
- item = (url, title)
+ item = (url, menu_text % params)
result.append(item)
for item in params['sidebar_additional']:
@@ -587,11 +585,15 @@
items = []
- for url, title in self._getSidebarItems(params):
- items.append({'url': url, 'title': title})
+ for url, menu_text in self._getSidebarItems(params):
+ items.append({'url': url, 'title': menu_text})
res = {}
- res['heading'] = params['name']
+
+ if not params['sidebar_heading']:
+ params['sidebar_heading'] = params['name']
+
+ res['heading'] = params['sidebar_heading']
res['items'] = items
return res
@@ -599,7 +601,8 @@
def getDjangoURLPatterns(self, params=None):
"""Retrieves a list of sidebar entries for this view from self._params.
- If self._params['django_patterns'] is None default entries will be constructed.
+ If self._params['django_patterns'] is None default entries will be
+ constructed.
"""
params = dicts.merge(params, self._params)
@@ -615,14 +618,7 @@
patterns = []
for url, module, name in default_patterns:
- name_short = params['name_short']
- name_plural = params['name_plural']
-
- name = name % {
- 'name': name_short,
- 'name_plural': name_plural,
- }
-
+ name = name % params
module = module % params['module_name']
url = url % {
--- a/app/soc/views/models/request.py Sat Nov 22 01:55:19 2008 +0000
+++ b/app/soc/views/models/request.py Sat Nov 22 03:13:59 2008 +0000
@@ -121,7 +121,7 @@
'list_heading': 'soc/request/list/request_heading.html',
}
- params['sidebar_defaults'] = [('/%s/list', 'List %(plural)s')]
+ params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s')]
params['delete_redirect'] = '/' + params['url_name'] + '/list'
params['create_redirect'] = '/' + params['url_name']
--- a/app/soc/views/models/role.py Sat Nov 22 01:55:19 2008 +0000
+++ b/app/soc/views/models/role.py Sat Nov 22 03:13:59 2008 +0000
@@ -190,7 +190,7 @@
default_patterns = self._params['django_patterns_defaults']
default_patterns += [
(r'^%(url_name)s/invite/%(lnp)s$',
- 'soc.views.models.%s.invite', 'Invite %(name)s')]
+ 'soc.views.models.%s.invite', 'Invite %(name_short)s')]
params['django_patterns_defaults'] = default_patterns
patterns = super(RoleView, self).getDjangoURLPatterns(params)
--- a/app/soc/views/models/site.py Sat Nov 22 01:55:19 2008 +0000
+++ b/app/soc/views/models/site.py Sat Nov 22 03:13:59 2008 +0000
@@ -54,9 +54,9 @@
#: list of model fields which will *not* be gathered by the form
exclude = ['inheritance_line', 'home', 'scope', 'scope_path', 'link_id']
- scope_path = forms.CharField(widget=forms.HiddenInput)
+# scope_path = forms.CharField(widget=forms.HiddenInput)
- link_id = forms.CharField(widget=forms.HiddenInput)
+# link_id = forms.CharField(widget=forms.HiddenInput)
class EditForm(CreateForm):
@@ -80,18 +80,20 @@
params = {}
- # add ugettext_lazy ?
+ # TODO(alturin): add ugettext_lazy ?
params['name'] = "Site Settings"
- params['name_short'] = "Site Settings"
+ params['name_short'] = "Site"
params['name_plural'] = "Site Settings"
# lower name and replace " " with "/"
- # for module name lower name and replace " " with "_"
params['url_name'] = "site/settings"
params['module_name'] = "site"
params['edit_form'] = EditForm
params['create_form'] = CreateForm
+ params['sidebar_defaults'] = [('/%s/edit', 'Edit %(name)s')]
+ params['sidebar_heading'] = params['name_short']
+
params['lists_template'] = {
'list_main': 'soc/list/list_main.html',
'list_pagination': 'soc/list/list_pagination.html',
@@ -101,9 +103,6 @@
params['delete_redirect'] = '/' + params['url_name'] + '/list'
- params['sidebar_additional'] = [
- ('/' + params['url_name'] + '/edit', 'Edit Main Site Settings')]
-
params = dicts.merge(original_params, params)
presence.View.__init__(self, original_params=params)
--- a/app/soc/views/models/user.py Sat Nov 22 01:55:19 2008 +0000
+++ b/app/soc/views/models/user.py Sat Nov 22 03:13:59 2008 +0000
@@ -177,6 +177,8 @@
params['delete_redirect'] = '/' + params['url_name'] + '/list'
+ params['sidebar_heading'] = 'Users'
+
params = dicts.merge(original_params, params)
base.View.__init__(self, params=params)
@@ -291,7 +293,7 @@
"""
params = {}
- params['name'] = "User (self)"
+ params['sidebar_heading'] = "User (self)"
params['sidebar'] = [
('/' + self._params['url_name'] + '/edit', 'Profile'),
('/' + self._params['url_name'] + '/roles', 'Roles'),