instantiate soup inside methods

pull/94/head
eric 2020-04-02 14:09:34 -04:00
parent 3bb738dbf3
commit 8efe0b012e
2 changed files with 13 additions and 2 deletions

View File

@ -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" > <ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" >
""" """
feed_xml = feed_header + '</ONIXMessage>' feed_xml = feed_header + '</ONIXMessage>'
soup = BeautifulSoup('', 'lxml') soup = None
bisac = Bisac() bisac = Bisac()
def text_node(tag, text, attrib=None): 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): def onix_feed(facet, max=None, page_number=None):
global soup
if not soup:
soup = BeautifulSoup('', 'lxml')
yield feed_header + str(header(facet)) yield feed_header + str(header(facet))
works = facet.works[0:max] if max else facet.works 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>' yield '</ONIXMessage>'
def onix_feed_for_work(work): def onix_feed_for_work(work):
global soup
if not soup:
soup = BeautifulSoup('', 'lxml')
feed = BeautifulSoup(feed_xml, 'xml') feed = BeautifulSoup(feed_xml, 'xml')
feed.ONIXMessage.append(header(work)) feed.ONIXMessage.append(header(work))
for edition in models.Edition.objects.filter(work=work, ebooks__isnull=False).distinct(): for edition in models.Edition.objects.filter(work=work, ebooks__isnull=False).distinct():

View File

@ -17,7 +17,7 @@ import regluit.core.cc as cc
licenses = cc.LICENSE_LIST licenses = cc.LICENSE_LIST
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
soup = BeautifulSoup('', 'lxml') soup = None
FORMAT_TO_MIMETYPE = {'pdf':"application/pdf", FORMAT_TO_MIMETYPE = {'pdf':"application/pdf",
'epub':"application/epub+zip", 'epub':"application/epub+zip",
'mobi':"application/x-mobipocket-ebook", '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)) return opds_feed_for_works(single_work_facet(work_id))
def opds_feed_for_works(the_facet, page=None, order_by='newest'): def opds_feed_for_works(the_facet, page=None, order_by='newest'):
global soup
if not soup:
soup = BeautifulSoup('', 'lxml')
works = the_facet.works works = the_facet.works
feed_path = the_facet.feed_path feed_path = the_facet.feed_path
title = the_facet.title title = the_facet.title