Implemented #546

This commit is contained in:
Julien Constant
2023-04-22 17:24:07 +02:00
parent 08460a6964
commit 1964974099
3 changed files with 22 additions and 4 deletions

View File

@ -23,6 +23,7 @@
# #
# #
import importlib import importlib
from typing import Tuple
from django.db import models from django.db import models
from django.core.mail import send_mail from django.core.mail import send_mail
@ -318,6 +319,14 @@ class User(AbstractBaseUser):
def to_dict(self): def to_dict(self):
return self.__dict__ 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 @cached_property
def was_subscribed(self): def was_subscribed(self):
return self.subscriptions.exists() return self.subscriptions.exists()

View File

@ -155,7 +155,12 @@
{% endif %} {% endif %}
{% else %} {% else %}
<div> <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 %} {% if user.is_board_member %}
<a href="{{ url('subscription:subscription') }}?member={{ profile.id }}">{% trans %}New subscription{% endtrans <a href="{{ url('subscription:subscription') }}?member={{ profile.id }}">{% trans %}New subscription{% endtrans
%}</a> %}</a>

View File

@ -3171,9 +3171,13 @@ msgstr "Avatar"
msgid "Scrub" msgid "Scrub"
msgstr "Blouse" msgstr "Blouse"
#: core/templates/core/user_detail.jinja:141 #: core/templates/core/user_detail.jinja:160
msgid "Not subscribed" msgid "Not subscribed for %(y)s year(s) %(m)s month(s) %(d)s day(s) (%(date)s)"
msgstr "Non cotisant" 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 #: core/templates/core/user_detail.jinja:143
#: subscription/templates/subscription/subscription.jinja:4 #: subscription/templates/subscription/subscription.jinja:4