Skip to content

Commit

Permalink
Checks now that the route doesn't exist but as map.match() doesn't se…
Browse files Browse the repository at this point in the history
…em to do what is claims to it is

quite hard to determine whether the URL already exists, so we are currently checking with url_for
  • Loading branch information
rossjones committed Jan 3, 2012
1 parent 4d20d50 commit 7007f26
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
13 changes: 7 additions & 6 deletions ckan/config/routing.py
Expand Up @@ -231,18 +231,19 @@ def make_map():

# These named routes are used for custom group forms which will use the
# names below based on the group.type (dataset_group is the default type)
map.connect('dataset_group_index', '/group', controller='group', action='index')
map.connect('dataset_group_list', '/group/list', controller='group', action='list')
map.connect('dataset_group_new', '/group/new', controller='group', action='new')
map.connect('dataset_group_action', '/group/{action}/{id}', controller='group',
map.connect('group_index', '/group', controller='group', action='index')
map.connect('group_list', '/group/list', controller='group', action='list')
map.connect('group_new', '/group/new', controller='group', action='new')
map.connect('group_action', '/group/{action}/{id}', controller='group',
requirements=dict(action='|'.join([
'edit',
'authz',
'history'
]))
)
map.connect('dataset_group_read', '/group/{id}', controller='group', action='read')

map.connect('group_read', '/group/{id}', controller='group', action='read')


register_package_behaviour(map)
register_group_behaviour(map)

Expand Down
10 changes: 8 additions & 2 deletions ckan/controllers/group.py
Expand Up @@ -32,7 +32,7 @@ def register_pluggable_behaviour(map):
exception will be raised.
"""
global _default_controller_behaviour

# Create the mappings and register the fallback behaviour if one is found.
for plugin in PluginImplementations(IGroupForm):
if plugin.is_fallback():
Expand All @@ -45,6 +45,12 @@ def register_pluggable_behaviour(map):
# Create the routes based on group_type here, this will allow us to have top level
# objects that are actually Groups, but first we need to make sure we are not
# clobbering an existing domain
from routes import url_for

u = url_for('/%s/new' % (group_type,) )
if u != '%s_new' % (group_type,):
raise Exception, "Plugin %r would overwrite the default group urls" % plugin

map.connect('%s_new' % (group_type,),
'/%s/new' % (group_type,), controller='group', action='new')
map.connect('%s_read' % (group_type,),
Expand Down Expand Up @@ -325,7 +331,7 @@ def _save_new(self, context, group_type=None):
try:
data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.params))))
data_dict['type'] = group_type or 'dataset_group'
data_dict['type'] = group_type or 'group'
context['message'] = data_dict.get('log_message', '')
group = get_action('group_create')(context, data_dict)

Expand Down
4 changes: 4 additions & 0 deletions ckan/controllers/package.py
Expand Up @@ -85,6 +85,10 @@ def register_pluggable_behaviour(map):
for package_type in plugin.package_types():
# Create a connection between the newly named type and the package controller
# but first we need to make sure we are not clobbering an existing domain
if package_type == 'package':
raise Exception, "The plugin %r would overwrite the default package " \
"implementation urls" % plugin

map.connect('/%s/new' % (package_type,), controller='package', action='new')
map.connect('%s_read' % (package_type,), '/%s/{id}' % (package_type,), controller='package', action='read')
map.connect('%s_action' % (package_type,),
Expand Down
4 changes: 2 additions & 2 deletions ckan/migration/versions/047_rename_package_group_member.py
Expand Up @@ -78,8 +78,8 @@ def upgrade(migrate_engine):
update member set table_name = 'package', capacity = 'member';
update member_revision set table_name = 'package', capacity = 'member';
update "group" set type = 'dataset_group';
update group_revision set type = 'dataset_group';
update "group" set type = 'group';
update group_revision set type = 'group';
ALTER TABLE "member"
Expand Down
2 changes: 1 addition & 1 deletion ckan/model/group.py
Expand Up @@ -57,7 +57,7 @@ def related_packages(self):
class Group(vdm.sqlalchemy.RevisionedObjectMixin,
vdm.sqlalchemy.StatefulObjectMixin,
DomainObject):
def __init__(self, name=u'', title=u'', description=u'', type=u'dataset_group'):
def __init__(self, name=u'', title=u'', description=u'', type=u'group'):
self.name = name
self.title = title
self.description = description
Expand Down
6 changes: 3 additions & 3 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -37,12 +37,12 @@ def setup_class(cls):
{'key': u'original media', 'state': u'active', 'value': u'"book"'}],
'groups': [{'description': u'These are books that David likes.',
'name': u'david',
'type': u'dataset_group',
'type': u'group',
'state': u'active',
'title': u"Dave's books"},
{'description': u'Roger likes these books.',
'name': u'roger',
'type': u'dataset_group',
'type': u'group',
'state': u'active',
'title': u"Roger's books"}],
'isopen': True,
Expand Down Expand Up @@ -868,7 +868,7 @@ def test_16_group_dictized(self):
'version': u'0.7a'}],
'state': u'active',
'title': u'help',
'type': u'dataset_group'}
'type': u'group'}

expected['packages'] = sorted(expected['packages'], key=lambda x: x['name'])

Expand Down

0 comments on commit 7007f26

Please sign in to comment.