Browse Source

Add global autocomplete tags

This is kind of hacky again (and shouldn't contain the coronavirus tag
over the long term), but makes sure that the "spoiler", "nsfw", and
"coronaviruses.covid19" tags are always offered as autocomplete options,
no matter how common they are in the topic's group.
merge-requests/110/head
Deimos 5 years ago
parent
commit
3f1decb243
  1. 9
      tildes/tildes/models/group/group.py
  2. 4
      tildes/tildes/templates/includes/new_topic_form.jinja2
  3. 2
      tildes/tildes/templates/intercooler/topic_tags_edit.jinja2

9
tildes/tildes/models/group/group.py

@ -86,6 +86,15 @@ class Group(DatabaseModel):
else:
self.sidebar_rendered_html = None
@property
def autocomplete_topic_tags(self) -> List[str]:
"""Return the topic tags that should be offered as autocomplete options."""
global_options = ["nsfw", "spoiler", "coronaviruses.covid19"]
return self.common_topic_tags + [
tag for tag in global_options if tag not in self.common_topic_tags
]
def __repr__(self) -> str:
"""Display the group's path and ID as its repr format."""
return f"<Group {self.path} ({self.group_id})>"

4
tildes/tildes/templates/includes/new_topic_form.jinja2

@ -48,11 +48,11 @@
{# Hide the tag-adding form in a <details> unless it should be shown for this user #}
{% if request.user.show_tags_on_new_topic %}
{{ topic_tagging(autocomplete_options=group.common_topic_tags, value=tags) }}
{{ topic_tagging(autocomplete_options=group.autocomplete_topic_tags, value=tags) }}
{% else %}
<details>
<summary>Add tags (optional)</summary>
{{ topic_tagging(autocomplete_options=group.common_topic_tags, value=tags) }}
{{ topic_tagging(autocomplete_options=group.autocomplete_topic_tags, value=tags) }}
</details>
{% endif %}

2
tildes/tildes/templates/intercooler/topic_tags_edit.jinja2

@ -14,7 +14,7 @@
data-js-remove-on-success
>
<input type="hidden" name="conflict_check" id="conflict_check" value="{{ topic.tags|join(",") }}">
{{ topic_tagging(value=topic.tags|join(', '), auto_focus=True, autocomplete_options=topic.group.common_topic_tags) }}
{{ topic_tagging(value=topic.tags|join(', '), auto_focus=True, autocomplete_options=topic.group.autocomplete_topic_tags) }}
<div class="form-buttons">
<button class="btn btn-primary" type="submit">Save tags</button>
<button type="button" class="btn btn-link" data-js-cancel-button>Cancel</button>

Loading…
Cancel
Save