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.
This commit is contained in:
Deimos
2020-03-17 17:05:42 -06:00
parent 355dd9d334
commit 3f1decb243
3 changed files with 12 additions and 3 deletions

View File

@@ -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})>"

View File

@@ -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 %}

View File

@@ -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>