From 09783377b9d451042fa1e5607c64f4df5f17ad56 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 16 Sep 2022 15:00:57 +0200 Subject: autocomplete tags in upload/edit form --- fietsboek/models/user.py | 10 ++++++++++ fietsboek/templates/edit.jinja2 | 2 +- fietsboek/templates/edit_form.jinja2 | 9 ++++++++- 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 @@
- + + + {% if request.identity %} + {% for tag in request.identity.autocomplete_tags() | sort %} +