Skip to content

Commit

Permalink
Show a log of recent activity
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Aug 9, 2024
1 parent 19eee4c commit a225cfe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/templates/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ <h2>{% translate 'CLI configuration' %}</h2>
<summary><code>~/.config/traduire.toml</code></summary>
<pre>{{ toml }}</pre>
</details>

<h2>{% translate 'Latest activity' %}</h2>
{% for a in activity %}{{ a.as_html }}{% empty %}<p>{% translate 'None' %}</p>{% endfor %}
{% endblock %}
17 changes: 17 additions & 0 deletions projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils.formats import date_format
from django.utils.html import format_html
from django.utils.timesince import timesince
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -232,3 +234,18 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)

save.alters_data = True

def as_html(self):
return format_html(
"""\
<p>
<small>{created_at}</small><br>
{user} {action} {catalog}
</p>
""",
created_at=date_format(self.created_at, "Y-m-d H:i"),
action=self.get_action_display(),
user=self.user or self.user_string,
project=self.project or self.project_string,
catalog=self.catalog or self.catalog_string,
)
3 changes: 3 additions & 0 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def project(request, slug):
{
"project": project,
"toml": project.toml(request=request),
"activity": Event.objects.filter(project=project).select_related(
"user", "project", "catalog"
)[:30],
},
)

Expand Down

0 comments on commit a225cfe

Please sign in to comment.