diff --git a/src/backend/joanie/core/models/accounts.py b/src/backend/joanie/core/models/accounts.py index 127723cb4..42426d43e 100644 --- a/src/backend/joanie/core/models/accounts.py +++ b/src/backend/joanie/core/models/accounts.py @@ -67,6 +67,13 @@ def __init__(self, *args, **kwargs): def __str__(self): return self.username + @property + def name(self): + """ + Return the full name of the user if available, otherwise the username. + """ + return self.get_full_name() or self.username + def clean(self): """ Normalize the `phone_number` value for consistency in database. diff --git a/src/backend/joanie/core/models/certifications.py b/src/backend/joanie/core/models/certifications.py index d14a59172..b0922d940 100644 --- a/src/backend/joanie/core/models/certifications.py +++ b/src/backend/joanie/core/models/certifications.py @@ -246,7 +246,7 @@ def get_document_context(self, language_code=None): "delivery_stamp": timezone.now(), "verification_link": self.verification_uri, "student": { - "name": self.owner.get_full_name() or self.owner.username, + "name": self.owner.name, }, "site": { "name": settings.JOANIE_CATALOG_NAME, diff --git a/src/backend/joanie/core/serializers/admin.py b/src/backend/joanie/core/serializers/admin.py index f303579c0..2743ce2f2 100755 --- a/src/backend/joanie/core/serializers/admin.py +++ b/src/backend/joanie/core/serializers/admin.py @@ -1269,7 +1269,7 @@ def get_owner_name(self, instance) -> str: Return the full name of the order's owner if available, otherwise fallback to the username """ - return instance.owner.get_full_name() or instance.owner.username + return instance.owner.name class AdminOrderExportSerializer(serializers.ModelSerializer): # pylint: disable=too-many-public-methods @@ -1396,7 +1396,7 @@ def get_owner_name(self, instance) -> str: Return the full name of the order's owner if available, otherwise fallback to the username """ - return instance.owner.get_full_name() or instance.owner.username + return instance.owner.name def get_enrollment_created_on(self, instance) -> str: """ @@ -1609,7 +1609,7 @@ def get_user_name(self, instance) -> str: Return the full name of the enrollment's user if available, otherwise fallback to the username """ - return instance.user.get_full_name() or instance.user.username + return instance.user.name class AdminEnrollmentSerializer(serializers.ModelSerializer): diff --git a/src/backend/joanie/core/serializers/client.py b/src/backend/joanie/core/serializers/client.py index 104b48bc9..848378350 100644 --- a/src/backend/joanie/core/serializers/client.py +++ b/src/backend/joanie/core/serializers/client.py @@ -389,7 +389,7 @@ def get_owner_name(self, instance) -> str: """ Return the name full name of the order's owner or fallback to username """ - return instance.owner.get_full_name() or instance.owner.username + return instance.owner.name class CertificationDefinitionSerializer(serializers.ModelSerializer): diff --git a/src/backend/joanie/core/utils/contract_definition.py b/src/backend/joanie/core/utils/contract_definition.py index 1a2263219..7b0bdfce3 100644 --- a/src/backend/joanie/core/utils/contract_definition.py +++ b/src/backend/joanie/core/utils/contract_definition.py @@ -121,7 +121,7 @@ def generate_document_context(contract_definition=None, user=None, order=None): contract_description = contract_definition.description if user: - user_name = user.get_full_name() or user.username + user_name = user.name user_email = user.email user_phone_number = user.phone_number diff --git a/src/backend/joanie/core/utils/emails.py b/src/backend/joanie/core/utils/emails.py index ac17635e6..828c79157 100644 --- a/src/backend/joanie/core/utils/emails.py +++ b/src/backend/joanie/core/utils/emails.py @@ -26,7 +26,7 @@ def prepare_context_data( or refused. """ context_data = { - "fullname": order.owner.get_full_name() or order.owner.username, + "fullname": order.owner.name, "email": order.owner.email, "product_title": product_title, "installment_amount": Money(installment_amount), diff --git a/src/backend/joanie/debug/views.py b/src/backend/joanie/debug/views.py index 4cf1c8d60..aeee48ad9 100644 --- a/src/backend/joanie/debug/views.py +++ b/src/backend/joanie/debug/views.py @@ -60,7 +60,7 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["title"] = "👨‍💻Development email preview" context["email"] = order.owner.email - context["fullname"] = order.owner.get_full_name() or order.owner.username + context["fullname"] = order.owner.name context["product"] = order.product context["site"] = { "name": settings.JOANIE_CATALOG_NAME, @@ -122,7 +122,7 @@ def get_context_data(self, **kwargs): targeted_installment_index=order.get_installment_index( state=PAYMENT_STATE_PAID ), - fullname=order.owner.get_full_name() or order.owner.username, + fullname=order.owner.name, email=order.owner.email, dashboard_order_link=settings.JOANIE_DASHBOARD_ORDER_LINK, site={ diff --git a/src/backend/joanie/payment/backends/base.py b/src/backend/joanie/payment/backends/base.py index 760f9c6b1..73ef90b85 100644 --- a/src/backend/joanie/payment/backends/base.py +++ b/src/backend/joanie/payment/backends/base.py @@ -83,7 +83,7 @@ def _send_mail_subscription_success(cls, order): template_vars={ "title": _("Subscription confirmed!"), "email": order.owner.email, - "fullname": order.owner.get_full_name() or order.owner.username, + "fullname": order.owner.name, "product": order.product, "site": { "name": settings.JOANIE_CATALOG_NAME,