Code Monkey home page Code Monkey logo

Comments (3)

tbarbugli avatar tbarbugli commented on May 25, 2024

unfortunately Django does not expose transactions callbacks (only 1.9 does it) so it is fairly hard for the integration library to detect rollbacks / execute only after the transaction is commited out of the box. One way to do this is to disable the default behavior and manually perform activity inserts/deletes in your own app. Feel free to add some code from your app o add more description of your use case.

from stream-django.

isaac-peka avatar isaac-peka commented on May 25, 2024

Not sure manually inserting/deleting is really the best way to go since it adds a lot of complication and editing code gets a lot more involved.

Actually, what you mentioned about the transaction callbacks being exposed in 1.9 helped me stumble across a library that provides transaction commit callbacks for Django 1.6+, so thanks for that :) https://django-transaction-hooks.readthedocs.org/en/latest/.

from stream-django.

isaac-peka avatar isaac-peka commented on May 25, 2024

Here's one example of what I mean (in regards to cleaning up). I've set up a manual signal handler that creates notifications only. Something like this:

@receiver(post_save, sender=ConversationMessage)
def send_message_notification(instance, created, **kwargs):
    if created:
        recipients = instance.conversation.users.exclude(pk=instance.author_id)
        feeds = ["notification:%d" % u.id for u in recipients]
        stream_client.add_to_many({
            'actor': create_reference(instance.author),
            'verb': 'message',
            'object': create_reference(instance.conversation),
            'message': create_reference(instance),
            'time': instance.created_at,
            'foreign_id': create_reference(instance),
        }, feeds)

How would I write the other side of this handler, i.e. the post_delete signal? Because the notifications are not bound to a source feed.

from stream-django.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.