Skip to content

Commit

Permalink
fix: better datetime handle
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Oct 10, 2023
1 parent 8ba2362 commit 2534881
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions frontend/html/emails/subscription_expired.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@

<br><br><br>
{% endblock %}

{% block unsubscribe %}
<p style="font-size: 12px;">
Если вам больше не хочется никогда получать никаких писем от Клуба,<br> нажмите <a href="{{ settings.APP_HOST }}/notifications/unsubscribe/%user_id%/%secret_code%/">отписаться вообще от всего</a>.
</p>
{% endblock %}
15 changes: 10 additions & 5 deletions payments/management/commands/send_subscription_expired.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import logging
from datetime import datetime, timedelta
from datetime import timedelta, date

from django.conf import settings
from django.core.management import BaseCommand
Expand All @@ -11,7 +12,7 @@

log = logging.getLogger(__name__)

TIMEDELTA = timedelta(days=14)
EXPIRATION_DAY = date.today() + timedelta(days=14)


class Command(BaseCommand):
Expand All @@ -30,12 +31,11 @@ def handle(self, *args, **options):
else:
about_to_expire_users = User.objects\
.filter(
membership_expires_at__gte=datetime.utcnow() + TIMEDELTA,
membership_expires_at__lt=datetime.utcnow() + TIMEDELTA + timedelta(days=1),
membership_expires_at__gte=EXPIRATION_DAY,
membership_expires_at__lt=EXPIRATION_DAY + timedelta(days=1),
moderation_status=User.MODERATION_STATUS_APPROVED,
deleted_at__isnull=True,
)\
.exclude(is_email_unsubscribed=True)\
.exclude(membership_platform_type=User.MEMBERSHIP_PLATFORM_PATREON)

for user in about_to_expire_users:
Expand All @@ -51,6 +51,11 @@ def handle(self, *args, **options):
"user": user,
})

email = email\
.replace("%username%", user.slug)\
.replace("%user_id%", str(user.id))\
.replace("%secret_code%", base64.b64encode(user.secret_hash.encode("utf-8")).decode())

send_club_email(
recipient=user.email,
subject=f"Ваша клубная карта скоро истечёт 😱",
Expand Down

0 comments on commit 2534881

Please sign in to comment.