From: jordan Date: Wed, 6 Apr 2011 14:53:34 +0000 (+0000) Subject: SPLUNK-198. Long usernames used to cause trouble with the UI. Every username length... X-Git-Tag: live~375 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/4dd05e7d3aeab9542cd63f7fe056f446f3f3b70e?ds=sidebyside SPLUNK-198. Long usernames used to cause trouble with the UI. Every username length should be reasonable, but some users use radiculously long usernames. For such cases two new settings have been added to the Users Set. TRUNCATE_LONG_USERNAMES and TRUNCATE_USERNAMES_LONGER_THAN. This way we provide an easy interface that lets the admins specify whether the long usernames should be truncated and after which character that should happen. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@935 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/user.py b/forum/models/user.py index 699c7bc..e736538 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -5,6 +5,8 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser from django.db.models import Q +from forum.settings import TRUNCATE_LONG_USERNAMES, TRUNCATE_USERNAMES_LONGER_THAN + import string from random import Random @@ -146,12 +148,17 @@ class User(BaseModel, DjangoUser): @property def decorated_name(self): + username = self.username + + if len(username) > TRUNCATE_USERNAMES_LONGER_THAN and TRUNCATE_LONG_USERNAMES: + username = '%s...' % username[:TRUNCATE_USERNAMES_LONGER_THAN-3] + if settings.SHOW_STATUS_DIAMONDS: if self.is_superuser: - return u"%s \u2666\u2666" % self.username + return u"%s \u2666\u2666" % username if self.is_staff: - return u"%s \u2666" % self.username + return u"%s \u2666" % username return self.username diff --git a/forum/settings/users.py b/forum/settings/users.py index 040e8eb..cceaf57 100644 --- a/forum/settings/users.py +++ b/forum/settings/users.py @@ -22,6 +22,16 @@ label = _("Disabled usernames"), help_text = _("A comma separated list of disabled usernames (usernames not allowed during a new user registration)."), widget=CommaStringListWidget)) +TRUNCATE_LONG_USERNAMES = Setting('TRUNCATE_LONG_USERNAMES', True, USERS_SET, dict( +label=_("Truncate long usernames"), +help_text = _("The long usernames will be truncated.."), +required=False, +)) + +TRUNCATE_USERNAMES_LONGER_THAN = Setting('TRUNCATE_USERNAMES_LONGER_THAN', 15, USERS_SET, dict( +label = _("Truncate usernames longer than"), +help_text = _("The usernames that are longer than this will be truncated and ... will be appended."))) + SHOW_STATUS_DIAMONDS = Setting('SHOW_STATUS_DIAMONDS', True, USERS_SET, dict( label=_("Show status diamonds"), help_text = _("Show status \"diamonds\" next to moderators or superusers usernames."),