From f1d17350a7275e5d22f9bbcb65dd3b6010f3b874 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 14 Sep 2020 05:38:20 -0700 Subject: [PATCH] Add Photo.remove_tags. --- etiquette/objects.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/etiquette/objects.py b/etiquette/objects.py index 0ef0436..f7ddae1 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -1034,6 +1034,24 @@ class Photo(ObjectBase): } self.photodb.sql_update(table='photos', pairs=data, where_key='id') + @decorators.required_feature('photo.add_remove_tag') + @decorators.transaction + def remove_tags(self, tags): + tags = [self.photodb.get_tag(name=tag) for tag in tags] + + self.photodb.log.debug('Removing %s from %s', tags, self) + query = f''' + DELETE FROM photo_tag_rel + WHERE tagid IN {sqlhelpers.listify(tag.id for tag in tags)} + ''' + self.photodb.sql_execute(query) + + data = { + 'id': self.id, + 'tagged_at': helpers.now(), + } + self.photodb.sql_update(table='photos', pairs=data, where_key='id') + @decorators.required_feature('photo.edit') @decorators.transaction def rename_file(self, new_filename, *, move=False):