diff options
-rw-r--r-- | fietsboek/models/user.py | 10 | ||||
-rw-r--r-- | fietsboek/templates/edit.jinja2 | 2 | ||||
-rw-r--r-- | fietsboek/templates/edit_form.jinja2 | 9 | ||||
-rw-r--r-- | fietsboek/templates/finish_upload.jinja2 | 2 |
4 files changed, 20 insertions, 3 deletions
diff --git a/fietsboek/models/user.py b/fietsboek/models/user.py index a972f8e..d4b5491 100644 --- a/fietsboek/models/user.py +++ b/fietsboek/models/user.py @@ -3,6 +3,7 @@ import datetime import enum import uuid import secrets +from functools import reduce from sqlalchemy import ( Column, @@ -303,6 +304,15 @@ class User(Base): stmt = friends_assoc.insert().values(user_1_id=self.id, user_2_id=friend.id) object_session(self).execute(stmt) + def autocomplete_tags(self): + """Returns all tags the user has ever used, suitable for autocompletion + lists. + + :return: All tags of the user. + :rtype: ~collections.abc.Iterator[str] + """ + return reduce(lambda acc, track: acc | track.text_tags(), self.tracks, set()) + Index('idx_users_email', User.email, unique=True) diff --git a/fietsboek/templates/edit.jinja2 b/fietsboek/templates/edit.jinja2 index 91c44e3..a9a4221 100644 --- a/fietsboek/templates/edit.jinja2 +++ b/fietsboek/templates/edit.jinja2 @@ -1,6 +1,6 @@ {% extends "layout.jinja2" %} -{% import "edit_form.jinja2" as edit_form %} +{% import "edit_form.jinja2" as edit_form with context %} {% import "util.jinja2" as util with context %} {% block content %} diff --git a/fietsboek/templates/edit_form.jinja2 b/fietsboek/templates/edit_form.jinja2 index 34c34c3..f7dd007 100644 --- a/fietsboek/templates/edit_form.jinja2 +++ b/fietsboek/templates/edit_form.jinja2 @@ -37,7 +37,14 @@ </div> <div class="row"> <div class="col-lg-3"> - <input type="text" id="new-tag" class="form-control"> + <input type="text" id="new-tag" class="form-control" list="user-tags"> + <datalist id="user-tags"> + {% if request.identity %} + {% for tag in request.identity.autocomplete_tags() | sort %} + <option value="{{ tag }}"> + {% endfor %} + {% endif %} + </datalist> </div> <div class="col-lg-3"> <button type="button" class="btn btn-primary" id="add-tag-btn">{{ _("page.track.form.add_tag") }}</buttton> diff --git a/fietsboek/templates/finish_upload.jinja2 b/fietsboek/templates/finish_upload.jinja2 index 0d32392..9ee4576 100644 --- a/fietsboek/templates/finish_upload.jinja2 +++ b/fietsboek/templates/finish_upload.jinja2 @@ -1,6 +1,6 @@ {% extends "layout.jinja2" %} -{% import "edit_form.jinja2" as edit_form %} +{% import "edit_form.jinja2" as edit_form with context %} {% import "util.jinja2" as util with context %} {% block content %} |