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
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)
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')
app_label = 'catalogue'
def save(self, *args, **kwargs):
- from fnpdjango.utils.text.slughifi import slughifi
from catalogue.utils import ExistingFile, remove_zip
try:
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']
#
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
# Pickle complains about not having this.
-TagRelation = Tag.intermediary_table_model
\ No newline at end of file
+TagRelation = Tag.intermediary_table_model
@register.simple_tag
def download_audio(book, daisy=True):
links = []
- if related['media'].get('mp3'):
+ if book.has_media('mp3'):
links.append("<a href='%s'>%s</a>" %
(reverse('download_zip_mp3', args=[book.slug]),
BookMedia.formats['mp3'].name))
- if related['media'].get('ogg'):
+ if book.has_media('ogg'):
links.append("<a href='%s'>%s</a>" %
(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("<a href='%s'>%s</a>" %
(dsy.file.url, BookMedia.formats['daisy'].name))
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
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]
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]
#
from collections import OrderedDict
import re
-import itertools
from django.conf import settings
from django.core.cache import get_cache
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 = []
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',
'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,
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))))
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)
# 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'))