from django.core.cache import cache
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
-from django.core.files import File
from django.template.loader import render_to_string
from django.utils.datastructures import SortedDict
from django.utils.safestring import mark_safe
from newtagging.models import TagBase, tags_updated
from newtagging import managers
from catalogue.fields import JSONField, OverwritingFileField
-from catalogue.utils import ExistingFile, ORMDocProvider, create_zip, remove_zip
+from catalogue.utils import create_zip
-from librarian import dcparser, html, epub, NoDublinCore
-import mutagen
-from mutagen import id3
-from slughifi import slughifi
-from sortify import sortify
-from os import unlink
TAG_CATEGORIES = (
('author', _('author')),
# TODO: why is this hard-coded ?
def book_upload_path(ext=None, maxlen=100):
def get_dynamic_path(media, filename, ext=ext):
+ from slughifi import slughifi
+
# how to put related book's slug here?
if not ext:
if media.type == 'daisy':
verbose_name_plural = _('book media')
def save(self, *args, **kwargs):
+ from slughifi import slughifi
+ from catalogue.utils import ExistingFile, remove_zip
+
try:
old = BookMedia.objects.get(pk=self.pk)
except BookMedia.DoesNotExist, e:
"""
Reads some metadata from the audiobook.
"""
+ import mutagen
+ from mutagen import id3
artist_name = director_name = project = funded_by = ''
if self.type == 'mp3':
"""
Reads source file SHA1 from audiobok metadata.
"""
+ import mutagen
+ from mutagen import id3
if filetype == 'mp3':
try:
return self.title
def save(self, force_insert=False, force_update=False, reset_short_html=True, **kwargs):
+ from sortify import sortify
+
self.sort_key = sortify(self.title)
ret = super(Book, self).save(force_insert, force_update)
""" (Re)builds the pdf file.
"""
- from librarian import pdf
from tempfile import NamedTemporaryFile
- import os
+ from os import unlink
+ from django.core.files import File
+ from librarian import pdf
+ from catalogue.utils import ORMDocProvider, remove_zip
try:
pdf_file = NamedTemporaryFile(delete=False)
""" (Re)builds the MOBI file.
"""
- from librarian import mobi
from tempfile import NamedTemporaryFile
- import os
+ from os import unlink
+ from django.core.files import File
+ from librarian import mobi
+ from catalogue.utils import ORMDocProvider, remove_zip
try:
mobi_file = NamedTemporaryFile(suffix='.mobi', delete=False)
from StringIO import StringIO
from hashlib import sha1
from django.core.files.base import ContentFile
+ from librarian import epub, NoDublinCore
+ from catalogue.utils import ORMDocProvider, remove_zip
if self.parent:
# don't need an epub
def build_html(self):
from tempfile import NamedTemporaryFile
from markupstring import MarkupString
+ from django.core.files import File
+ from slughifi import slughifi
+ from librarian import html
meta_tags = list(self.tags.filter(
category__in=('author', 'epoch', 'genre', 'kind')))
@classmethod
def from_xml_file(cls, xml_file, **kwargs):
+ from django.core.files import File
+ from librarian import dcparser
+
# use librarian to parse meta-data
book_info = dcparser.parse(xml_file)
def from_text_and_meta(cls, raw_file, book_info, overwrite=False,
build_epub=True, build_txt=True, build_pdf=True, build_mobi=True):
import re
+ from slughifi import slughifi
+ from sortify import sortify
# check for parts before we do anything
children = []
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-import tempfile
-import zipfile
-import tarfile
-import sys
-import pprint
-import traceback
import re
import itertools
from datetime import datetime
from catalogue import models
from catalogue import forms
from catalogue.utils import split_tags
-from newtagging import views as newtagging_views
from pdcounter import models as pdcounter_models
from pdcounter import views as pdcounter_views
from suggest.forms import PublishingSuggestForm
-from slughifi import slughifi
staff_required = user_passes_test(lambda user: user.is_staff)
without loading the whole file into memory. A similar approach can
be used for large dynamic PDF files.
"""
+ from slughifi import slughifi
+ import tempfile
+ import zipfile
+
shelf = get_object_or_404(models.Tag, slug=slug, category='set')
formats = []
try:
book_import_form.save()
except:
+ import sys
+ import pprint
+ import traceback
info = sys.exc_info()
exception = pprint.pformat(info[1])
tb = '\n'.join(traceback.format_tb(info[2]))