summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6822e24)
epub generation fix
search fix
blog feed fix
from optparse import make_option
from django.core.management.base import BaseCommand
from optparse import make_option
from django.core.management.base import BaseCommand
make_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
make_option('-f', '--force', action='store_true', dest='force', default=False,
make_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
make_option('-f', '--force', action='store_true', dest='force', default=False,
- help='Print status messages to stdout')
+ help='Print status messages to stdout'),
+ make_option('-E', '--no-build-epub', action='store_false', dest='build_epub', default=True,
+ help='Don\'t build EPUB file'),
+ make_option('-w', '--wait-until', dest='wait_until', metavar='TIME',
+ help='Wait until specified time (Y-M-D h:m:s)'),
)
help = 'Imports books from the specified directories.'
args = 'directory [directory ...]'
)
help = 'Imports books from the specified directories.'
args = 'directory [directory ...]'
force = options.get('force')
show_traceback = options.get('traceback', False)
force = options.get('force')
show_traceback = options.get('traceback', False)
+ if options.get('wait_until'):
+ wait_until = time.mktime(time.strptime(options.get('wait_until'), '%Y-%m-%d %H:%M:%S'))
+ if verbose > 0:
+ print "Will wait until %s; it's %f seconds from now" % (
+ time.strftime('%Y-%m-%d %H:%M:%S',
+ time.localtime(wait_until)), wait_until - time.time())
+
# Start transaction management.
transaction.commit_unless_managed()
transaction.enter_transaction_management()
# Start transaction management.
transaction.commit_unless_managed()
transaction.enter_transaction_management()
- book = Book.from_xml_file(file_path, overwrite=force)
+ book = Book.from_xml_file(file_path, overwrite=force, build_epub=options.get('build_epub'))
files_imported += 1
if os.path.isfile(file_base + '.pdf'):
files_imported += 1
if os.path.isfile(file_base + '.pdf'):
files_imported, files_skipped, files_imported + files_skipped)
print
files_imported, files_skipped, files_imported + files_skipped)
print
+ if wait_until:
+ print 'Waiting...'
+ try:
+ time.sleep(wait_until - time.time())
+ except IOError:
+ print "it's already too late"
+
transaction.commit()
transaction.leave_transaction_management()
transaction.commit()
transaction.leave_transaction_management()
epub_file = StringIO()
try:
epub_file = StringIO()
try:
- epub.transform(BookImportDocProvider(self), self.slug, epub_file)
+ epub.transform(BookImportDocProvider(self), self.slug, output_file=epub_file)
self.epub_file.save('%s.epub' % self.slug, ContentFile(epub_file.getvalue()), save=False)
self.save()
FileRecord(slug=self.slug, type='epub', sha1=sha1(epub_file.getvalue()).hexdigest()).save()
self.epub_file.save('%s.epub' % self.slug, ContentFile(epub_file.getvalue()), save=False)
self.save()
FileRecord(slug=self.slug, type='epub', sha1=sha1(epub_file.getvalue()).hexdigest()).save()
- def from_xml_file(cls, xml_file, overwrite=False):
+ def from_xml_file(cls, xml_file, overwrite=False, build_epub=True):
# use librarian to parse meta-data
book_info = dcparser.parse(xml_file)
# use librarian to parse meta-data
book_info = dcparser.parse(xml_file)
xml_file = File(open(xml_file))
try:
xml_file = File(open(xml_file))
try:
- return cls.from_text_and_meta(xml_file, book_info, overwrite)
+ return cls.from_text_and_meta(xml_file, book_info, overwrite, build_epub=build_epub)
finally:
xml_file.close()
@classmethod
finally:
xml_file.close()
@classmethod
- def from_text_and_meta(cls, raw_file, book_info, overwrite=False):
+ def from_text_and_meta(cls, raw_file, book_info, overwrite=False, build_epub=True):
from tempfile import NamedTemporaryFile
from slughifi import slughifi
from markupstring import MarkupString
from tempfile import NamedTemporaryFile
from slughifi import slughifi
from markupstring import MarkupString
new_fragment.save()
new_fragment.tags = set(book_tags + themes + [book_tag] + ancestor_tags)
new_fragment.save()
new_fragment.tags = set(book_tags + themes + [book_tag] + ancestor_tags)
+ if build_epub and not book.parent:
+ print 'epub'
book.build_epub(remove_descendants=False)
book_descendants = list(book.children.all())
book.build_epub(remove_descendants=False)
book_descendants = list(book.children.all())
if isinstance(match, models.Book))
authors = set(match.name.lower() for match in result
if isinstance(match, models.Tag) and match.category=='author')
if isinstance(match, models.Book))
authors = set(match.name.lower() for match in result
if isinstance(match, models.Tag) and match.category=='author')
- result = (res for res in result if not (
+ result = tuple(res for res in result if not (
(isinstance(res, pdcounter_models.BookStub) and res.pretty_title().lower() in book_titles)
or (isinstance(res, pdcounter_models.Author) and res.name.lower() in authors)
))
(isinstance(res, pdcounter_models.BookStub) and res.pretty_title().lower() in book_titles)
or (isinstance(res, pdcounter_models.Author) and res.name.lower() in authors)
))
<div id="latest-blog-posts">
<h2>{% trans "News" %}</h2>
{% cache 1800 latest-blog-posts %}
<div id="latest-blog-posts">
<h2>{% trans "News" %}</h2>
{% cache 1800 latest-blog-posts %}
- {% latest_blog_posts "http://www.nowoczesnapolska.org.pl/tematy/wolne-lektury/feed/" %}
+ {% latest_blog_posts "http://nowoczesnapolska.org.pl/category/wolne-lektury/feed/" %}
{% endcache %}
<p class="see-more"><a href="http://www.nowoczesnapolska.org.pl/">{% trans "See our blog" %} ⇒</a></p>
</div>
{% endcache %}
<p class="see-more"><a href="http://www.nowoczesnapolska.org.pl/">{% trans "See our blog" %} ⇒</a></p>
</div>