Skip to content

Commit

Permalink
Slight refactor of logic/auth/__init__.py for more pythonic plus stor…
Browse files Browse the repository at this point in the history
…e found object
  • Loading branch information
tobes committed Apr 15, 2013
1 parent cdf7926 commit ba5063c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ckan/logic/auth/__init__.py
Expand Up @@ -8,18 +8,19 @@
def _get_object(context, data_dict, name, class_name):
# return the named item if in the data_dict, or get it from
# model.class_name
if not data_dict:
data_dict = {}

if not name in context:
try:
return context[name]
except KeyError:
model = context['model']
if not data_dict:
data_dict = {}
id = data_dict.get('id', None)
obj = getattr(model, class_name).get(id)
if not obj:
raise logic.NotFound
else:
obj = context[name]
return obj
# Save in case we need this again during the request
context[name] = obj
return obj


def get_related_object(context, data_dict=None):
Expand Down

0 comments on commit ba5063c

Please sign in to comment.