Skip to content

Commit

Permalink
Show time of last update
Browse files Browse the repository at this point in the history
Refs #8.
  • Loading branch information
matthiask committed Jul 8, 2024
1 parent cbb7e7f commit 21eab09
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/templates/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ <h1>{{ project }}</h1>
<h2>{% translate 'catalogs'|capfirst %}</h2>
<ul>
{% for catalog in project.catalogs.all %}
<li><a href="{{ catalog.get_absolute_url }}">{{ catalog }}</a></li>
<li>
<a href="{{ catalog.get_absolute_url }}">{{ catalog }}</a>
<small>
{% blocktranslate with timesince=project.pretty_timesince trimmed %}Updated {{ timesince }} ago.{% endblocktranslate %}
</small>
</li>
{% endfor %}
</ul>

Expand Down
7 changes: 6 additions & 1 deletion app/templates/projects/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ <h2>{% translate 'Your projects' %}</h2>
{% if projects %}
<ul>
{% for project in projects %}
<li><a href="{{ project.get_absolute_url }}">{{ project.name }}</a></li>
<li>
<a href="{{ project.get_absolute_url }}">{{ project.name }}</a>
<small>
{% blocktranslate with timesince=project.pretty_timesince trimmed %}Updated {{ timesince }} ago.{% endblocktranslate %}
</small>
</li>
{% endfor %}
</ul>
{% else %}
Expand Down
1 change: 1 addition & 0 deletions projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def update(self, catalog, *, request):

catalog.pofile = str(catalog.po)
catalog.save()
catalog.project.save()

else:
messages.info(request, _("No changes detected."))
Expand Down
9 changes: 9 additions & 0 deletions projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core import validators
from django.db import models
from django.urls import reverse
from django.utils.timesince import timesince
from django.utils.translation import gettext_lazy as _


Expand Down Expand Up @@ -77,6 +78,10 @@ def clean(self):
def get_api_url(self):
return f"/api/pofile/{self.slug}/"

@property
def pretty_timesince(self):
return timesince(self.updated_at, depth=1)


class CatalogQuerySet(models.QuerySet):
def for_user(self, user):
Expand Down Expand Up @@ -129,3 +134,7 @@ def get_absolute_url(self):
@cached_property
def po(self):
return polib.pofile(self.pofile, wrapwidth=0)

@property
def pretty_timesince(self):
return timesince(self.updated_at, depth=1)

0 comments on commit 21eab09

Please sign in to comment.