jazzband / django-newsletter

An email newsletter application for the Django web application framework, including an extended admin interface, web (un)subscription, dynamic e-mail templates, an archive and HTML email support.
GNU Affero General Public License v3.0
846 stars 204 forks source link

Dynamic subscription #367

Open newearthmartin opened 3 years ago

newearthmartin commented 3 years ago

The goal of this PR is to be able to dynamically generate a list of subscriptions at the moment of submitting the Submission. It is following on this idea https://github.com/jazzband/django-newsletter/issues/359.

The Newsletter class has a new field subscription_generator_class. If this field is empty, it will continue behaving as usual. However, if the field is not empty, It is a class name that will be instantiated into a subscription generator object. The subscription generator will be in charge of generating the list of subscriptions at the moment of sending the message.

This is done by implementing the generate_subscriptions(submission) method. This method must return a list of Subscription objects to be used for sending the message. These dynamic Submission objects must be in-memory objects and should not be saved to the DB.

Existing Subscription objects in the DB for this Newsletter/Submission will still be used. At the time of submission, dynamically generated Subscriptions will be added to DB Subscription objects. Also, unsubscribed DB Subscriptions will be removed from the dynamically generated Subscriptions.

codecov[bot] commented 3 years ago

Welcome to Codecov :tada:

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered :open_umbrella:

newearthmartin commented 2 years ago

@dokterbob curious if you have any opinions about this PR

aclark4life commented 2 months ago

@newearthmartin Nice to see someone still working on this!

newearthmartin commented 2 months ago

I just added a modification in the original proposed behavior. Now, existing DB Subscription objects will be joined with dynamically generated ones. This is especially useful to keep track of user unsubscribes.

newearthmartin commented 2 months ago

Thanks @aclark4life ! Would be great to get some feedback here or at the original discussion https://github.com/jazzband/django-newsletter/issues/359