forked from intelowlproject/IntelOwl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueryset.py
More file actions
38 lines (30 loc) · 1.08 KB
/
queryset.py
File metadata and controls
38 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from django.db.models import QuerySet
logger = logging.getLogger(__name__)
class AnalyzableQuerySet(QuerySet):
def visible_for_user(self, user):
from api_app.models import Job
from api_app.user_events_manager.models import UserAnalyzableEvent
analyzables_job = (
Job.objects.visible_for_user(user)
.values("analyzable")
.distinct()
.values_list("analyzable__pk", flat=True)
)
analyzables_ue = (
UserAnalyzableEvent.objects.visible_for_user(user)
.values("analyzable")
.distinct()
.values_list("analyzable__pk", flat=True)
)
return self.filter(pk__in=analyzables_job) | self.filter(pk__in=analyzables_ue)
def create(self, *args, **kwargs):
obj = self.model(**kwargs)
self._for_write = True
try:
obj.full_clean()
except Exception as e:
logger.error(f"Already exists obj {obj.md5}")
raise e
obj.save(force_insert=True, using=self.db)
return obj