django-newsletter
django-newsletter copied to clipboard
Dynamic subscription
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 Report
Merging #367 (5c1d961) into master (c350966) will increase coverage by
0.04%. The diff coverage is89.28%.
@@ Coverage Diff @@
## master #367 +/- ##
==========================================
+ Coverage 86.02% 86.06% +0.04%
==========================================
Files 16 16
Lines 1302 1328 +26
Branches 137 140 +3
==========================================
+ Hits 1120 1143 +23
- Misses 135 137 +2
- Partials 47 48 +1
| Impacted Files | Coverage Δ | |
|---|---|---|
| newsletter/admin.py | 81.74% <33.33%> (-0.63%) |
:arrow_down: |
| newsletter/models.py | 91.96% <96.00%> (+0.29%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update c350966...5c1d961. Read the comment docs.
@dokterbob curious if you have any opinions about this PR