From ba5063c17956b721c0ab209dc5fa9dcd4e7414d4 Mon Sep 17 00:00:00 2001 From: tobes Date: Sat, 13 Apr 2013 12:40:02 +0100 Subject: [PATCH] Slight refactor of logic/auth/__init__.py for more pythonic plus store found object --- ckan/logic/auth/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ckan/logic/auth/__init__.py b/ckan/logic/auth/__init__.py index 500be7fef3f..9ed00ec07ad 100644 --- a/ckan/logic/auth/__init__.py +++ b/ckan/logic/auth/__init__.py @@ -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):