Skip to content

Commit

Permalink
[#1607][validators] Added a group validator that checks for existence…
Browse files Browse the repository at this point in the history
… of a group by id or name
  • Loading branch information
Ian Murray authored and rossjones committed Mar 6, 2012
1 parent 6ef3618 commit 3c7c875
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ckan/logic/validators.py
Expand Up @@ -114,6 +114,16 @@ def group_id_exists(group_id, context):
raise Invalid('%s: %s' % (_('Not found'), _('Group')))
return group_id

def group_id_or_name_exists(reference, context):
"""
Raises Invalid if a group identified by the name or id cannot be found.
"""
model = context['model']
result = model.Group.get(reference)
if not result:
raise Invalid(_('That group name or ID does not exist.'))
return reference

def activity_type_exists(activity_type):
"""Raises Invalid if there is no registered activity renderer for the
given activity_type. Otherwise returns the given activity_type.
Expand Down

0 comments on commit 3c7c875

Please sign in to comment.