From ba8024b667a4ca16305e3b8c6fe566ba328a488d Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Thu, 9 Oct 2014 10:49:40 +0200 Subject: Skip default tags for tag suggestions. - Fixup for issue #52 --- service/pixelated/adapter/tag_service.py | 3 +++ service/pixelated/user_agent.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'service/pixelated') diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py index 874a9a58..f128f1bb 100644 --- a/service/pixelated/adapter/tag_service.py +++ b/service/pixelated/adapter/tag_service.py @@ -59,3 +59,6 @@ class TagService: def all_tags(self): return self.tag_index.values().union(self.SPECIAL_TAGS) + + def all_custom_tags(self): + return self.tag_index.values().difference(self.SPECIAL_TAGS) diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index 12b9a97a..03372f23 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -124,12 +124,17 @@ def delete_mails(): @app.route('/tags') def tags(): + tag_service = mail_service.tag_service + query = request.args.get('q') + skipDefaultTags = request.args.get('skipDefaultTags') + + all_tags = tag_service.all_custom_tags() if skipDefaultTags else tag_service.all_tags() if query: - tags = [tag for tag in mail_service.all_tags() if bool(re.match(query, tag.name, re.IGNORECASE))] + tags = [tag for tag in all_tags if bool(re.match(query, tag.name, re.IGNORECASE))] else: - tags = mail_service.all_tags() + tags = all_tags return respond_json([tag.as_dict() for tag in tags]) -- cgit v1.2.3