Skip to content

Commit

Permalink
Merge from organizations-in-core into new demo branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Sep 5, 2012
2 parents 0bf88cd + 42deeef commit e824827
Show file tree
Hide file tree
Showing 44 changed files with 2,212 additions and 84 deletions.
27 changes: 24 additions & 3 deletions ckan/config/routing.py
Expand Up @@ -57,6 +57,7 @@ def make_map():
'resource',
'tag',
'group',
'organization',
'related',
'revision',
'licenses',
Expand Down Expand Up @@ -119,6 +120,7 @@ def make_map():
m.connect('/util/resource/format_icon',
action='format_icon', conditions=GET)
m.connect('/util/group/autocomplete', action='group_autocomplete')
m.connect('/util/organization/autocomplete', action='organization_autocomplete')
m.connect('/util/markdown', action='markdown')
m.connect('/util/dataset/munge_name', action='munge_package_name')
m.connect('/util/dataset/munge_title_to_name',
Expand Down Expand Up @@ -218,9 +220,8 @@ def make_map():
map.redirect('/groups', '/group')
map.redirect('/groups/{url:.*}', '/group/{url}')

##to get back formalchemy uncomment these lines
##map.connect('/group/new', controller='group_formalchemy', action='new')
##map.connect('/group/edit/{id}', controller='group_formalchemy', action='edit')
map.redirect('/organizations', '/organization')
map.redirect('/organizations/{url:.*}', '/organization/{url}')

# These named routes are used for custom group forms which will use the
# names below based on the group.type ('group' is the default type)
Expand All @@ -238,6 +239,26 @@ def make_map():
)
m.connect('group_read', '/group/{id}', action='read')

# These are the routes for organizations
with SubMapper(map, controller='organization') as m:
m.connect('organization_index', '/organization', action='index')
m.connect('organization_list', '/organization/list', action='list')
m.connect('organization_new', '/organization/new', action='new')
m.connect('organization_users', '/organization/users/{id}',
action='users')
m.connect('organization_apply_named', '/organization/apply/{id}',
action='apply')
m.connect('organization_apply', '/organization/apply',
action='apply')
m.connect('organization_action', '/organization/{action}/{id}',
requirements=dict(action='|'.join([
'edit',
'history'
]))
)
m.connect('organization_read', '/organization/{id}', action='read')


register_package_plugins(map)
register_group_plugins(map)

Expand Down
23 changes: 23 additions & 0 deletions ckan/controllers/api.py
Expand Up @@ -638,6 +638,29 @@ def convert_to_dict(user):
out = map(convert_to_dict, query.all())
return out

@jsonp.jsonpify
def organization_autocomplete(self):
q = request.params.get('q', '')
limit = request.params.get('limit', 20)
try:
limit = int(limit)
except:
limit = 20
limit = min(50, limit)

query = model.Group.search_by_name_or_title(q, 'organization')

def convert_to_dict(user):
out = {}
for k in ['id', 'name', 'title']:
out[k] = getattr(user, k)
return out

query = query.limit(limit)
out = map(convert_to_dict, query.all())
return out


def is_slug_valid(self):
slug = request.params.get('slug') or ''
slugtype = request.params.get('type') or ''
Expand Down

0 comments on commit e824827

Please sign in to comment.