Introduced django_extra_patterns
This way no classes ever need to override the getDjangoURLPatterns,
which results in less code, which is also more clear (that is, it is
immediately obvious that a View adds an extra mapping if it sets
the new django_extra_patterns value, or that it overrides the mapping
when it sets django_patterns_defaults.
Patch by: Sverre Rabbelier
--- a/app/soc/views/helper/params.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/helper/params.py Wed Dec 03 23:48:10 2008 +0000
@@ -100,19 +100,20 @@
new_params['link_id_pattern_core'] = linkable.LINK_ID_PATTERN_CORE
new_params['django_patterns'] = None
+ new_params['extra_django_patterns'] = []
new_params['django_patterns_defaults'] = [
(r'^%(url_name)s/show/%(key_fields)s$',
- 'soc.views.models.%s.public', 'Show %(name_short)s'),
+ 'soc.views.models.%(module_name)s.public', 'Show %(name_short)s'),
(r'^%(url_name)s/create$',
- 'soc.views.models.%s.create', 'Create %(name_short)s'),
+ 'soc.views.models.%(module_name)s.create', 'Create %(name_short)s'),
(r'^%(url_name)s/create/%(key_fields)s$',
- 'soc.views.models.%s.create', 'Create %(name_short)s'),
+ 'soc.views.models.%(module_name)s.create', 'Create %(name_short)s'),
(r'^%(url_name)s/delete/%(key_fields)s$',
- 'soc.views.models.%s.delete', 'Delete %(name_short)s'),
+ 'soc.views.models.%(module_name)s.delete', 'Delete %(name_short)s'),
(r'^%(url_name)s/edit/%(key_fields)s$',
- 'soc.views.models.%s.edit', 'Edit %(name_short)s'),
+ 'soc.views.models.%(module_name)s.edit', 'Edit %(name_short)s'),
(r'^%(url_name)s/list$',
- 'soc.views.models.%s.list', 'List %(name_plural)s'),
+ 'soc.views.models.%(module_name)s.list', 'List %(name_plural)s'),
]
new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
--- a/app/soc/views/models/program.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/models/program.py Wed Dec 03 23:48:10 2008 +0000
@@ -68,6 +68,10 @@
'clean_link_id': cleaning.clean_link_id,
}
+ new_params['extra_django_patterns'] = [
+ (r'^%(url_name)s/create/(?P<scope_path>%(ulnp)s)$',
+ 'soc.views.models.%(module_name)s.create', 'Create %(name_short)s')]
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -106,24 +110,6 @@
fields['scope'] = sponsor
- def getDjangoURLPatterns(self, params=None):
- """See base.View.getDjangoURLPatterns().
- """
-
- default_patterns = self._params['django_patterns_defaults']
- default_patterns += [
- (r'^%(url_name)s/create/(?P<scope_path>%(ulnp)s)$',
- 'soc.views.models.%s.create', 'Create %(name_short)s')]
-
- params = {}
- params['django_patterns_defaults'] = default_patterns
-
- params = dicts.merge(params, self._params)
- patterns = super(View, self).getDjangoURLPatterns(params)
-
- return patterns
-
-
view = View()
create = view.create
--- a/app/soc/views/models/role.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/models/role.py Wed Dec 03 23:48:10 2008 +0000
@@ -80,6 +80,16 @@
params: This dictionary should be filled with the parameters
"""
+ new_params = {}
+
+ patterns = [(r'^%(url_name)s/invite/%(lnp)s$',
+ 'soc.views.models.%(module_name)s.invite',
+ 'Invite %(name_short)s')]
+
+ new_params['extra_django_patterns'] = patterns
+
+ params = dicts.merge(params, new_params)
+
super(View, self).__init__(params=params)
def create(self, request, **kwargs):
@@ -129,21 +139,3 @@
contents = [content]
return self._list(request, params, contents, page_name)
-
- def getDjangoURLPatterns(self, params=None):
- """See base.View.getDjangoURLPatterns().
- """
-
- default_patterns = self._params['django_patterns_defaults']
- default_patterns += [
- (r'^%(url_name)s/invite/%(lnp)s$',
- 'soc.views.models.%s.invite', 'Invite %(name_short)s')]
-
- params = {}
- params['django_patterns_defaults'] = default_patterns
-
- params = dicts.merge(params, self._params)
- patterns = super(View, self).getDjangoURLPatterns(params)
-
- return patterns
-
--- a/app/soc/views/models/site.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/models/site.py Wed Dec 03 23:48:10 2008 +0000
@@ -95,6 +95,19 @@
'public': [access.allow]
}
+ patterns = []
+
+ page_name = "Home Page"
+ patterns += [(r'^$', 'soc.views.models.%(module_name)s.main_public',
+ page_name)]
+
+ page_name = "Edit Site Settings"
+ patterns += [(r'^%(url_name)s/edit$',
+ 'soc.views.models.%(module_name)s.main_edit',
+ page_name)]
+
+ new_params['extra_django_patterns'] = patterns
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -135,20 +148,6 @@
return self.edit(request, page_name, seed=key_values, **key_values)
- def getDjangoURLPatterns(self, params=None):
- """See base.View.getDjangoURLPatterns().
- """
-
- page_name = "Home Page"
- patterns = super(View, self).getDjangoURLPatterns()
- patterns += [(r'^$', 'soc.views.models.site.main_public',
- {'page_name': page_name}, page_name)]
-
- page_name = "Edit Site Settings"
- patterns += [(r'^' + self._params['url_name'] + '/edit$',
- 'soc.views.models.site.main_edit',
- {'page_name': page_name}, page_name)]
- return patterns
view = View()
--- a/app/soc/views/models/user_self.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/models/user_self.py Wed Dec 03 23:48:10 2008 +0000
@@ -113,6 +113,18 @@
new_params['sidebar_heading'] = 'Users'
+ patterns = []
+
+ page_name = "Profile"
+ patterns += [(r'^%(url_name)s/edit$',
+ 'soc.views.models.%(module_name)s.edit', page_name)]
+
+ page_name = "Requests Overview"
+ patterns += [(r'^%(url_name)s/roles$',
+ 'soc.views.models.request.list_self', page_name)]
+
+ new_params['django_patterns_defaults'] = patterns
+
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
@@ -234,21 +246,6 @@
return super(View, self).getSidebarLinks(request, params)
- def getDjangoURLPatterns(self, params=None):
- """See base.View.getDjangoURLPatterns().
- """
-
- patterns = []
- patterns += [(r'^' + self._params['url_name'] + '/edit$',
- 'soc.views.models.user_self.edit')]
-
- page_name = "Requests Overview"
- patterns += [(r'^' + self._params['url_name'] + '/roles$',
- 'soc.views.models.request.list_self',
- {'page_name': page_name}, page_name)]
-
- return patterns
-
view = View()
--- a/app/soc/views/sitemap/sitemap.py Wed Dec 03 21:28:16 2008 +0000
+++ b/app/soc/views/sitemap/sitemap.py Wed Dec 03 23:48:10 2008 +0000
@@ -59,13 +59,14 @@
# Construct defaults manualy
default_patterns = params['django_patterns_defaults']
+ default_patterns += params['extra_django_patterns']
key_fields_pattern = params['key_fields_pattern']
patterns = []
for url, module, name in default_patterns:
name = name % params
- module = module % params['module_name']
+ module = module % params
url = url % {
'url_name': params['url_name'],