add license page to epub before sending it for watermarking
parent
3f63ef336f
commit
ed341884ea
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
Utilities that manipulate epub files
|
||||
"""
|
||||
|
||||
from pyepub import EPUB
|
||||
from StringIO import StringIO
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
def personalize(epub_file, acq):
|
||||
output = EPUB(epub_file, "a")
|
||||
context={'acq':acq}
|
||||
part = StringIO(str(render_to_string('epub/datedcc_license.xhtml', context)))
|
||||
output.addpart(part, "datedcc_license.xhtml", "application/xhtml+xml", 1) #after title, we hope
|
||||
output.close()
|
||||
output.writetodisk('testfile2.epub')
|
||||
return output
|
|
@ -31,6 +31,7 @@ regluit imports
|
|||
'''
|
||||
import regluit
|
||||
import regluit.core.isbn
|
||||
from regluit.core.epub import personalize
|
||||
|
||||
from regluit.core.signals import (
|
||||
successful_campaign,
|
||||
|
@ -294,7 +295,16 @@ class Acq(models.Model):
|
|||
'kf8mobi': True,
|
||||
'epub': True,
|
||||
}
|
||||
self.watermarked = watermarker.platform(epubfile= self.work.ebookfiles()[0].file, **params)
|
||||
personalized = personalize(self.work.ebookfiles()[0].file, self)
|
||||
print personalized.mode
|
||||
print personalized.info['spine']
|
||||
print personalized.filename.__class__.__name__
|
||||
personalized.filename.seek(0)
|
||||
f=open('testfile.epub','w')
|
||||
f.write(personalized.filename.read())
|
||||
f.close()
|
||||
personalized.filename.seek(0)
|
||||
self.watermarked = watermarker.platform(epubfile= personalized.filename, **params)
|
||||
self.save()
|
||||
return self.watermarked
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ from regluit.frontend.views import safe_get_work
|
|||
from regluit.payment.models import Transaction
|
||||
from regluit.payment.parameters import PAYMENT_TYPE_AUTHORIZATION
|
||||
from regluit.utils.localdatetime import now, date_today
|
||||
from regluit.pyepub import EPUB
|
||||
|
||||
class BookLoaderTests(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -850,12 +851,16 @@ class EbookFileTests(TestCase):
|
|||
# make sure we get rid of temp file
|
||||
os.remove(temp.name)
|
||||
|
||||
test_epub= EPUB(ebf.file, mode='a')
|
||||
self.assertEqual(len(test_epub.opf) , 4)
|
||||
self.assertTrue(len(test_epub.opf[2]) < 30)
|
||||
|
||||
acq=Acq.objects.create(user=u,work=w,license=TESTING)
|
||||
self.assertIsNot(acq.nonce, None)
|
||||
|
||||
url= acq.get_watermarked().download_link_epub
|
||||
self.assertRegexpMatches(url,'download.booxtream.com/')
|
||||
print url
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>License Information</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="booksection">
|
||||
<p> </p>
|
||||
<p class="copyk">After {{ acq.work.last_campaign.cc_date }}, this book is licensed under a {{ acq.work.last_campaign.license }}, details available at</p>
|
||||
<p class="Pub"><a href="{{ acq.work.last_campaign.license_url }}">{{ acq.work.last_campaign.license_url }}</a></p>
|
||||
<p class="copy"><img class="fig1" src="images/cc_by_sa.png" alt="images"/></p>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue