35
35
from kitsune .sumo .urlresolvers import reverse
36
36
from kitsune .sumo .utils import chunked
37
37
from kitsune .tags .models import BigVocabTaggableManager , SumoTag
38
- from kitsune .tags .utils import add_existing_tag
39
38
from kitsune .upload .models import ImageAttachment
40
39
from kitsune .wiki .models import Document
41
40
@@ -276,16 +275,16 @@ def product_slug(self):
276
275
277
276
return self ._product_slug
278
277
279
- def auto_tag (self ):
280
- """Apply tags to myself that are implied by my metadata.
281
-
278
+ def handle_metadata_tags (self , action ):
279
+ """
280
+ Add or remove tags that are implied by my metadata.
282
281
You don't need to call save on the question after this.
283
-
284
282
"""
285
- to_add = []
283
+ tags = []
284
+
286
285
if product_config := self .product_config :
287
286
for tag in product_config .associated_tags .all ():
288
- to_add .append (tag )
287
+ tags .append (tag )
289
288
290
289
version = self .metadata .get ("ff_version" , "" )
291
290
@@ -299,27 +298,43 @@ def auto_tag(self):
299
298
or version in product_details .firefox_history_stability_releases
300
299
or version in product_details .firefox_history_major_releases
301
300
):
302
- to_add .append ("Firefox %s" % version )
301
+ tags .append ("Firefox %s" % version )
303
302
tenths = _tenths_version (version )
304
303
if tenths :
305
- to_add .append ("Firefox %s" % tenths )
304
+ tags .append ("Firefox %s" % tenths )
306
305
elif _has_beta (version , dev_releases ):
307
- to_add .append ("Firefox %s" % version )
308
- to_add .append ("beta" )
306
+ tags .append ("Firefox %s" % version )
307
+ tags .append ("beta" )
309
308
310
- # Add a tag for the OS if it already exists as a tag:
309
+ # Add a tag for the OS but only if it already exists as a tag.
311
310
if os := self .metadata .get ("os" ):
312
311
try :
313
- add_existing_tag ( os , self . tags )
312
+ os_tag = SumoTag . objects . get ( name__iexact = os )
314
313
except SumoTag .DoesNotExist :
315
314
pass
315
+ else :
316
+ tags .append (os_tag )
317
+
316
318
product_md = self .metadata .get ("product" )
317
319
topic_md = self .metadata .get ("category" )
318
320
if self .product and not product_md :
319
- to_add .append (self .product .slug )
321
+ tags .append (self .product .slug )
320
322
if self .topic and not topic_md :
321
- to_add .append (self .topic .slug )
322
- self .tags .add (* to_add )
323
+ tags .append (self .topic .slug )
324
+
325
+ getattr (self .tags , action )(* tags )
326
+
327
+ def auto_tag (self ):
328
+ """
329
+ Add tags that are implied by my metadata.
330
+ """
331
+ self .handle_metadata_tags ("add" )
332
+
333
+ def remove_auto_tags (self ):
334
+ """
335
+ Remove tags that are implied by my metadata.
336
+ """
337
+ self .handle_metadata_tags ("remove" )
323
338
324
339
def get_absolute_url (self ):
325
340
# Note: If this function changes, we need to change it in
0 commit comments