Failure: we'll start a new a approach from now onwards

master
Castro0o 9 years ago
parent 795a19f950
commit 5405d9861f

@ -52,6 +52,29 @@ def replace_video(content):
content = re.sub(video_exp, '', content)
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
# pprint.pprint( work)
for key in work.keys():
@ -60,60 +83,75 @@ def create_workpage( work, work_key, tree): # replace text content in dict with
div_header = tree.find(".//div[@class='header']")
div_body = tree.find(".//div[@class='body']")
div_av = tree.find(".//div[@class='av']")
if key in ['Description', 'Extra']:
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)
if key in ['Creator', 'Date', 'Bio']:
workpage_div_content(tree, key, 'p', work[key])
elif key == 'Title':
workpage_div_content(tree, key, 'h1', work[key])
elif key == 'Thumbnail':
thumb = api_file_url(work[key])
workpage_div_content(tree, key, 'img', thumb)
elif key == 'Website':
workpage_div_content(tree, key, 'a', work[key])
elif key in ['Description', 'Extra']:
test_el = ET.Element('div', attrib={'id':'test', 'style':'background:yellow'})
workpage_div_content(tree, key, test_el, '')
# HOW TO INSERT EXISTING HTML CHUNCK INTO TEMPLATE ???
# 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
# 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])
img_el = ET.SubElement(div_av, 'img', attrib={'src': thumb})
elif key in ['Website']:
work_el = ET.SubElement(div_header, 'a', attrib={'href': work[key], 'id':key})
work_el.text = work[key]
elif key in ['Title']:
work_el = ET.SubElement(div_header, 'h1', attrib={'id': key})
work_el.text = (work[key]).replace('_', ' ')
elif key in ['Creator', 'Date', 'Bio']:
work_el =ET.SubElement(div_header, 'p', attrib={'id': key})
work_el.text = work[key]

@ -6,10 +6,19 @@
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="work">
<div class="header"></div><!--title, Creator, Date, Bio will go here -->
<div class="body"></div> <!-- Description, Extra will go here -->
<div class="av"></div> <!-- AV material (Thumbanail, gallery, video )will go here-->
<div id="header">
<div id="title"></div>
<div id="creator"></div>
<div id="date"></div>
<div id="website"></div>
<div id="thumbnail"></div>
<div id="bio"></div>
</div>
<div id="body">
<div id="description"></div>
<div id="extra"></div>
</div> <!-- Description, Extra will go here -->
</body>
</html>

Loading…
Cancel
Save