Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from datetime import datetime
3from actstream.managers import ActionManager, stream
4from actstream.registry import check
5from django.apps import apps
6from django.contrib.contenttypes.models import ContentType
7from django.db.models import Q
10class DiscussDataActionManager(ActionManager):
11 @stream
12 def mystream(self, obj, verb="posted", time=None):
13 if time is None:
14 time = datetime.now()
15 return obj.actor_actions.filter(verb=verb, timestamp__lte=time)
17 @stream
18 def dataset_access_requests_sent(self, sender, recipient=None):
19 notification_content_type = ContentType.objects.get(
20 app_label="ddcomments", model="notification"
21 )
22 dataset_content_type = ContentType.objects.get(
23 app_label="dddatasets", model="dataset"
24 )
25 filters = {"action_object_content_type": notification_content_type.id}
26 filters["target_content_type"] = dataset_content_type.id
27 if recipient: # optional recipient
28 filters["target"] = recipient
29 # Actions where sender is the actor with extra filters applied
30 return sender.actor_actions.filter(**filters)
32 @stream
33 def datasets_actions(self, datasets):
35 ctype = ContentType.objects.get(app_label="dddatasets", model="dataset")
36 return self.filter(
37 action_object_content_type=ctype, action_object_object_id__in=datasets,
38 )
40 @stream
41 def access_requests_received(self, datasets):
42 notification_content_type = ContentType.objects.get(
43 app_label="ddcomments", model="notification"
44 )
45 dataset_content_type = ContentType.objects.get(
46 app_label="dddatasets", model="dataset"
47 )
49 return self.filter(
50 action_object_content_type=notification_content_type.id,
51 target_content_type=dataset_content_type.id,
52 target_object_id__in=datasets,
53 )
55 def everything(self, *args, **kwargs):
56 """
57 Return all actions (public=True and False)
58 """
59 return self.filter(*args, **kwargs)
61 @stream
62 def any_everything(self, obj, **kwargs):
63 """
64 Stream of most recent actions where obj is the actor OR target OR action_object.
65 Includes also Actions which are not public
66 """
67 check(obj)
68 ctype = ContentType.objects.get_for_model(obj)
69 return self.everything(
70 Q(actor_content_type=ctype, actor_object_id=obj.pk,)
71 | Q(target_content_type=ctype, target_object_id=obj.pk,)
72 | Q(action_object_content_type=ctype, action_object_object_id=obj.pk,),
73 **kwargs,
74 )