diff --git a/common/templates/_sidebar.html b/common/templates/_sidebar.html index 1720452f..a534aef6 100644 --- a/common/templates/_sidebar.html +++ b/common/templates/_sidebar.html @@ -183,25 +183,31 @@ {% endif %} - {% if top_tags %} + {% if top_tags is not None %}
- {% trans 'Common Tags' %} + {% trans 'Tags' %}
{% for t in top_tags %} - {{ t.title }} + + {% if t.pinned %} + + {% endif %} + {% if t.visibility > 0 %} + + {% endif %} + {{ t.title }} + ({{ t.total }}) {% empty %} -
{% trans "nothing so far." %}
+
{% trans "no tags so far." %}
{% endfor %}
- {% if top_tags %} - ...{% trans 'show more' %} - {% endif %} + ({% trans 'show all' %})
diff --git a/journal/migrations/0026_pinned_tag_index.py b/journal/migrations/0026_pinned_tag_index.py new file mode 100644 index 00000000..b9c7231e --- /dev/null +++ b/journal/migrations/0026_pinned_tag_index.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.13 on 2024-06-05 00:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("journal", "0025_pin_tags"), + ] + + operations = [ + migrations.AddIndex( + model_name="tag", + index=models.Index( + fields=["owner", "pinned"], name="journal_tag_owner_i_068598_idx" + ), + ), + ] diff --git a/journal/models/tag.py b/journal/models/tag.py index 2858b361..a6445204 100644 --- a/journal/models/tag.py +++ b/journal/models/tag.py @@ -51,6 +51,7 @@ class Tag(List): class Meta: unique_together = [["owner", "title"]] + indexes = [models.Index(fields=["owner", "pinned"])] @staticmethod def cleanup_title(title, replace=True): @@ -102,13 +103,6 @@ class TagManager: ) return tag_titles - @staticmethod - def all_tags_by_owner(owner, public_only=False): - tags = owner.tag_set.all().annotate(total=Count("members")).order_by("-total") - if public_only: - tags = tags.filter(visibility=0) - return tags - @staticmethod def tag_item_for_owner( owner: APIdentity, @@ -142,13 +136,14 @@ class TagManager: def __init__(self, owner): self.owner = owner - @property - def all_tags(self): - return TagManager.all_tags_by_owner(self.owner) - - @property - def public_tags(self): - return TagManager.all_tags_by_owner(self.owner, public_only=True) + def get_tags(self, public_only=False, pinned_only=False): + tags = self.owner.tag_set.all() + tags = tags.annotate(total=Count("members")).order_by("-total") + if public_only: + tags = tags.filter(visibility=0) + if pinned_only: + tags = tags.filter(pinned=True) + return tags @staticmethod def popular_tags(days: int = 30): diff --git a/journal/templates/tag_edit.html b/journal/templates/tag_edit.html index dff32184..86a4b54c 100644 --- a/journal/templates/tag_edit.html +++ b/journal/templates/tag_edit.html @@ -49,7 +49,7 @@ - {% trans "Personal tags are not shown to others when they view your tag list, unless you pin them. However, if you use this tag when marking an item publicly, it might still be visible to others." %} + {% trans "Personal tags are not included in public index. However, if you use this tag when marking an item publicly, it might still be visible to others." %}