X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/24a30f976686c4d183c1bd09cdae95c15a7b8dae..6e102eb7360b2c7df5a8565486e3428e6ccf2ab8:/apps/catalogue/models.py diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 00baa287e..2b6a2cc2f 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -64,6 +64,9 @@ class Tag(TagBase): gazeta_link = models.CharField(blank=True, max_length=240) wiki_link = models.CharField(blank=True, max_length=240) + class UrlDeprecationWarning(DeprecationWarning): + pass + categories_rev = { 'autor': 'author', 'epoka': 'epoch', @@ -122,19 +125,20 @@ class Tag(TagBase): real_tags = [] ambiguous_slugs = [] category = None + deprecated = False tags_splitted = tags.split('/') - for index, name in enumerate(tags_splitted): - if name in Tag.categories_rev: + for name in tags_splitted: + if category: + real_tags.append(Tag.objects.get(slug=name, category=category)) + category = None + elif name in Tag.categories_rev: category = Tag.categories_rev[name] else: - if category: - real_tags.append(Tag.objects.get(slug=name, category=category)) - category = None - else: - try: - real_tags.append(Tag.objects.exclude(category='book').get(slug=name)) - except Tag.MultipleObjectsReturned, e: - ambiguous_slugs.append(name) + try: + real_tags.append(Tag.objects.exclude(category='book').get(slug=name)) + deprecated = True + except Tag.MultipleObjectsReturned, e: + ambiguous_slugs.append(name) if category: # something strange left off @@ -145,8 +149,11 @@ class Tag(TagBase): e.tags = real_tags e.ambiguous_slugs = ambiguous_slugs raise e - else: - return real_tags + if deprecated: + e = Tag.UrlDeprecationWarning() + e.tags = real_tags + raise e + return real_tags else: return TagBase.get_tag_list(tags) @@ -168,7 +175,7 @@ def book_upload_path(ext=None, maxlen=100): name = slughifi(filename.split(".")[0]) else: name = slughifi(media.name) - return 'lektura/%s.%s' % (name[:(maxlen-len('lektura/.%s' % ext))], ext) + return 'lektura/%s.%s' % (name[:maxlen-len('lektura/.%s' % ext)-4], ext) return get_dynamic_path @@ -558,7 +565,7 @@ class Book(models.Model): tag.save() book_tags.append(tag) - book.tags = book_tags + book_shelves + book.tags = set(book_tags + book_shelves) book_tag = book.book_tag()