instantiate soup inside methods
parent
3bb738dbf3
commit
8efe0b012e
10
api/onix.py
10
api/onix.py
|
@ -17,7 +17,7 @@ feed_header = """<?xml version="1.0" encoding="UTF-8"?>
|
|||
<ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" >
|
||||
"""
|
||||
feed_xml = feed_header + '</ONIXMessage>'
|
||||
soup = BeautifulSoup('', 'lxml')
|
||||
soup = None
|
||||
bisac = Bisac()
|
||||
|
||||
def text_node(tag, text, attrib=None):
|
||||
|
@ -36,6 +36,10 @@ def sub_element(node, tag, attrib=None):
|
|||
|
||||
|
||||
def onix_feed(facet, max=None, page_number=None):
|
||||
global soup
|
||||
if not soup:
|
||||
soup = BeautifulSoup('', 'lxml')
|
||||
|
||||
yield feed_header + str(header(facet))
|
||||
works = facet.works[0:max] if max else facet.works
|
||||
|
||||
|
@ -56,6 +60,10 @@ def onix_feed(facet, max=None, page_number=None):
|
|||
yield '</ONIXMessage>'
|
||||
|
||||
def onix_feed_for_work(work):
|
||||
global soup
|
||||
if not soup:
|
||||
soup = BeautifulSoup('', 'lxml')
|
||||
|
||||
feed = BeautifulSoup(feed_xml, 'xml')
|
||||
feed.ONIXMessage.append(header(work))
|
||||
for edition in models.Edition.objects.filter(work=work, ebooks__isnull=False).distinct():
|
||||
|
|
|
@ -17,7 +17,7 @@ import regluit.core.cc as cc
|
|||
licenses = cc.LICENSE_LIST
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
soup = BeautifulSoup('', 'lxml')
|
||||
soup = None
|
||||
FORMAT_TO_MIMETYPE = {'pdf':"application/pdf",
|
||||
'epub':"application/epub+zip",
|
||||
'mobi':"application/x-mobipocket-ebook",
|
||||
|
@ -273,6 +273,9 @@ def opds_feed_for_work(work_id):
|
|||
return opds_feed_for_works(single_work_facet(work_id))
|
||||
|
||||
def opds_feed_for_works(the_facet, page=None, order_by='newest'):
|
||||
global soup
|
||||
if not soup:
|
||||
soup = BeautifulSoup('', 'lxml')
|
||||
works = the_facet.works
|
||||
feed_path = the_facet.feed_path
|
||||
title = the_facet.title
|
||||
|
|
Loading…
Reference in New Issue