diff --git a/cookbook/models.py b/cookbook/models.py index 3f198e640..c4816ed6f 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -1,3 +1,4 @@ +import operator import re import uuid from datetime import date, timedelta @@ -53,9 +54,11 @@ class PermissionModelMixin: def get_space(self): p = '.'.join(self.get_space_key()) - if getattr(self, p, None): - return getattr(self, p) - raise NotImplementedError('get space for method not implemented and standard fields not available') + try: + if space := operator.attrgetter(p)(self): + return space + except AttributeError: + raise NotImplementedError('get space for method not implemented and standard fields not available') class Space(ExportModelOperationsMixin('space'), models.Model): diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index cd9a7018c..17ebea158 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -140,7 +140,7 @@ {% page_help request.resolver_match.url_name as help_button %} {% if help_button %}{{ help_button|safe }}{% endif %} -