Implemented #546

This commit is contained in:
Julien Constant 2023-04-22 17:24:07 +02:00
parent 08460a6964
commit 1964974099
No known key found for this signature in database
GPG Key ID: 816E7C070117E5B7
3 changed files with 22 additions and 4 deletions

View File

@ -23,6 +23,7 @@
#
#
import importlib
from typing import Tuple
from django.db import models
from django.core.mail import send_mail
@ -317,6 +318,14 @@ class User(AbstractBaseUser):
def to_dict(self):
return self.__dict__
@cached_property
def last_subscription_date(self) -> date:
return self.subscriptions.filter(subscription_end__lte=timezone.now()).order_by('-subscription_end').first().subscription_end
def last_subscription_since(self) -> Tuple[int, int, int]:
diff = date.today() - self.last_subscription_date
return [diff.days // 365, (diff.days % 365) // 30, (diff.days % 365) % 30]
@cached_property
def was_subscribed(self):

View File

@ -155,7 +155,12 @@
{% endif %}
{% else %}
<div>
{% trans %}Not subscribed{% endtrans %}
{% if profile.was_subscribed %}
{% set duration = profile.last_subscription_since() %}
{% trans y=duration[0], m=duration[1], d=duration[2], date=profile.last_subscription_date %}Not subscribed for {{ y }} year(s) {{ m }} month(s) {{ d }} day(s) ({{ date }}){% endtrans %}
{% else %}
{% trans %}Never subscribed{% endtrans %}
{% endif %}
{% if user.is_board_member %}
<a href="{{ url('subscription:subscription') }}?member={{ profile.id }}">{% trans %}New subscription{% endtrans
%}</a>

View File

@ -3171,9 +3171,13 @@ msgstr "Avatar"
msgid "Scrub"
msgstr "Blouse"
#: core/templates/core/user_detail.jinja:141
msgid "Not subscribed"
msgstr "Non cotisant"
#: core/templates/core/user_detail.jinja:160
msgid "Not subscribed for %(y)s year(s) %(m)s month(s) %(d)s day(s) (%(date)s)"
msgstr "Non cotisant depuis %(y)s année(s) %(m)s mois %(d)s jour(s) (%(date)s)"
#: core/templates/core/user_detail.jinja:162
msgid "Never subscribed"
msgstr "N'a jamais cotisé"
#: core/templates/core/user_detail.jinja:143
#: subscription/templates/subscription/subscription.jinja:4