summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 6150ab0aa..e4a72eab7 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -235,7 +235,7 @@ class OwnPerms:
return cls.objects.filter(query).count()
@classmethod
- def get_owns(cls, user):
+ def get_owns(cls, user, replace_query={}):
"""
Get Own items
"""
@@ -247,10 +247,12 @@ class OwnPerms:
if hasattr(cls, 'BASKET_MODEL'):
items = list(cls.BASKET_MODEL.objects.filter(user=user).all())
query = cls.get_query_owns(user)
- if not query:
+ if not query and not replace_query:
return cls.objects.filter(pk__isnull=True)
- items += list(
- cls.objects.filter(query).order_by(*cls._meta.ordering).all())
+ q = cls.objects.filter(query)
+ if replace_query:
+ q = cls.objects.filter(**replace_query)
+ items += list(q.order_by(*cls._meta.ordering).all())
return items
@@ -2412,10 +2414,10 @@ class Person(Address, Merge, OwnPerms, ValueGetter):
bool(self.person_types.filter(
groups__permissions__codename=right_name).count()) or \
bool(self.ishtaruser.filter(
- groups__permissions__codename__in=right_name
+ groups__permissions__codename__in=[right_name]
).count()) or\
bool(self.ishtaruser.filter(
- user_permissions__codename__in=right_name).count())
+ user_permissions__codename__in=[right_name]).count())
# or self.person_types.filter(wizard__url_name=right_name).count())
if session:
cache.set(cache_key, res, settings.CACHE_SMALLTIMEOUT)
@@ -2512,8 +2514,9 @@ class IshtarUser(User):
def has_perm(self, perm, model=None, session=None, obj=None):
if not session:
return super(IshtarUser, self).has_perm(perm, model)
- cache_key = 'usersession-{}-{}'.format(session.session_key, perm,
- model or 'no')
+ cache_key = 'usersession-{}-{}-{}-{}'.format(
+ session.session_key, perm, model.__name__ if model else 'no',
+ obj.pk if obj else 'no')
res = cache.get(cache_key)
if res in (True, False):
return res