From 1bc28542fa4ef7453935a70604c39dd100b03fc2 Mon Sep 17 00:00:00 2001 From: Bob Booy Liewes Date: Mon, 28 Feb 2022 14:08:43 +0100 Subject: [PATCH] Use the django default user method get_username() in the history for obaining the username of the user. This uses the USERNAME_FIELD attribute on the abstract user model class in order to obtain which user attribute to use as username. For the default user model it defaults back to username, which is a valid attribute there. See https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#django.contrib.auth.models.AbstractBaseUser.get_username for more info --- binder/history.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binder/history.py b/binder/history.py index 698f9377..739bc9c1 100644 --- a/binder/history.py +++ b/binder/history.py @@ -22,7 +22,7 @@ class Changeset(models.Model): def __str__(self): uuid = self.uuid[:8] if self.uuid else None - username = self.user.username if self.user else None + username = self.user.get_username() if self.user else None return '{}/{} by {} on {}'.format(self.id, uuid, username, self.date.strftime('%Y%m%d-%H%M%S')) class Meta: @@ -215,7 +215,7 @@ def view_changesets(request, changesets): users = [] for u in get_user_model().objects.filter(id__in=userids): - users.append({'id': u.id, 'username': u.username, 'email': u.email, 'first_name': u.first_name, 'last_name': u.last_name}) + users.append({'id': u.id, 'username': u.get_username(), 'email': u.email, 'first_name': u.first_name, 'last_name': u.last_name}) return JsonResponse({'data': data, 'with': {'user': users}}) @@ -224,7 +224,7 @@ def view_changesets(request, changesets): def view_changesets_debug(request, changesets): body = ['', '', '', '', ''] for cs in changesets: - username = cs.user.username if cs.user else None + username = cs.user.get_username() if cs.user else None body.append('

Changeset {} by {}: {} on {} {{{}}}'.format(cs.id, cs.source, username, cs.date.strftime('%Y-%m-%d %H:%M:%S'), cs.uuid)) body.append('

') body.append('')