[BB-3963] Add marketing djangoapp
Created by: arjunsinghy96
Description
Adds a marketing
django app with EmailTemplate
, Subscriber
and SentEmail
models.
Adds settings MARKETING_EMAIL_SENDER
and MARKETING_DELETE_FOLLOWUP_EMAILS_AFTER_DAYS
Adds periodic tasks send_followup_emails
to dispatch all followup emails for the day and prune_emails
to delete all old emails (configurable using settings.MARKETING_DELETE_FOLLOWUP_EMAILS_AFTER_DAYS
)
Jira Tickets
Testing Instructions
Common
- Get the devstack running and checkout to this branch.
- Run migrations.
Checking admin and admin action
- Start the dev server and visit the admin panel at http://localhost:5000/admin/marketing/
- Verify that each of the three models
EmailTemplate
,SentEmail
andSubscriber
are registered. - Create a new inactive
EmailTemplate
object. - Verify that
send_sample_emails
action is available inEmailTemplate
admin. - Select the Template created above and trigger the
send_sample_emails
action. - Check dev server logs and verfiy that the email was sent.
Testing tasks
- Set
MARKETING_DELETE_FOLLOWUP_EMAILS_AFTER_DAYS
to0
. (This will be required when testingprune_emails
) - Restart the dev server.
- Create a
Subscriber
object and settrial_started_at
to a appropriate value such thattrial_started_at + EmailTemplate.send_after_days
is equal to now. One example will be to setsend_after_days
to1
andtrial_started_at
to yesterday's date with time less than current time - With dev server still running open a shell using
make shell
in another terminal. - Run following code
from marketing.tasks import send_followup_emails
send_followup_emails()
- In dev server logs verify that the email was sent to subscriber.
- Trigger the task again (using
send_followup_email
) and verfiy that this time no email is sent. - Verify that the
SentEmail
model have the recently sent email (Check in django admin) - Verfiy that the saved emails in
SentEmail
are not editable from admin panel. - Now run the following code in shell to verfiy the
prune_email
task
from marketing.tasks import prune_emails
prune_emails()
- Verify that the
SentEmail
models has no elements. (Django admin can be used.)
Template variables
Following variables are provided in template context:
-
full_name
: String -
username
: String -
instance_name
: String -
subdomain
: String -
application
: Instance ofBetaTestApplication
Try out these variables using django's {{ variable }}
template syntax.