fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
b348f49
)
rearrange imports
author
Radek Czajka
<radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 18 Nov 2011 11:45:01 +0000
(12:45 +0100)
committer
Radek Czajka
<radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 18 Nov 2011 11:45:01 +0000
(12:45 +0100)
apps/catalogue/forms.py
patch
|
blob
|
history
apps/catalogue/models.py
patch
|
blob
|
history
apps/catalogue/views.py
patch
|
blob
|
history
apps/reporting/utils.py
patch
|
blob
|
history
apps/reporting/views.py
patch
|
blob
|
history
diff --git
a/apps/catalogue/forms.py
b/apps/catalogue/forms.py
index
04969c2
..
391e3e4
100644
(file)
--- a/
apps/catalogue/forms.py
+++ b/
apps/catalogue/forms.py
@@
-3,7
+3,6
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import forms
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django import forms
-from django.core.files.base import ContentFile
from django.utils.translation import ugettext_lazy as _
from slughifi import slughifi
from django.utils.translation import ugettext_lazy as _
from slughifi import slughifi
@@
-17,6
+16,8
@@
class BookImportForm(forms.Form):
book_xml = forms.CharField(required=False)
def clean(self):
book_xml = forms.CharField(required=False)
def clean(self):
+ from django.core.files.base import ContentFile
+
if not self.cleaned_data['book_xml_file']:
if self.cleaned_data['book_xml']:
self.cleaned_data['book_xml_file'] = \
if not self.cleaned_data['book_xml_file']:
if self.cleaned_data['book_xml']:
self.cleaned_data['book_xml_file'] = \
diff --git
a/apps/catalogue/models.py
b/apps/catalogue/models.py
index
bb20774
..
22ed325
100644
(file)
--- a/
apps/catalogue/models.py
+++ b/
apps/catalogue/models.py
@@
-10,7
+10,6
@@
import django.dispatch
from django.core.cache import cache
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
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 django.template.loader import render_to_string
from django.utils.datastructures import SortedDict
from django.utils.safestring import mark_safe
@@
-23,14
+22,8
@@
from django.conf import settings
from newtagging.models import TagBase, tags_updated
from newtagging import managers
from catalogue.fields import JSONField, OverwritingFileField
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, remov
e_zip
+from catalogue.utils import
creat
e_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')),
TAG_CATEGORIES = (
('author', _('author')),
@@
-180,6
+173,8
@@
class Tag(TagBase):
# TODO: why is this hard-coded ?
def book_upload_path(ext=None, maxlen=100):
def get_dynamic_path(media, filename, ext=ext):
# 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':
# how to put related book's slug here?
if not ext:
if media.type == 'daisy':
@@
-212,6
+207,9
@@
class BookMedia(models.Model):
verbose_name_plural = _('book media')
def save(self, *args, **kwargs):
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:
try:
old = BookMedia.objects.get(pk=self.pk)
except BookMedia.DoesNotExist, e:
@@
-236,6
+234,8
@@
class BookMedia(models.Model):
"""
Reads some metadata from the audiobook.
"""
"""
Reads some metadata from the audiobook.
"""
+ import mutagen
+ from mutagen import id3
artist_name = director_name = project = funded_by = ''
if self.type == 'mp3':
artist_name = director_name = project = funded_by = ''
if self.type == 'mp3':
@@
-268,6
+268,8
@@
class BookMedia(models.Model):
"""
Reads source file SHA1 from audiobok metadata.
"""
"""
Reads source file SHA1 from audiobok metadata.
"""
+ import mutagen
+ from mutagen import id3
if filetype == 'mp3':
try:
if filetype == 'mp3':
try:
@@
-321,6
+323,8
@@
class Book(models.Model):
return self.title
def save(self, force_insert=False, force_update=False, reset_short_html=True, **kwargs):
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)
self.sort_key = sortify(self.title)
ret = super(Book, self).save(force_insert, force_update)
@@
-465,9
+469,11
@@
class Book(models.Model):
""" (Re)builds the pdf file.
"""
""" (Re)builds the pdf file.
"""
- from librarian import pdf
from tempfile import NamedTemporaryFile
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)
try:
pdf_file = NamedTemporaryFile(delete=False)
@@
-487,9
+493,11
@@
class Book(models.Model):
""" (Re)builds the MOBI file.
"""
""" (Re)builds the MOBI file.
"""
- from librarian import mobi
from tempfile import NamedTemporaryFile
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)
try:
mobi_file = NamedTemporaryFile(suffix='.mobi', delete=False)
@@
-513,6
+521,8
@@
class Book(models.Model):
from StringIO import StringIO
from hashlib import sha1
from django.core.files.base import ContentFile
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
if self.parent:
# don't need an epub
@@
-551,6
+561,9
@@
class Book(models.Model):
def build_html(self):
from tempfile import NamedTemporaryFile
from markupstring import MarkupString
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')))
meta_tags = list(self.tags.filter(
category__in=('author', 'epoch', 'genre', 'kind')))
@@
-627,6
+640,9
@@
class Book(models.Model):
@classmethod
def from_xml_file(cls, xml_file, **kwargs):
@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)
# use librarian to parse meta-data
book_info = dcparser.parse(xml_file)
@@
-642,6
+658,8
@@
class Book(models.Model):
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
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 = []
# check for parts before we do anything
children = []
diff --git
a/apps/catalogue/views.py
b/apps/catalogue/views.py
index
5f0b016
..
c808534
100644
(file)
--- a/
apps/catalogue/views.py
+++ b/
apps/catalogue/views.py
@@
-2,12
+2,6
@@
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
# 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
import re
import itertools
from datetime import datetime
@@
-35,11
+29,9
@@
from django.views.generic.list_detail import object_list
from catalogue import models
from catalogue import forms
from catalogue.utils import split_tags
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 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)
staff_required = user_passes_test(lambda user: user.is_staff)
@@
-573,6
+565,10
@@
def download_shelf(request, slug):
without loading the whole file into memory. A similar approach can
be used for large dynamic PDF files.
"""
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 = []
shelf = get_object_or_404(models.Tag, slug=slug, category='set')
formats = []
@@
-721,6
+717,9
@@
def import_book(request):
try:
book_import_form.save()
except:
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]))
info = sys.exc_info()
exception = pprint.pformat(info[1])
tb = '\n'.join(traceback.format_tb(info[2]))
diff --git
a/apps/reporting/utils.py
b/apps/reporting/utils.py
index
8a7a6cf
..
0f04995
100755
(executable)
--- a/
apps/reporting/utils.py
+++ b/
apps/reporting/utils.py
@@
-4,14
+4,9
@@
#
import os
import os.path
#
import os
import os.path
-import shutil
-import subprocess
-from tempfile import mkdtemp
-from StringIO import StringIO
from django.conf import settings
import logging
from django.http import HttpResponse
from django.conf import settings
import logging
from django.http import HttpResponse
-from django.template.loader import render_to_string
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
@@
-25,7
+20,13
@@
def render_to_pdf(output_path, template, context=None, add_files=None):
:param dict add_files: a dictionary of additional files XeTeX will need
"""
:param dict add_files: a dictionary of additional files XeTeX will need
"""
+ from StringIO import StringIO
+ import shutil
+ from tempfile import mkdtemp
+ import subprocess
import Texml.processor
import Texml.processor
+ from django.template.loader import render_to_string
+
rendered = render_to_string(template, context)
texml = StringIO(rendered.encode('utf-8'))
tempdir = mkdtemp(prefix = "render_to_pdf-")
rendered = render_to_string(template, context)
texml = StringIO(rendered.encode('utf-8'))
tempdir = mkdtemp(prefix = "render_to_pdf-")
diff --git
a/apps/reporting/views.py
b/apps/reporting/views.py
index
0203863
..
958e080
100644
(file)
--- a/
apps/reporting/views.py
+++ b/
apps/reporting/views.py
@@
-37,7
+37,6
@@
def stats_page(request):
signals=[Book.published])
def catalogue_pdf(path):
books_by_author, orphans, books_by_parent = Book.book_list()
signals=[Book.published])
def catalogue_pdf(path):
books_by_author, orphans, books_by_parent = Book.book_list()
- print books_by_parent
render_to_pdf(path, 'reporting/catalogue.texml', locals(), {
"wl-logo.png": os.path.join(settings.STATIC_ROOT, "img/logo-big.png"),
})
render_to_pdf(path, 'reporting/catalogue.texml', locals(), {
"wl-logo.png": os.path.join(settings.STATIC_ROOT, "img/logo-big.png"),
})