From 5b9ee3437b7fa98820eba7286abd524c3ede76e9 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 10 Sep 2014 11:35:49 +0200 Subject: [PATCH] Some cleaning. --- apps/catalogue/models/book.py | 6 ++---- apps/catalogue/models/bookmedia.py | 1 - apps/catalogue/models/listeners.py | 4 +--- apps/catalogue/models/tag.py | 5 ++--- apps/catalogue/templatetags/catalogue_tags.py | 6 +++--- apps/catalogue/utils.py | 5 ++--- apps/catalogue/views.py | 5 +---- apps/lesmianator/models.py | 2 +- apps/newtagging/models.py | 4 ++-- apps/picture/models.py | 2 +- 10 files changed, 15 insertions(+), 25 deletions(-) diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index 37d9b71b2..e499afc7b 100644 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -18,7 +18,7 @@ from fnpdjango.storage import BofhFileSystemStorage from catalogue import constants from catalogue.fields import EbookField from catalogue.models import Tag, Fragment, BookMedia -from catalogue.utils import create_zip, split_tags +from catalogue.utils import create_zip from catalogue import app_settings from catalogue import tasks from newtagging import managers @@ -64,7 +64,7 @@ class Book(models.Model): upload_to=_cover_upload_to, storage=bofh_storage, max_length=255) # Cleaner version of cover for thumbs - cover_thumb = EbookField('cover_thumb', _('cover thumbnail'), + cover_thumb = EbookField('cover_thumb', _('cover thumbnail'), null=True, blank=True, upload_to=_cover_thumb_upload_to, max_length=255) @@ -166,8 +166,6 @@ class Book(models.Model): author = u'' type(self).objects.filter(pk=self.pk).update(sort_key_author=author) - - def has_description(self): return len(self.description) > 0 has_description.short_description = _('description') diff --git a/apps/catalogue/models/bookmedia.py b/apps/catalogue/models/bookmedia.py index 607f4cd92..1ef3fd7b9 100644 --- a/apps/catalogue/models/bookmedia.py +++ b/apps/catalogue/models/bookmedia.py @@ -46,7 +46,6 @@ class BookMedia(models.Model): app_label = 'catalogue' def save(self, *args, **kwargs): - from fnpdjango.utils.text.slughifi import slughifi from catalogue.utils import ExistingFile, remove_zip try: diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index 031c4f13c..d414eb27f 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -6,10 +6,8 @@ from django.conf import settings from django.core.cache import caches from django.db.models.signals import post_save, pre_delete, post_delete import django.dispatch -from catalogue.models import Tag, BookMedia, Book, Fragment, Collection -from catalogue import tasks +from catalogue.models import BookMedia, Book, Collection from catalogue.utils import delete_from_cache_by_language -from newtagging.models import tags_updated permanent_cache = caches['permanent'] diff --git a/apps/catalogue/models/tag.py b/apps/catalogue/models/tag.py index bff993248..fb2511891 100644 --- a/apps/catalogue/models/tag.py +++ b/apps/catalogue/models/tag.py @@ -4,10 +4,9 @@ # from django.conf import settings from django.contrib.auth.models import User -from django.core.exceptions import ValidationError from django.db import models from django.db.models import permalink -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _ from newtagging.models import TagBase @@ -172,4 +171,4 @@ class Tag(TagBase): # Pickle complains about not having this. -TagRelation = Tag.intermediary_table_model \ No newline at end of file +TagRelation = Tag.intermediary_table_model diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 515c1fe97..2edae9b21 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -434,15 +434,15 @@ def tag_url(category, slug): @register.simple_tag def download_audio(book, daisy=True): links = [] - if related['media'].get('mp3'): + if book.has_media('mp3'): links.append("%s" % (reverse('download_zip_mp3', args=[book.slug]), BookMedia.formats['mp3'].name)) - if related['media'].get('ogg'): + if book.has_media('ogg'): links.append("%s" % (reverse('download_zip_ogg', args=[book.slug]), BookMedia.formats['ogg'].name)) - if daisy and related['media'].get('daisy'): + if daisy and book.has_media('daisy'): for dsy in book.get_media('daisy'): links.append("%s" % (dsy.file.url, BookMedia.formats['daisy'].name)) diff --git a/apps/catalogue/utils.py b/apps/catalogue/utils.py index df7e438e4..91e782efe 100644 --- a/apps/catalogue/utils.py +++ b/apps/catalogue/utils.py @@ -14,7 +14,6 @@ from django.http import HttpResponse from django.core.files.uploadedfile import UploadedFile from django.core.files.storage import DefaultStorage from django.utils.encoding import force_unicode -from django.utils.translation import get_language from django.conf import settings from os import mkdir, path, unlink from errno import EEXIST, ENOENT @@ -155,7 +154,7 @@ class MultiQuerySet(object): def __getitem__(self, item): try: - indices = (offset, stop, step) = item.indices(self.count()) + (offset, stop, step) = item.indices(self.count()) except AttributeError: # it's not a slice - make it one return self[item : item + 1][0] @@ -185,7 +184,7 @@ class SortedMultiQuerySet(MultiQuerySet): def __getitem__(self, item): sort_heads = [0] * len(self.querysets) try: - indices = (offset, stop, step) = item.indices(self.count()) + (offset, stop, step) = item.indices(self.count()) except AttributeError: # it's not a slice - make it one return self[item : item + 1][0] diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 76aaddf16..f47329a97 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -4,7 +4,6 @@ # from collections import OrderedDict import re -import itertools from django.conf import settings from django.core.cache import get_cache @@ -190,7 +189,7 @@ def tagged_object_list(request, tags=''): only_my_shelf = only_shelf and request.user.is_authenticated() and request.user == tags[0].user - objects = only_author = None + objects = None categories = {} object_queries = [] @@ -240,7 +239,6 @@ def tagged_object_list(request, tags=''): if not objects: - only_author = len(tags) == 1 and tags[0].category == 'author' objects = models.Book.objects.none() return render_to_response('catalogue/tagged_object_list.html', @@ -248,7 +246,6 @@ def tagged_object_list(request, tags=''): 'object_list': objects, 'categories': categories, 'only_shelf': only_shelf, - #~ 'only_author': only_author, 'only_my_shelf': only_my_shelf, 'formats_form': forms.DownloadFormatsForm(), 'tags': tags, diff --git a/apps/lesmianator/models.py b/apps/lesmianator/models.py index 1f558e916..5db02c2ae 100644 --- a/apps/lesmianator/models.py +++ b/apps/lesmianator/models.py @@ -168,7 +168,7 @@ class Continuations(models.Model): elif isinstance(sth, Tag): conts = cls.for_set(sth) else: - raise NotImplemented('Lesmianator continuations: only Book and Tag supported') + raise NotImplementedError('Lesmianator continuations: only Book and Tag supported') c, created = cls.objects.get_or_create(content_type=object_type, object_id=sth.id) c.pickle.save(sth.slug+'.p', ContentFile(cPickle.dumps((should_keys, conts)))) diff --git a/apps/newtagging/models.py b/apps/newtagging/models.py index 7e9936f30..ead442f31 100644 --- a/apps/newtagging/models.py +++ b/apps/newtagging/models.py @@ -228,8 +228,8 @@ def create_intermediary_table_model(model): class TagMeta(ModelBase): "Metaclass for tag models (models inheriting from TagBase)." - def __new__(cls, name, bases, attrs): - model = super(TagMeta, cls).__new__(cls, name, bases, attrs) + def __new__(mcs, name, bases, attrs): + model = super(TagMeta, mcs).__new__(mcs, name, bases, attrs) if not model._meta.abstract: # Create an intermediary table and register custom managers for concrete models model.intermediary_table_model = create_intermediary_table_model(model) diff --git a/apps/picture/models.py b/apps/picture/models.py index 75ea4c37d..5fc37228f 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -380,5 +380,5 @@ class Picture(models.Model): # copied from book.py, figure out def related_themes(self): - return catalogue.models.Tag.usage_for_queryset( + return catalogue.models.Tag.objects.usage_for_queryset( self.areas.all(), counts=True).filter(category__in=('theme', 'thing')) -- 2.20.1