Giter Club home page Giter Club logo

django-df-notifications's People

Contributors

ayushin avatar dependabot[bot] avatar eugapx avatar eugen1j avatar rishabh27shah avatar yevhenii-apex avatar

Stargazers

 avatar

Watchers

 avatar  avatar

django-df-notifications's Issues

create a CustomPushMessage model

CustomPushNotification
title
body
image
audience = many2many to users all if none
created, modified, sent

and a send action in the admin

Create a channel throttling system with back-off and aggregation

I am thinking about limiting notification rate per channel with throttling class similar to DRF.

Imagine the system generates 1000 push notifications for a user.

We want to send the first notification immediately, then start exponentially backing them off (either using django cache or database backend) and then send them a minute later, then 5 minutes later and so on.

Some channels and project specific notifications can be aggregated. Imagine social network, when you receive 1 like, then 150 in the next 5 minutes, you would not want to get 150 notifications but rather just two, second one saying you have received 150 likes (or some other logic like user a, user b and 148 other users have liked your story).

new migrations are created after installing fresh package

Migrations for 'df_notifications':
  venv/lib/python3.9/site-packages/df_notifications/migrations/0002_alter_notificationtemplate_id_alter_userdevice_user.py
    - Alter field id on notificationtemplate
    - Alter field user on userdevice

Missing migrations after install

Running migrations:
  No migrations to apply.
  Your models in app(s): 'df_notifications' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
django@django-web-5c84cd796-vnb7b:/app$ ./manage.py makemigrations
Migrations for 'df_notifications':
  /usr/local/lib/python3.9/site-packages/df_notifications/migrations/0002_alter_notificationhistory_id_alter_userdevice_user.py
    - Alter field id on notificationhistory
    - Alter field user on userdevice
Traceback (most recent call last):
  File "/app/./manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 90, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 190, in handle
    self.write_migration_files(changes)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py", line 228, in write_migration_files
    with open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/df_notifications/migrations/0002_alter_notificationhistory_id_alter_userdevice_user.py'
Sentry is attempting to send 2 pending error messages
Waiting up to 2 seconds

Create generic NotificationTemplate

The idea is to move away from notifications models scattered across different apps and replace/rename AbstractNotification that now is being inherited by applications specific models with NotificationTemplate and extend it with slug field, so other apps can use it like follows:

from df_notifications.signals import register_signal ? register_model? register_notification

@register_notification(signal=pre_save, model=User, slug='user_created'):
def user_created_notification(prev: instance, next: instance, model: models.Model, template: NotificationTemplate):
  context = {
     'prev': prev,
     'instance': next,
  }
   if condition:
      template.send_all(users=[next.user], context=context)
 

New design on NotificationTemplate

In the current design, we handle all notification channels via NotificationTemplate class.

It's bad because different channels require different fields: email needs a subject, body, body_html; push needs a subject, body, data.

Also, we handle sending notifications to the different channels in one place.

We need to develop a design, that allows us to write separate handlers (classes I think) for different notification channels.

Something like this, but you can propose your own solution for these problems:

class BaseNotificationChannel:
   parts = []
 
   def render_parts(...):
       return {p: ... for p in self.parts}

 
class EmailNotificationChannel(BaseNotificationChannel):
   parts = ['subject', 'body', 'body_html']
   

   def send(...):
       parts = self.render_parts(...)
       send_email(...)

To store template parts in the DB, we can use https://github.com/jazzband/django-dbtemplates. Also, we need to lookup up the templates in the template folder if we find none in the DB.

NotificationTemplate instances will store links or paths to these parts in this case.

Integrate django-df-model-actions

The goal is to use django-df-model-actions package instead of using BaseModelRule class from the library.

When we will have asynchronous actions djangoflow/django-df-model-actions#4.

So, we need to make sure that we can use two libs together.

You need to write some tests to prove it (and test manually), make changes if needed, and describe in readme how to use them (maybe using test app as an example).

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.