def draw_table(self, table, table_num=None): style = 'tt %s %s' % ( table.attrib.get('style', self.defaults['table_style']), table.attrib.get('align', self.defaults['table_align'])) cellpadding = '3' cellspacing = '0' htmltable = E.TABLE(cellpadding=cellpadding, ) htmltable.attrib['cellspacing'] = cellspacing htmltable.attrib['class'] = style # Add caption, if it exists if 'title' in table.attrib and table.attrib['title']: caption = '' if table_num and self.pis['tablecount'] == 'yes': caption = 'Table ' + str(table_num) + ': ' htmltable.append(E.CAPTION(caption + table.attrib['title'])) # Draw headers header_row = E.TR() col_aligns = [] for header in table.findall('ttcol'): th = E.TH() if header.text: th.text = header.text header_align = header.attrib.get('align', self.defaults['ttcol_align']) th.attrib['class'] = header_align # Store alignment information col_aligns.append(header_align) header_row.append(th) htmltable.append(E.THEAD(header_row)) # Draw body body = E.TBODY() tr = E.TR() num_columns = len(col_aligns) for i, cell in enumerate(table.findall('c')): col_num = i % num_columns if col_num == 0 and i != 0: # New row body.append(tr) tr = E.TR() td = E.TD() if cell.text: # Add text td.text = cell.text for child in cell: # Add any inline elements (references) for element in self._expand_ref(child): td.append(element) # Get alignment from header td.attrib['class'] = col_aligns[col_num] tr.append(td) body.append(tr) # Add final row htmltable.append(body) # Add to body buffer self.buf.append(self._serialize(htmltable))
def html_page_return(board, thread, default_style): html = E.HTML( E.HEAD( E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}), E.TITLE("/"+board+"/ - №"+str(thread)), #title E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js *initiate.style_cache ), E.BODY( E.P(E.CLASS("board"), board, id = 'board'), E.P(E.CLASS("thread"), str(thread), id = 'thread'), E.TABLE( E.CLASS("maintable"), E.THEAD(E.TR(E.TD( E.TABLE(E.TR(E.TD(E.CLASS('left'), copy.copy(initiate.board_cache_navigation)), E.TD(E.CLASS('right'), utilfunctions.generate_right_up_corner_menu()), ), id='headblock'), E.HR(E.CLASS("delimeter")), )), id = 'header'), E.TBODY(E.TR(E.TD( E.H2(E.CLASS("boardname"), E.A('/' + board + '/ - '+ initiate.board_cache[board].name, href = '/' + board), ), E.HR(E.CLASS("delimeter")), initiate.board_cache[board].post_form, #need to make it depending on post_form_type E.SCRIPT('function open_form() {document.getElementById("postform").style.display = "block"; document.getElementById("closeform").style.display = "block"; document.getElementById("threadcreate").style.display = "none";}'), E.SCRIPT('function close_form() {document.getElementById("postform").style.display = "none"; document.getElementById("closeform").style.display = "none"; document.getElementById("threadcreate").style.display = "block";}'), E.H3(E.A('Ответить в тред', href = "javascript:open_form();"), id = 'threadcreate'), E.H4(E.A('Скрыть форму', href = "javascript:close_form();"), id = 'closeform'), E.HR(E.CLASS("delimeter")), EM('main', '', id = 'mainframe'), E.DIV('', id = 'optionsdiv'), )), id = 'mainpart'), E.TFOOT(E.TR(E.TD( E.DIV( E.HR(E.CLASS("delimeter"), id = 'end') ), initiate.board_cache_navigation, E.DIV('powered by ', E.A('Farlight Imageboard Engine', href='https://github.com/Alpherie/farlight_board_engine', target='_blank', ), id='credentials'), )), id = 'footer'),#we make it a footer ), onload = 'threadfunc()' ) ) return lxml.html.tostring(html)
def main_page_gen(default_style): html = E.HTML( E.HEAD( E.META(**{'http-equiv':"Default-Style", 'content':default_style, 'id':'stylemetatag'}), E.TITLE("U2ch - Main Page"), E.SCRIPT(type = 'text/javascript', src = '/mainscript.js'), #js *initiate.style_cache ), E.BODY( E.UL(initiate.stats_cache, style = "display: none;", id = "mblstatscache"), E.TABLE( E.CLASS("maintable"), E.THEAD(E.TR(E.TD(E.DIV(E.CLASS("mainslogandiv"), E.SPAN("U2CH"), E.SPAN("", style="display: inline-block; width: 5em;"), E.SPAN("Viewing above imageboards"), ), E.DIV(E.CLASS("mainimagediv"), E.IMG(src="u-2.jpg", style="width:496px;height:334px;"), ), )), id = 'header'), E.TBODY(E.TR(E.TD( E.HR(E.CLASS("delimeter")), E.DIV(E.CLASS("mblcontainer"), E.DIV(E.CLASS("mblcentering"), initiate.board_cache_main_page, ), ), E.HR(E.CLASS("delimeter")), )), id = 'mainpart'), E.TFOOT(E.TR(E.TD( E.DIV('powered by ', E.A('Farlight Imageboard Engine', href='https://github.com/Alpherie/farlight_board_engine', target='_blank', ), id='credentials'), )), id = 'footer'), ), onload = 'mainpagefunc()' ) ) return lxml.html.tostring(html)