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