diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-09-16 15:00:57 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-09-16 15:00:57 +0200 |
commit | 09783377b9d451042fa1e5607c64f4df5f17ad56 (patch) | |
tree | 590b55fd00f7273a5d0ae5902cfcc9888ece6e83 | |
parent | b7dee45781af030debdd109c2ee8ddc4acca0616 (diff) | |
download | fietsboek-09783377b9d451042fa1e5607c64f4df5f17ad56.tar.gz fietsboek-09783377b9d451042fa1e5607c64f4df5f17ad56.tar.bz2 fietsboek-09783377b9d451042fa1e5607c64f4df5f17ad56.zip |
autocomplete tags in upload/edit form
-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 %} |