diff --git a/hypha/apply/activity/templatetags/activity_tags.py b/hypha/apply/activity/templatetags/activity_tags.py index 4a0c6add978992ae9fa97cfbe0c1539b2bb38942..7a6fb275462c8f3b2714bc0959928a83290b248a 100644 --- a/hypha/apply/activity/templatetags/activity_tags.py +++ b/hypha/apply/activity/templatetags/activity_tags.py @@ -35,7 +35,7 @@ def display_author(activity, user) -> str: return settings.ORG_LONG_NAME if isinstance(activity.related_object, Review) and activity.source.user == user: return "Reviewer" - return activity.user.get_full_name_with_group() + return activity.user.get_display_name_with_group() @register.filter diff --git a/hypha/apply/users/models.py b/hypha/apply/users/models.py index 2470e68affb4c4cfdfc22de1da1390135e4f8a15..5375aa29c11feb5986566b9cc502049ac4bc82e7 100644 --- a/hypha/apply/users/models.py +++ b/hypha/apply/users/models.py @@ -226,16 +226,26 @@ class User(AbstractUser): def get_full_name(self): return self.full_name.strip() - def get_short_name(self): - return self.email + def get_short_name(self) -> str: + """Gets the local-part (username) of the user's email - def get_full_name_with_group(self): + ie. hyphaiscool@hypha.app returns "hyphaiscool" + """ + return self.email.split("@")[0] + + def get_display_name_with_group(self) -> str: + """Gets the user's display name, along with their role in parenthesis + + If the user has a full name set that will be used, otherwise pulls the email. + """ + display_name = str(self) is_apply_staff = f" ({STAFF_GROUP_NAME})" if self.is_apply_staff else "" is_reviewer = f" ({REVIEWER_GROUP_NAME})" if self.is_reviewer else "" + is_partner = f" ({PARTNER_GROUP_NAME})" if self.is_partner else "" is_applicant = f" ({APPLICANT_GROUP_NAME})" if self.is_applicant else "" is_finance = f" ({FINANCE_GROUP_NAME})" if self.is_finance else "" is_contracting = f" ({CONTRACTING_GROUP_NAME})" if self.is_contracting else "" - return f"{self.full_name.strip()}{is_apply_staff}{is_reviewer}{is_applicant}{is_finance}{is_contracting}" + return f"{display_name}{is_apply_staff}{is_reviewer}{is_applicant}{is_partner}{is_finance}{is_contracting}" @cached_property def roles(self):