Skip to content
Snippets Groups Projects
Commit 175fa7ed authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Reformat

parent 92db09d3
No related branches found
No related tags found
1 merge request!318Resolve "Add helper function to filter a queryset by a rule"
Pipeline #2903 failed
......@@ -354,7 +354,9 @@ def handle_uploaded_file(f, filename: str):
@cache_memoize(3600)
def queryset_rules_filter(obj: Union[HttpRequest, Model], queryset: QuerySet, perm: str) -> QuerySet:
def queryset_rules_filter(
obj: Union[HttpRequest, Model], queryset: QuerySet, perm: str
) -> QuerySet:
"""Filter queryset by user and permission."""
wanted_objects = set()
......@@ -365,4 +367,4 @@ def queryset_rules_filter(obj: Union[HttpRequest, Model], queryset: QuerySet, pe
if obj.has_perm(perm, item):
wanted_objects.add(item.pk)
return queryset.filter(pk__in = wanted_objects)
return queryset.filter(pk__in=wanted_objects)
......@@ -63,7 +63,10 @@ def has_any_object(perm: str, klass):
@predicate(name)
def fn(user: User) -> bool:
return get_objects_for_user(user, perm, klass).exists() or queryset_rules_filter(user, klass.objects.all(), perm).exists()
return (
get_objects_for_user(user, perm, klass).exists()
or queryset_rules_filter(user, klass.objects.all(), perm).exists()
)
return fn
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment