add column to EbookFile to indicate a failed make_mobi
so we don't keep trying with a bad epub filepull/91/head
parent
e1553f8121
commit
c422965bdb
|
@ -21,7 +21,7 @@ class Command(BaseCommand):
|
|||
if not work.ebooks().filter(format="mobi"):
|
||||
for ebook in work.ebooks().filter(format="epub"):
|
||||
ebf = ebook.get_archive_ebf()
|
||||
if ebf:
|
||||
if ebf and ebf.mobied >= 0:
|
||||
try:
|
||||
print u'making mobi for {}'.format(work.title)
|
||||
if ebf.make_mobi():
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0012_campaign_charitable'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='ebookfile',
|
||||
name='mobied',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
|
@ -1056,6 +1056,7 @@ class EbookFile(models.Model):
|
|||
asking = models.BooleanField(default=False)
|
||||
ebook = models.ForeignKey('Ebook', related_name='ebook_files', null=True)
|
||||
source = models.URLField(null=True, blank=True)
|
||||
mobied = models.IntegerField(default=0) #-1 indicates a failed conversion attempt
|
||||
version = None
|
||||
def check_file(self):
|
||||
if self.format == 'epub':
|
||||
|
@ -1072,9 +1073,13 @@ class EbookFile(models.Model):
|
|||
def make_mobi(self):
|
||||
if not self.format == 'epub' or not settings.MOBIGEN_URL:
|
||||
return False
|
||||
if self.mobied < 0:
|
||||
return False
|
||||
try:
|
||||
mobi_cf = ContentFile(mobi.convert_to_mobi(self.file.url))
|
||||
except:
|
||||
self.mobied = -1
|
||||
self.save()
|
||||
return False
|
||||
new_mobi_ebf = EbookFile.objects.create(
|
||||
edition=self.edition,
|
||||
|
@ -1097,6 +1102,8 @@ class EbookFile(models.Model):
|
|||
)
|
||||
new_mobi_ebf.ebook = new_ebook
|
||||
new_mobi_ebf.save()
|
||||
self.mobied = 1
|
||||
self.save()
|
||||
return True
|
||||
|
||||
send_to_kindle_limit = 7492232
|
||||
|
|
|
@ -1157,6 +1157,29 @@ class EbookFileTests(TestCase):
|
|||
self.assertTrue(c.work.ebookfiles().filter(asking=True, ebook__active=True).count() == 0)
|
||||
self.assertTrue(c.work.ebookfiles().filter(asking=False, ebook__active=True).count() > 0)
|
||||
|
||||
def test_bad_ebookfile(self):
|
||||
w = Work.objects.create(title="Work 3")
|
||||
e = Edition.objects.create(title=w.title, work=w)
|
||||
|
||||
temp = NamedTemporaryFile(delete=False)
|
||||
test_file_content = "bad text file"
|
||||
temp.write(test_file_content)
|
||||
temp.close()
|
||||
|
||||
try:
|
||||
# put the bad file into Django storage
|
||||
temp_file = open(temp.name)
|
||||
dj_file = DjangoFile(temp_file)
|
||||
ebf = EbookFile(format='epub', edition=e, file=dj_file)
|
||||
ebf.save()
|
||||
temp_file.close()
|
||||
ebf.make_mobi()
|
||||
finally:
|
||||
# make sure we get rid of temp file
|
||||
os.remove(temp.name)
|
||||
self.assertTrue(ebf.mobied < 0)
|
||||
|
||||
|
||||
class MobigenTests(TestCase):
|
||||
def test_convert_to_mobi(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue