entity_event/models.py
def events_targets(self, entity_kind=None, **event_filters):
        """Return all events for this medium, with who each event is for.

        This method is useful for individually notifying every
        entity concerned with a collection of events, while
        still respecting subscriptions and usubscriptions. For
        example, ``events_targets`` can be used to send email
        notifications, by retrieving all unseen events (and marking
        them as now having been seen), and then processing the
        emails. In code, this could look like:

        .. code-block:: python

            email = Medium.objects.get(name='email')
            new_emails = email.events_targets(seen=False, mark_seen=True)

            for event, targets in new_emails:
                django.core.mail.send_mail(
                    subject = event.context["subject"]
                    message = event.context["message"]
                    recipient_list = [t.entity_meta["email"] for t in targets]
                )

        This ``events_targets`` method attempts to make bulk
        processing of push-style notifications straightforward. This
        sort of processing should normally occur in a separate thread
        from any request/response cycle.

        Filtering based on the properties of the events themselves is
        supported, through the rest of the following arguments, which
        are optional.

        :type entity_kind: EntityKind
        :param entity_kind: Only include targets of the given kind in
            each targets list.

        :type start_time: datetime.datetime (optional)
        :param start_time: Only return events that occurred after the
            given time. If no time is given for this argument, no
            filtering is done.

        :type end_time: datetime.datetime (optional)
        :param end_time: Only return events that occurred before the
            given time. If no time is given for this argument, no
            filtering is done

        :type seen: Boolean (optional)
        :param seen: This flag controls whether events that have
            marked as seen are included. By default, both events that
            have and have not been marked as seen are included. If
            ``True`` is given for this parameter, only events that
            have been marked as seen will be included. If ``False`` is
            given, only events that have not been marked as seen will
            be included.

        :type include_expired: Boolean (optional)
        :param include_expired: By default, events that have a
            expiration time, which has passed, are not included in the
            results. Passing in ``True`` to this argument causes
            expired events to be returned as well.

        :type actor: Entity (optional)
        :param actor: Only include events with the given entity as an
            actor.

        :type mark_seen: Boolean (optional)
        :param mark_seen: Create a side effect in the database that
            marks all the returned events as having been seen by this
            medium.

        :rtype: List of tuples
        :returns: A list of tuples in the form ``(event, targets)``
            where ``targets`` is a list of entities.
        """
        events = self.get_filtered_events(**event_filters)
        subscriptions = Subscription.objects.filter(medium=self)

        event_pairs = []
        for event in events:
            targets = []
            for sub in subscriptions:
                if event.source != sub.source:
                    continue

                subscribed = sub.subscribed_entities()
                if sub.only_following:
                    potential_targets = self.followers_of(
                        event.eventactor_set.values_list('entity__id', flat=True)
                    )
                    subscription_targets = list(Entity.objects.filter(
                        Q(id__in=subscribed), Q(id__in=potential_targets)))
                else:
                    subscription_targets = list(subscribed)

                targets.extend(subscription_targets)

            targets = self.filter_source_targets_by_unsubscription(event.source_id, targets)

            if entity_kind:
                targets = [t for t in targets if t.entity_kind == entity_kind]
            if targets:
                event_pairs.append((event, targets))

        return event_pairs
Return all events for this medium, with who each event is for.

        This method is useful for individually notifying every
        entity concerned with a collection of events, while
        still respecting subscriptions and usubscriptions. For
        example, ``events_targets`` can be used to send email
        notifications, by retrieving all unseen events (and marking
        them as now having been seen), and then processing the
        emails. In code, this could look like:

        .. code-block:: python

            email = Medium.objects.get(name='email')
            new_emails = email.events_targets(seen=False, mark_seen=True)

            for event, targets in new_emails:
                django.core.mail.send_mail(
                    subject = event.context["subject"]
                    message = event.context["message"]
                    recipient_list = [t.entity_meta["email"] for t in targets]
                )

        This ``events_targets`` method attempts to make bulk
        processing of push-style notifications straightforward. This
        sort of processing should normally occur in a separate thread
        from any request/response cycle.

        Filtering based on the properties of the events themselves is
        supported, through the rest of the following arguments, which
        are optional.

        :type entity_kind: EntityKind
        :param entity_kind: Only include targets of the given kind in
            each targets list.

        :type start_time: datetime.datetime (optional)
        :param start_time: Only return events that occurred after the
            given time. If no time is given for this argument, no
            filtering is done.

        :type end_time: datetime.datetime (optional)
        :param end_time: Only return events that occurred before the
            given time. If no time is given for this argument, no
            filtering is done

        :type seen: Boolean (optional)
        :param seen: This flag controls whether events that have
            marked as seen are included. By default, both events that
            have and have not been marked as seen are included. If
            ``True`` is given for this parameter, only events that
            have been marked as seen will be included. If ``False`` is
            given, only events that have not been marked as seen will
            be included.

        :type include_expired: Boolean (optional)
        :param include_expired: By default, events that have a
            expiration time, which has passed, are not included in the
            results. Passing in ``True`` to this argument causes
            expired events to be returned as well.

        :type actor: Entity (optional)
        :param actor: Only include events with the given entity as an
            actor.

        :type mark_seen: Boolean (optional)
        :param mark_seen: Create a side effect in the database that
            marks all the returned events as having been seen by this
            medium.

        :rtype: List of tuples
        :returns: A list of tuples in the form ``(event, targets)``
            where ``targets`` is a list of entities.
        
Return all events for this medium, with who each event is for.
This method is useful for individually notifying every
entity concerned with a collection of events, while
still respecting subscriptions and usubscriptions. For
example, ``events_targets`` can be used to send email
notifications, by retrieving all unseen events (and marking
them as now having been seen), and then processing the
emails. In code, this could look like.

code-block:: python





This ``events_targets`` method attempts to make bulk
processing of push-style notifications straightforward. This
sort of processing should normally occur in a separate thread
from any request/response cycle.

Filtering based on the properties of the events themselves is
supported, through the rest of the following arguments, which
are optional.
Return all events for this medium with who each event is for . This method is useful for individually notifying every entity concerned with a collection of events while still respecting subscriptions and usubscriptions . For example ` ` events_targets ` ` can be used to send email notifications by retrieving all unseen events ( and marking them as now having been seen ) and then processing the emails . In code this could look like . code - block :: python This ` ` events_targets ` ` method attempts to make bulk processing of push - style notifications straightforward . This sort of processing should normally occur in a separate thread from any request / response cycle . Filtering based on the properties of the events themselves is supported through the rest of the following arguments which are optional .
def events_targets(self, entity_kind=None, **event_filters):
        events = self.get_filtered_events(**event_filters)
        subscriptions = Subscription.objects.filter(medium=self)
        event_pairs = []
        for event in events:
            targets = []
            for sub in subscriptions:
                if event.source != sub.source:
                    continue
                subscribed = sub.subscribed_entities()
                if sub.only_following:
                    potential_targets = self.followers_of(
                        event.eventactor_set.values_list('entity__id', flat=True)
                    )
                    subscription_targets = list(Entity.objects.filter(
                        Q(id__in=subscribed), Q(id__in=potential_targets)))
                else:
                    subscription_targets = list(subscribed)
                targets.extend(subscription_targets)
            targets = self.filter_source_targets_by_unsubscription(event.source_id, targets)
            if entity_kind:
                targets = [t for t in targets if t.entity_kind == entity_kind]
            if targets:
                event_pairs.append((event, targets))
        return event_pairs
def events_targets ( self , entity_kind = None , ** event_filters ) : events = self . get_filtered_events ( ** event_filters ) subscriptions = Subscription . objects . filter ( medium = self ) event_pairs = [ ] for event in events : targets = [ ] for sub in subscriptions : if event . source != sub . source : continue subscribed = sub . subscribed_entities ( ) if sub . only_following : potential_targets = self . followers_of ( event . eventactor_set . values_list ( 'entity__id' , flat = True ) ) subscription_targets = list ( Entity . objects . filter ( Q ( id__in = subscribed ) , Q ( id__in = potential_targets ) ) ) else : subscription_targets = list ( subscribed ) targets . extend ( subscription_targets ) targets = self . filter_source_targets_by_unsubscription ( event . source_id , targets ) if entity_kind : targets = [ t for t in targets if t . entity_kind == entity_kind ] if targets : event_pairs . append ( ( event , targets ) ) return event_pairs
Return all events for this medium, with who each event is for.
Return all events for this medium with who each event is for .
"""Return all events for this medium, with who each event is for.

        This method is useful for individually notifying every
        entity concerned with a collection of events, while
        still respecting subscriptions and usubscriptions. For
        example, ``events_targets`` can be used to send email
        notifications, by retrieving all unseen events (and marking
        them as now having been seen), and then processing the
        emails. In code, this could look like:

        .. code-block:: python

            email = Medium.objects.get(name='email')
            new_emails = email.events_targets(seen=False, mark_seen=True)

            for event, targets in new_emails:
                django.core.mail.send_mail(
                    subject = event.context["subject"]
                    message = event.context["message"]
                    recipient_list = [t.entity_meta["email"] for t in targets]
                )

        This ``events_targets`` method attempts to make bulk
        processing of push-style notifications straightforward. This
        sort of processing should normally occur in a separate thread
        from any request/response cycle.

        Filtering based on the properties of the events themselves is
        supported, through the rest of the following arguments, which
        are optional.

        :type entity_kind: EntityKind
        :param entity_kind: Only include targets of the given kind in
            each targets list.

        :type start_time: datetime.datetime (optional)
        :param start_time: Only return events that occurred after the
            given time. If no time is given for this argument, no
            filtering is done.

        :type end_time: datetime.datetime (optional)
        :param end_time: Only return events that occurred before the
            given time. If no time is given for this argument, no
            filtering is done

        :type seen: Boolean (optional)
        :param seen: This flag controls whether events that have
            marked as seen are included. By default, both events that
            have and have not been marked as seen are included. If
            ``True`` is given for this parameter, only events that
            have been marked as seen will be included. If ``False`` is
            given, only events that have not been marked as seen will
            be included.

        :type include_expired: Boolean (optional)
        :param include_expired: By default, events that have a
            expiration time, which has passed, are not included in the
            results. Passing in ``True`` to this argument causes
            expired events to be returned as well.

        :type actor: Entity (optional)
        :param actor: Only include events with the given entity as an
            actor.

        :type mark_seen: Boolean (optional)
        :param mark_seen: Create a side effect in the database that
            marks all the returned events as having been seen by this
            medium.

        :rtype: List of tuples
        :returns: A list of tuples in the form ``(event, targets)``
            where ``targets`` is a list of entities.
        """
A list of tuples in the form ``(event, targets)``
where ``targets`` is a list of entities.
A list of tuples in the form ` ` ( event targets ) ` ` where ` ` targets ` ` is a list of entities .
List of tuples
self
entity_kind
Only include targets of the given kind in
each targets list.
Only include targets of the given kind in each targets list .
start_time
Only return events that occurred after the
given time. If no time is given for this argument, no
filtering is done.
Only return events that occurred after the given time . If no time is given for this argument no filtering is done .
end_time
Only return events that occurred before the
given time. If no time is given for this argument, no
filtering is done
Only return events that occurred before the given time . If no time is given for this argument no filtering is done
seen
This flag controls whether events that have
marked as seen are included. By default, both events that
have and have not been marked as seen are included. If
``True`` is given for this parameter, only events that
have been marked as seen will be included. If ``False`` is
given, only events that have not been marked as seen will
be included.
This flag controls whether events that have marked as seen are included . By default both events that have and have not been marked as seen are included . If ` ` True ` ` is given for this parameter only events that have been marked as seen will be included . If ` ` False ` ` is given only events that have not been marked as seen will be included .
include_expired
By default, events that have a
expiration time, which has passed, are not included in the
results. Passing in ``True`` to this argument causes
expired events to be returned as well.
By default events that have a expiration time which has passed are not included in the results . Passing in ` ` True ` ` to this argument causes expired events to be returned as well .
actor
Only include events with the given entity as an
actor.
Only include events with the given entity as an actor .
mark_seen
Create a side effect in the database that
marks all the returned events as having been seen by this
medium.
Create a side effect in the database that marks all the returned events as having been seen by this medium .