automatic expiry of non-recurring users
This commit is contained in:
@@ -59,8 +59,12 @@ def send_template_email(from_email,to_email,subject,
|
||||
|
||||
html_content = htmly.render(context)
|
||||
text_content = textify(html_content)
|
||||
|
||||
if 'cc' in kwargs:
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'])
|
||||
else:
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
|
||||
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
|
||||
if 'attach_file' in kwargs:
|
||||
@@ -82,6 +86,8 @@ def send_template_email(from_email,to_email,subject,
|
||||
else:
|
||||
emailbounced = False
|
||||
|
||||
|
||||
|
||||
if not emailbounced:
|
||||
res = msg.send()
|
||||
else:
|
||||
|
||||
@@ -5,8 +5,9 @@ import datetime
|
||||
from utils import myqueue
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default')
|
||||
from rowers.tasks import handle_updatefitnessmetric
|
||||
from rowers.tasks import handle_updatefitnessmetric,handle_sendemail_expired
|
||||
from rowers.mytypes import otwtypes
|
||||
from django.contrib import messages
|
||||
|
||||
def getrower(user):
|
||||
try:
|
||||
@@ -101,3 +102,24 @@ class GDPRMiddleWare(object):
|
||||
return redirect(
|
||||
'/rowers/me/gdpr-optin/?next=%s' % nexturl
|
||||
)
|
||||
|
||||
class RowerPlanMiddleWare(object):
|
||||
def process_request(self, request):
|
||||
if request.user.is_authenticated() and request.user.rower.rowerplan != 'basic':
|
||||
if request.user.rower.paymenttype == 'single':
|
||||
if request.user.rower.planexpires < timezone.now().date():
|
||||
messg = 'Your paid plan has expired. We have reset you to a free basic plan.'
|
||||
messages.error(request,messg)
|
||||
r = getrower(request.user)
|
||||
r.rowerplan = 'basic'
|
||||
r.save()
|
||||
# send email
|
||||
job = myqueue(queue,
|
||||
handle_sendemail_expired,
|
||||
r.user.email,
|
||||
r.user.first_name,
|
||||
r.user.last_name,
|
||||
str(r.planexpires))
|
||||
elif request.user.rower.planexpires-datetime.timedelta(days=5)<timezone.now().date():
|
||||
messg = 'Your paid plan will expire soon. Your account will be reset to basic on %d' % request.user.rower.planexpires
|
||||
messages.info(request,messg)
|
||||
|
||||
@@ -702,6 +702,13 @@ class Rower(models.Model):
|
||||
|
||||
rowerplan = models.CharField(default='basic',max_length=30,
|
||||
choices=plans)
|
||||
paymenttype = models.CharField(
|
||||
default='single',max_length=30,
|
||||
choices=(
|
||||
('single','single'),
|
||||
('recurring','recurring')
|
||||
)
|
||||
)
|
||||
|
||||
planexpires = models.DateField(default=timezone.now)
|
||||
teamplanexpires = models.DateField(default=timezone.now)
|
||||
|
||||
@@ -721,6 +721,28 @@ def handle_updatedps(useremail, workoutids, debug=False,**kwargs):
|
||||
|
||||
# send email when a breakthrough workout is uploaded
|
||||
|
||||
@app.task
|
||||
def handle_sendemail_expired(useremail,userfirstname,userlastname,expireddate,
|
||||
**kwargs):
|
||||
if 'debug' in kwargs:
|
||||
debug = kwargs['debug']
|
||||
else:
|
||||
debug = False
|
||||
|
||||
subject = "Your rowsandall.com paid account has expired"
|
||||
from_email = 'Rowsandall <info@rowsandall.com>'
|
||||
|
||||
d = {
|
||||
'first_name':userfirstname,
|
||||
'last_name':userlastname,
|
||||
'siteurl':siteurl,
|
||||
'expireddate':expireddate,
|
||||
}
|
||||
|
||||
res = send_template_email(from_email,[useremail],
|
||||
subject,'accountexpiredemail.html',
|
||||
d,cc=['support@rowsandall.com'],**kwargs)
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_sendemail_breakthrough(workoutid, useremail,
|
||||
|
||||
23
rowers/templates/accountexpiredemail.html
Normal file
23
rowers/templates/accountexpiredemail.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% extends "emailbase.html" %}
|
||||
|
||||
{% block body %}
|
||||
<p>Dear <strong>{{ first_name }}</strong>,</p>
|
||||
|
||||
<p>
|
||||
Your Pro account on rowsandall.com expired on {{ expireddate }}. It
|
||||
has now been automatically reset to Basic.
|
||||
Let me know if you have any questions. If you want to continue using Pro membership,
|
||||
just sign up again through the site and I will change your membership back to Pro.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you do not want to continue the Pro membership, I'd be interested to know why you
|
||||
decided to not continue your Pro account. Did it not fulfill your expectations?
|
||||
This information is valuable to improve the site for all users. Thank you!
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Best Regards, the Rowsandall Team
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user