X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1c07de888eadc1333264d627ffdff1066a5f01b9..6e102eb7360b2c7df5a8565486e3428e6ccf2ab8:/apps/catalogue/models.py?ds=inline diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index b78b5939b..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) @@ -160,12 +167,15 @@ def book_upload_path(ext=None, maxlen=100): def get_dynamic_path(media, filename, ext=ext): # how to put related book's slug here? if not ext: - ext = media.type + if media.type == 'daisy': + ext = 'daisy.zip' + else: + ext = media.type if not media.name: 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 @@ -555,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()