From f7f1e7f35850f111f3478116b440085cc7a6f3ac Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 19 Apr 2020 10:54:05 +0200 Subject: [PATCH] replace user.next_bill_date() by sub.next_bill_date.strftime("%Y-%m-%d") --- app/dashboard/templates/dashboard/billing.html | 2 +- app/dashboard/templates/dashboard/pricing.html | 15 ++++++++------- app/models.py | 10 ---------- cron.py | 12 ++++++++++-- .../emails/transactional/subscription-end.html | 2 +- .../emails/transactional/subscription-end.txt | 2 +- templates/header.html | 6 ++++-- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/dashboard/templates/dashboard/billing.html b/app/dashboard/templates/dashboard/billing.html index d2a74a17..6c6cbfb7 100644 --- a/app/dashboard/templates/dashboard/billing.html +++ b/app/dashboard/templates/dashboard/billing.html @@ -14,7 +14,7 @@ {% if sub.cancelled %}

You are on the {{ sub.plan_name() }} plan.
- You have canceled your subscription and it will end on {{ current_user.next_bill_date() }} + You have canceled your subscription and it will end on {{ sub.next_bill_date.strftime("%Y-%m-%d") }}


diff --git a/app/dashboard/templates/dashboard/pricing.html b/app/dashboard/templates/dashboard/pricing.html index 0ce5320c..fd50e965 100644 --- a/app/dashboard/templates/dashboard/pricing.html +++ b/app/dashboard/templates/dashboard/pricing.html @@ -57,13 +57,14 @@ - {% if current_user.is_cancel() %} - + {% set sub = current_user.get_subscription() %} + {% if sub and sub.cancelled %} + {% endif %}
diff --git a/app/models.py b/app/models.py index dc5f3575..05a850ab 100644 --- a/app/models.py +++ b/app/models.py @@ -262,16 +262,6 @@ class User(db.Model, ModelMixin, UserMixin): return True - def next_bill_date(self) -> str: - sub: Subscription = self.get_subscription() - if sub: - return sub.next_bill_date.strftime("%Y-%m-%d") - - LOG.error( - f"next_bill_date() should be called only on user with active subscription. User {self}" - ) - return "" - def is_cancel(self) -> bool: """User has canceled their subscription but the subscription is still active, i.e. next_bill_date > now""" diff --git a/cron.py b/cron.py index 912d69a7..651092c6 100644 --- a/cron.py +++ b/cron.py @@ -63,8 +63,16 @@ def notify_premium_end(): send_email( user.email, f"Your subscription will end soon {user.name}", - render("transactional/subscription-end.txt", user=user), - render("transactional/subscription-end.html", user=user), + render( + "transactional/subscription-end.txt", + user=user, + next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"), + ), + render( + "transactional/subscription-end.html", + user=user, + next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"), + ), ) diff --git a/templates/emails/transactional/subscription-end.html b/templates/emails/transactional/subscription-end.html index 6d4d5a2b..dcb4536f 100644 --- a/templates/emails/transactional/subscription-end.html +++ b/templates/emails/transactional/subscription-end.html @@ -7,7 +7,7 @@ {{ render_text("Hi,") }} {% endif %} - {{ render_text("Your subscription will end on " + user.next_bill_date() + ".") }} + {{ render_text("Your subscription will end on " + next_bill_date + ".") }} {{ render_text("When the subscription ends:") }} diff --git a/templates/emails/transactional/subscription-end.txt b/templates/emails/transactional/subscription-end.txt index 32c6b881..b84c90fd 100644 --- a/templates/emails/transactional/subscription-end.txt +++ b/templates/emails/transactional/subscription-end.txt @@ -1,6 +1,6 @@ Hi {{user.name}} -Your subscription will end on {{ user.next_bill_date() }}. +Your subscription will end on {{ next_bill_date }}. When the subscription ends: diff --git a/templates/header.html b/templates/header.html index 7161fe40..973c8860 100644 --- a/templates/header.html +++ b/templates/header.html @@ -28,9 +28,11 @@ {% if current_user.in_trial() %} Trial ends {{ current_user.trial_end|dt }} {% elif current_user.is_premium() %} + Premium - {% if current_user.is_cancel() %} - until {{ current_user.next_bill_date() }} + {% set sub = current_user.get_subscription() %} + {% if sub and sub.cancelled %} + until {{ sub.next_bill_date.strftime("%Y-%m-%d") }} {% endif %} {% endif %}