mirror of https://github.com/snachodog/mybuddy.git
Use user first and last name, when available, in UI
This commit is contained in:
parent
192d8d9b09
commit
d0b33c2b1b
|
@ -232,7 +232,9 @@
|
||||||
href="#"
|
href="#"
|
||||||
data-toggle="dropdown"
|
data-toggle="dropdown"
|
||||||
aria-haspopup="true"
|
aria-haspopup="true"
|
||||||
aria-expanded="false"><i class="icon icon-user" aria-hidden="true"></i> {{ request.user }}
|
aria-expanded="false">
|
||||||
|
<i class="icon icon-user" aria-hidden="true"></i>
|
||||||
|
{% firstof user.get_full_name user.get_username %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-user-menu-link">
|
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-user-menu-link">
|
||||||
<h6 class="dropdown-header">{% trans "User" %}</h6>
|
<h6 class="dropdown-header">{% trans "User" %}</h6>
|
||||||
|
|
|
@ -440,6 +440,13 @@ class Timer(models.Model):
|
||||||
child=self.child)
|
child=self.child)
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_username(self):
|
||||||
|
""" Get Timer user's name with a preference for the full name. """
|
||||||
|
if self.user.get_full_name():
|
||||||
|
return self.user.get_full_name()
|
||||||
|
return self.user.get_username()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, db, field_names, values):
|
def from_db(cls, db, field_names, values):
|
||||||
instance = super(Timer, cls).from_db(db, field_names, values)
|
instance = super(Timer, cls).from_db(db, field_names, values)
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
{% blocktrans trimmed with user=object.user %}
|
{% blocktrans trimmed with user=object.user_username %}
|
||||||
{{ timer }} created by {{ user }}
|
{{ timer }} created by {{ user }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
<td>{{ timer.duration|duration_string }}</td>
|
<td>{{ timer.duration|duration_string }}</td>
|
||||||
<td>{{ timer.end }}</td>
|
<td>{{ timer.end }}</td>
|
||||||
<td>{{ timer.active|bool_icon }}</td>
|
<td>{{ timer.active|bool_icon }}</td>
|
||||||
<td>{{ timer.user }}</td>
|
<td>{{ timer.user_username }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -171,15 +171,16 @@ class TimerTestCase(TestCase):
|
||||||
last_name='Last',
|
last_name='Last',
|
||||||
birth_date=timezone.localdate()
|
birth_date=timezone.localdate()
|
||||||
)
|
)
|
||||||
|
self.user = User.objects.first()
|
||||||
self.named = models.Timer.objects.create(
|
self.named = models.Timer.objects.create(
|
||||||
name='Named',
|
name='Named',
|
||||||
end=timezone.localtime(),
|
end=timezone.localtime(),
|
||||||
user=User.objects.first(),
|
user=self.user,
|
||||||
child=child
|
child=child
|
||||||
)
|
)
|
||||||
self.unnamed = models.Timer.objects.create(
|
self.unnamed = models.Timer.objects.create(
|
||||||
end=timezone.localtime(),
|
end=timezone.localtime(),
|
||||||
user=User.objects.first()
|
user=self.user
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_timer_create(self):
|
def test_timer_create(self):
|
||||||
|
@ -202,6 +203,13 @@ class TimerTestCase(TestCase):
|
||||||
'{} ({})'.format(str(self.named), str(self.named.child))
|
'{} ({})'.format(str(self.named), str(self.named.child))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_timer_user_username(self):
|
||||||
|
self.assertEqual(self.named.user_username, self.user.get_username())
|
||||||
|
self.user.first_name = 'User'
|
||||||
|
self.user.last_name = 'Name'
|
||||||
|
self.user.save()
|
||||||
|
self.assertEqual(self.named.user_username, self.user.get_full_name())
|
||||||
|
|
||||||
def test_timer_restart(self):
|
def test_timer_restart(self):
|
||||||
self.named.restart()
|
self.named.restart()
|
||||||
self.assertIsNone(self.named.end)
|
self.assertIsNone(self.named.end)
|
||||||
|
|
|
@ -13,12 +13,12 @@
|
||||||
|
|
||||||
{% block listgroup %}
|
{% block listgroup %}
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
{% for instance in instances %}
|
{% for timer in instances %}
|
||||||
<a href="{% url 'core:timer-detail' instance.id %}"
|
<a href="{% url 'core:timer-detail' timer.id %}"
|
||||||
class="list-group-item list-group-item-action">
|
class="list-group-item list-group-item-action">
|
||||||
<strong>{{ instance.title_with_child }}</strong>
|
<strong>{{ timer.title_with_child }}</strong>
|
||||||
<p class="text-muted small m-0">
|
<p class="text-muted small m-0">
|
||||||
{% blocktrans trimmed with start=instance.start|time user=instance.user %}
|
{% blocktrans trimmed with start=timer.start|time user=timer.user_username %}
|
||||||
Started by {{ user }} at {{ start }}
|
Started by {{ user }} at {{ start }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in New Issue