regluit/core/epub.py

28 lines
1.0 KiB
Python
Raw Normal View History

"""
Utilities that manipulate epub files
"""
2013-09-21 00:59:40 +00:00
from regluit.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(unicode(render_to_string('epub/datedcc_license.xhtml', context)))
output.addpart(part, "datedcc_license.xhtml", "application/xhtml+xml", 1) #after title, we hope
2013-09-20 21:44:37 +00:00
output.addmetadata('rights','%s after %s'%(acq.work.last_campaign().license_url,acq.work.last_campaign().cc_date))
output.close()
2013-09-20 21:45:28 +00:00
#output.writetodisk('testfile2.epub')
return output
def ungluify(epub_file, campaign):
output = EPUB(epub_file, "a")
context={'campaign':campaign}
part = StringIO(unicode(render_to_string('epub/cc_license.xhtml', context)))
output.addpart(part, "cc_license.xhtml", "application/xhtml+xml", 1) #after title, we hope
output.addmetadata('rights', campaign.license_url)
output.close()
#output.writetodisk('testfile3.epub')
return output