|
|
@ -52,6 +52,29 @@ def replace_video(content):
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
return content, videos
|
|
|
|
return content, videos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def workpage_div_content(tree, div_id, element, content):
|
|
|
|
|
|
|
|
parent_str = ".//div[@id='{}']".format( div_id.lower() )
|
|
|
|
|
|
|
|
parent = tree.find(parent_str)
|
|
|
|
|
|
|
|
if element is 'img':
|
|
|
|
|
|
|
|
lxml.SubElement(parent, 'img', attrib={'src': content})
|
|
|
|
|
|
|
|
elif element in ['p','h1','h2']:
|
|
|
|
|
|
|
|
sub = lxml.SubElement(parent, element)
|
|
|
|
|
|
|
|
sub.text = content
|
|
|
|
|
|
|
|
elif element == 'a':
|
|
|
|
|
|
|
|
sub = ET.SubElement(parent, element, attrib={'href':content})
|
|
|
|
|
|
|
|
sub.text = content
|
|
|
|
|
|
|
|
else:# element == 'span':
|
|
|
|
|
|
|
|
test_el = ET.Element('div', attrib={'id':'test', 'style':'background:yellow'})
|
|
|
|
|
|
|
|
test = ET.SubElement(parent, test_el)
|
|
|
|
|
|
|
|
# parent.append(test)
|
|
|
|
|
|
|
|
# sub = ET.SubElement(parent, element)
|
|
|
|
|
|
|
|
#sub.text = content = ' '+ div_id
|
|
|
|
|
|
|
|
# parent.append(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print parent_str, ET.tostring(parent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_workpage( work, work_key, tree): # replace text content in dict with html nodes, holding the content
|
|
|
|
def create_workpage( work, work_key, tree): # replace text content in dict with html nodes, holding the content
|
|
|
|
# pprint.pprint( work)
|
|
|
|
# pprint.pprint( work)
|
|
|
|
for key in work.keys():
|
|
|
|
for key in work.keys():
|
|
|
@ -61,59 +84,74 @@ def create_workpage( work, work_key, tree): # replace text content in dict with
|
|
|
|
div_body = tree.find(".//div[@class='body']")
|
|
|
|
div_body = tree.find(".//div[@class='body']")
|
|
|
|
div_av = tree.find(".//div[@class='av']")
|
|
|
|
div_av = tree.find(".//div[@class='av']")
|
|
|
|
|
|
|
|
|
|
|
|
if key in ['Description', 'Extra']:
|
|
|
|
if key in ['Creator', 'Date', 'Bio']:
|
|
|
|
mw_content = work[key]
|
|
|
|
workpage_div_content(tree, key, 'p', work[key])
|
|
|
|
# if re.search(gallery_exp, mw_content):
|
|
|
|
elif key == 'Title':
|
|
|
|
# # replace_gallery must replace the gallery inline
|
|
|
|
workpage_div_content(tree, key, 'h1', work[key])
|
|
|
|
# mw_content, gallery_imgs = replace_gallery(mw_content)
|
|
|
|
elif key == 'Thumbnail':
|
|
|
|
# work['Images'] = gallery_imgs
|
|
|
|
|
|
|
|
# for imgsrc in gallery_imgs:
|
|
|
|
|
|
|
|
# img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc})
|
|
|
|
|
|
|
|
# elif re.search(video_exp, mw_content):
|
|
|
|
|
|
|
|
# mw_content, videos = replace_video(mw_content)
|
|
|
|
|
|
|
|
# work['Video'] = videos
|
|
|
|
|
|
|
|
# # for video in videos:
|
|
|
|
|
|
|
|
# # iframe_el = ET.SubElement(div_av, 'iframe', attrib={'src': video, 'width':'600px', 'height':'450px'})
|
|
|
|
|
|
|
|
# # print 'VIDEO', ET.tostring(iframe_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print '--------------'
|
|
|
|
|
|
|
|
print 'mw_content', mw_content
|
|
|
|
|
|
|
|
print '--------------'
|
|
|
|
|
|
|
|
html_content = pandoc2html( mw_content if key in work.keys() else '') # convert to HTML
|
|
|
|
|
|
|
|
print 'html_content', html_content
|
|
|
|
|
|
|
|
document_el = html5lib.parse(html_content, namespaceHTMLElements=False)#ET.fromstring(html_content)
|
|
|
|
|
|
|
|
print ET.tostring(document_el)
|
|
|
|
|
|
|
|
print 'document_el', document_el, ET.iselement(document_el)
|
|
|
|
|
|
|
|
all_el = document_el.findall('body//')
|
|
|
|
|
|
|
|
if all_el:
|
|
|
|
|
|
|
|
all_el.reverse()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for el in all_el:
|
|
|
|
|
|
|
|
print 'el', ET.tostring(el)
|
|
|
|
|
|
|
|
div_body.append(el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imgs = document_el.findall('.//img')
|
|
|
|
|
|
|
|
# if imgs:
|
|
|
|
|
|
|
|
# for img in imgs:
|
|
|
|
|
|
|
|
# src = api_file_url(img.get('src'))
|
|
|
|
|
|
|
|
# img.set('src', src)
|
|
|
|
|
|
|
|
# print 'IMG', img, src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif key in ['Thumbnail']:
|
|
|
|
|
|
|
|
thumb = api_file_url(work[key])
|
|
|
|
thumb = api_file_url(work[key])
|
|
|
|
img_el = ET.SubElement(div_av, 'img', attrib={'src': thumb})
|
|
|
|
workpage_div_content(tree, key, 'img', thumb)
|
|
|
|
|
|
|
|
elif key == 'Website':
|
|
|
|
elif key in ['Website']:
|
|
|
|
workpage_div_content(tree, key, 'a', work[key])
|
|
|
|
work_el = ET.SubElement(div_header, 'a', attrib={'href': work[key], 'id':key})
|
|
|
|
elif key in ['Description', 'Extra']:
|
|
|
|
work_el.text = work[key]
|
|
|
|
test_el = ET.Element('div', attrib={'id':'test', 'style':'background:yellow'})
|
|
|
|
elif key in ['Title']:
|
|
|
|
workpage_div_content(tree, key, test_el, '')
|
|
|
|
work_el = ET.SubElement(div_header, 'h1', attrib={'id': key})
|
|
|
|
|
|
|
|
work_el.text = (work[key]).replace('_', ' ')
|
|
|
|
# HOW TO INSERT EXISTING HTML CHUNCK INTO TEMPLATE ???
|
|
|
|
|
|
|
|
|
|
|
|
elif key in ['Creator', 'Date', 'Bio']:
|
|
|
|
|
|
|
|
work_el =ET.SubElement(div_header, 'p', attrib={'id': key})
|
|
|
|
|
|
|
|
work_el.text = work[key]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# test_sub = ET.SubElement(test_el, 'span')
|
|
|
|
|
|
|
|
# test_sub.text = content
|
|
|
|
|
|
|
|
# sub = ET.SubElement(parent, test_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# mw_content = work[key]
|
|
|
|
|
|
|
|
# # if re.search(gallery_exp, mw_content):
|
|
|
|
|
|
|
|
# # # replace_gallery must replace the gallery inline
|
|
|
|
|
|
|
|
# # mw_content, gallery_imgs = replace_gallery(mw_content)
|
|
|
|
|
|
|
|
# # work['Images'] = gallery_imgs
|
|
|
|
|
|
|
|
# # for imgsrc in gallery_imgs:
|
|
|
|
|
|
|
|
# # img_el = ET.SubElement(div_av, 'img', attrib={'src': imgsrc})
|
|
|
|
|
|
|
|
# # elif re.search(video_exp, mw_content):
|
|
|
|
|
|
|
|
# # mw_content, videos = replace_video(mw_content)
|
|
|
|
|
|
|
|
# # work['Video'] = videos
|
|
|
|
|
|
|
|
# # # for video in videos:
|
|
|
|
|
|
|
|
# # # iframe_el = ET.SubElement(div_av, 'iframe', attrib={'src': video, 'width':'600px', 'height':'450px'})
|
|
|
|
|
|
|
|
# # # print 'VIDEO', ET.tostring(iframe_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print '--------------'
|
|
|
|
|
|
|
|
# print 'mw_content', mw_content
|
|
|
|
|
|
|
|
# print '--------------'
|
|
|
|
|
|
|
|
# html_content = pandoc2html( mw_content if key in work.keys() else '') # convert to HTML
|
|
|
|
|
|
|
|
# print 'html_content', html_content
|
|
|
|
|
|
|
|
# document_el = html5lib.parse(html_content, namespaceHTMLElements=False)#ET.fromstring(html_content)
|
|
|
|
|
|
|
|
# print ET.tostring(document_el)
|
|
|
|
|
|
|
|
# print 'document_el', document_el, ET.iselement(document_el)
|
|
|
|
|
|
|
|
# all_el = document_el.findall('body//')
|
|
|
|
|
|
|
|
# if all_el:
|
|
|
|
|
|
|
|
# all_el.reverse()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# for el in all_el:
|
|
|
|
|
|
|
|
# print 'el', ET.tostring(el)
|
|
|
|
|
|
|
|
# div_body.append(el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# imgs = document_el.findall('.//img')
|
|
|
|
|
|
|
|
# # if imgs:
|
|
|
|
|
|
|
|
# # for img in imgs:
|
|
|
|
|
|
|
|
# # src = api_file_url(img.get('src'))
|
|
|
|
|
|
|
|
# # img.set('src', src)
|
|
|
|
|
|
|
|
# # print 'IMG', img, src
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|