def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if settings.USE_JSONFIELD: from actstream.jsonfield import DataField, register_app DataField(blank=True, null=True).contribute_to_class(action_class, 'data') register_app(self)
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if settings.USE_JSONFIELD: from actstream.jsonfield import DataField, register_app DataField(blank=True, null=True).contribute_to_class( action_class, 'data' ) register_app(self)
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if settings.USE_JSONFIELD: try: from jsonfield.fields import JSONField except ImportError: raise ImproperlyConfigured('You must have django-jsonfield installed ' 'if you wish to use a JSONField on your actions') JSONField(blank=True, null=True).contribute_to_class(action_class, 'data')
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if settings.USE_JSONFIELD: try: from jsonfield.fields import JSONField except ImportError: raise ImproperlyConfigured( 'You must have django-jsonfield installed ' 'if you wish to use a JSONField on your actions') JSONField(blank=True, null=True).contribute_to_class(action_class, 'data')
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if settings.USE_JSONFIELD: try: from django_mysql.models import JSONField from jsonfield_compat import register_app except ImportError: raise ImproperlyConfigured( 'You must have django-jsonfield and django-jsonfield-compat ' 'installed if you wish to use a JSONField on your actions') JSONField( blank=True, null=True, encoder=CustomEncoder(allow_nan=False)).contribute_to_class( action_class, 'data') register_app(self)
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models') action_class = self.get_model('action') if actstream_settings.USE_JSONFIELD: if not hasattr(action_class, 'data'): from actstream.jsonfield import DataField DataField(blank=True, null=True).contribute_to_class( action_class, 'data' ) # dynamically load django_jsonfield_backport to INSTALLED_APPS if django.VERSION < (3, 1) and 'django_jsonfield_backport' not in settings.INSTALLED_APPS: settings.INSTALLED_APPS += ('django_jsonfield_backport', ) # reset loaded apps apps.app_configs = OrderedDict() # reset initialization status apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False apps.clear_cache() # re-initialize all apps apps.populate(settings.INSTALLED_APPS)
action_object_stream = Action.objects.action_object target_stream = Action.objects.target user_stream = Action.objects.user model_stream = Action.objects.model_actions def setup_generic_relations(): """ Set up GenericRelations for actionable models. """ for model in actstream_settings.MODELS.values(): if not model: continue for field in ('actor', 'target', 'action_object'): generic.GenericRelation(Action, content_type_field='%s_content_type' % field, object_id_field='%s_object_id' % field, related_name='actions_with_%s_%s_as_%s' % ( model._meta.app_label, model._meta.module_name, field), ).contribute_to_class(model, '%s_actions' % field) # @@@ I'm not entirely sure why this works setattr(Action, 'actions_with_%s_%s_as_%s' % ( model._meta.app_label, model._meta.module_name, field), None) setup_generic_relations() # connect the signal action.connect(action_handler, dispatch_uid='actstream.models')
def ready(self): from .actions import my_action_handler from actstream.signals import action action.connect(my_action_handler, dispatch_uid='notifications.models.Action')
if isinstance(getattr(model, attr, None), generic.ReverseGenericRelatedObjectsDescriptor): break generic.GenericRelation( Action, content_type_field='%s_content_type' % field, object_id_field='%s_object_id' % field, related_name='actions_with_%s_%s_as_%s' % (model._meta.app_label, model._meta.module_name, field), ).contribute_to_class(model, attr) # @@@ I'm not entirely sure why this works setattr( Action, 'actions_with_%s_%s_as_%s' % (model._meta.app_label, model._meta.module_name, field), None) setup_generic_relations() if actstream_settings.USE_JSONFIELD: try: from jsonfield.fields import JSONField except ImportError: raise ImproperlyConfigured( 'You must have django-jsonfield installed ' 'if you wish to use a JSONField on your actions') JSONField(blank=True, null=True).contribute_to_class(Action, 'data') # connect the signal action.connect(action_handler, dispatch_uid='actstream.models')
def ready(self): from actstream.actions import action_handler action.connect(action_handler, dispatch_uid='actstream.models')
content_type = ContentType.objects.get_for_model(actor)).delete() def actor_stream(actor): return Action.objects.stream_for_actor(actor) actor_stream.__doc__ = Action.objects.stream_for_actor.__doc__ def user_stream(user): return Follow.objects.stream_for_user(user) user_stream.__doc__ = Follow.objects.stream_for_user.__doc__ def model_stream(model): return Action.objects.stream_for_model(model) model_stream.__doc__ = Action.objects.stream_for_model.__doc__ def action_handler(verb, target=None, **kwargs): actor = kwargs.pop('sender') kwargs.pop('signal', None) kw = { 'actor_content_type': ContentType.objects.get_for_model(actor), 'actor_object_id': actor.pk, 'verb': verb } if target: kw.update(target_object_id=target.pk, target_content_type=ContentType.objects.get_for_model(target)) kw.update(kwargs) Action.objects.get_or_create(**kw)[0] action.connect(action_handler)
""" return timesince_(self.timestamp, now) def on_action_sent(verb, **kwargs): """ Handler function to create Action instance upon action signal call. """ kwargs.pop('signal', None) actor = kwargs.pop('sender') actor_ct = ContentType.objects.get_for_model(actor) newaction = Action(actor_content_type=actor_ct, actor_object_id=actor.pk, verb=unicode(verb), public=bool(kwargs.pop('public', True)), timestamp=kwargs.pop('timestamp', now()), extra_data=kwargs.pop('extra_data', '')) for opt in ('target', 'action_object'): obj = kwargs.pop(opt, None) if not obj is None: setattr(newaction, '%s_object_id' % opt, obj.pk) setattr(newaction, '%s_content_type' % opt, ContentType.objects.get_for_model(obj)) newaction.save() action.connect(on_action_sent, sender=None, dispatch_uid='actstream.models')