Commit 8903b766 authored by Michal Čihař's avatar Michal Čihař

Single place to get user name for display

parent 21ee8a2d
......@@ -42,6 +42,7 @@ from south.signals import post_migrate
from weblate.lang.models import Language
from weblate.trans.models import Project
from weblate.trans.util import get_user_display
import weblate
import logging
......@@ -191,6 +192,9 @@ class Profile(models.Model):
def __unicode__(self):
return self.user.username
def get_user_display(self):
return get_user_display(self.user)
def notify_user(self, notification, translation_obj, context = {}, headers = {}):
'''
Wrapper for sending notifications to user.
......
......@@ -33,7 +33,7 @@
<ul id="menu">
{% if user.is_authenticated %}
<li><a href="{% url 'profile' %}">{% blocktrans with user.get_full_name as name %}Logged in as {{ name }}{% endblocktrans %}</a></li>
<li><a href="{% url 'profile' %}">{% blocktrans with user.get_profile.get_user_display as name %}Logged in as {{ name }}{% endblocktrans %}</a></li>
<li><a href="{% url 'auth_logout' %}">{% trans "Logout" %}</a></li>
{% else %}
{% if registration_open %}
......
......@@ -76,7 +76,7 @@
<tbody>
{% for u in top_translations %}
<tr>
<td>{{ u.user.get_full_name }}</td>
<td>{{ u.get_user_display }}</td>
<td class="percent">{{ u.translated }}</td>
</tr>
{% endfor %}
......@@ -95,7 +95,7 @@
<tbody>
{% for u in top_suggestions %}
<tr>
<td>{{ u.user.get_full_name }}</td>
<td>{{ u.get_user_display }}</td>
<td class="percent">{{ u.suggested }}</td>
</tr>
{% endfor %}
......
{% for comment in comments %}
<tr>
<td>
<strong>{{ comment.user.get_full_name }}</strong><br />
<strong>{{ comment.get_user_display }}</strong><br />
{{ comment.timestamp|date:"DATETIME_FORMAT" }}
</td>
<td dir="auto">{{ comment.comment }}</td>
......
......@@ -113,7 +113,7 @@
<tr><td class="translatetext">{{ suggestion.target|fmttranslation:unit.translation.language }}</td></tr>
<tr><td>
{% if suggestion.user %}
{% blocktrans with suggestion.user.get_full_name as user %}Suggested by {{ user }}{% endblocktrans %}
{% blocktrans with suggestion.get_user_display as user %}Suggested by {{ user }}{% endblocktrans %}
{% else %}
{% trans "Suggested by anonymous user" %}
{% endif %}
......
......@@ -110,7 +110,7 @@
<div id="locking">
<p>{% trans "Locking the translation will prevent others to work on translation." %}</p>
{% if object.is_user_locked %}
<p>{% trans "Locked by:" %} {{ object.lock_user.get_full_name }}</p>
<p>{% trans "Locked by:" %} {{ object.get_lock_user_display }}</p>
<p>{% trans "Lock valid till:" %} {{ object.lock_time|date:"DATETIME_FORMAT" }}</p>
{% else %}
<p>{% trans "Translation is currently not locked." %}</p>
......
......@@ -52,7 +52,7 @@ from weblate.lang.models import Language
from weblate.trans.checks import CHECKS
from weblate.trans.managers import TranslationManager, UnitManager, DictionaryManager
from weblate.trans.filelock import FileLock, FileLockException
from util import is_plural, split_plural, join_plural, get_source, get_target, is_translated
from util import is_plural, split_plural, join_plural, get_source, get_target, is_translated, get_user_display
from django.db.models.signals import post_syncdb
from south.signals import post_migrate
......@@ -1293,7 +1293,7 @@ class Translation(models.Model):
'''
Returns formatted lock user.
'''
return self.lock_user.get_full_name()
return get_user_display(self.lock_user)
def get_lock_display(self):
return _('This translation is locked by %(user)s for translation till %(time)s!') % {
......@@ -2607,6 +2607,9 @@ class Suggestion(models.Model):
'''
return self.get_matching_unit().get_absolute_url()
def get_user_display(self):
return get_user_display(self.user)
class Comment(models.Model):
checksum = models.CharField(max_length = 40, db_index = True)
comment = models.TextField()
......@@ -2618,6 +2621,9 @@ class Comment(models.Model):
class Meta:
ordering = ['timestamp']
def get_user_display(self):
return get_user_display(self.user)
CHECK_CHOICES = [(x, CHECKS[x].name) for x in CHECKS]
class Check(models.Model):
......@@ -2709,10 +2715,7 @@ class Change(models.Model):
}
def get_user_display(self):
if self.user is None:
return _('None')
else:
return self.user.get_full_name()
return get_user_display(self.user)
def get_absolute_url(self):
'''
......
......@@ -25,6 +25,15 @@ from translate.storage.properties import propunit
PLURAL_SEPARATOR = '\x00\x00'
def get_user_display(user):
'''
Nicely formats user for display.
'''
if user is None:
return _('None')
else:
return user.get_full_name()
def is_plural(s):
'''
Checks whether string is plural form.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment