From fda9b049b90abeba3afff926c7795c8f690ce0c9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste <bleme@pm.me> Date: Wed, 21 Oct 2020 13:56:06 +0200 Subject: [PATCH] syntax: clean up --- djangoldp/permissions.py | 15 +++++++++------ djangoldp/tests/tests_perf_get.py | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/djangoldp/permissions.py b/djangoldp/permissions.py index bfbd3e94..1c3046cf 100644 --- a/djangoldp/permissions.py +++ b/djangoldp/permissions.py @@ -38,18 +38,15 @@ class LDPPermissions(DjangoObjectPermissions): Filter user permissions for a model class """ - # this may be a permission for the model class, or an instance self.refresh_cache() + # this may be a permission for the model class, or an instance if isinstance(obj_or_model, ModelBase): model = obj_or_model else: obj = obj_or_model model = obj_or_model.__class__ - model_name = model._meta.model_name - user_key = 'None' if user is None else user.id - obj_key = 'None' if obj is None else obj.id - perms_cache_key = 'User{}{}{}'.format(user_key, model_name, obj_key) + perms_cache_key = self.cache_key(model, obj, user) if self.with_cache and perms_cache_key in self.perms_cache: return self.perms_cache[perms_cache_key] @@ -95,7 +92,13 @@ class LDPPermissions(DjangoObjectPermissions): self.perms_cache[perms_cache_key] = list(perms) return self.perms_cache[perms_cache_key] - # return list(perms) + + def cache_key(self, model, obj, user): + model_name = model._meta.model_name + user_key = 'None' if user is None else user.id + obj_key = 'None' if obj is None else obj.id + perms_cache_key = 'User{}{}{}'.format(user_key, model_name, obj_key) + return perms_cache_key def filter_user_perms(self, context, obj_or_model, permissions): # Only used on Model.get_permissions to translate permissions to LDP diff --git a/djangoldp/tests/tests_perf_get.py b/djangoldp/tests/tests_perf_get.py index 4b1ca1ed..1120e1cc 100644 --- a/djangoldp/tests/tests_perf_get.py +++ b/djangoldp/tests/tests_perf_get.py @@ -18,6 +18,7 @@ class TestPerformanceGET(APITestCase): result_line = [] withAuth = True withPermsCache = True + # fixtures = ['test_ten_1000.json',] @classmethod def setUpClass(cls): -- GitLab