示例#1
0
 def setUp(self):
     super(TestViewSaving, self).setUp()
     self.arch = h.DIV(
         h.DIV(h.H3("Column 1"),
               h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
         h.DIV(
             h.H3("Column 2"),
             h.UL(
                 h.LI("Item 1"),
                 h.LI(
                     h.SPAN(
                         "My Company",
                         attrs(model='res.company',
                               id=1,
                               field='name',
                               type='char'))),
                 h.LI(
                     h.SPAN(
                         "+00 00 000 00 0 000",
                         attrs(model='res.company',
                               id=1,
                               field='phone',
                               type='char'))))))
     self.view_id = self.registry('ir.ui.view').create(
         self.cr, self.uid, {
             'name': "Test View",
             'type': 'qweb',
             'arch': ET.tostring(self.arch,
                                 encoding='utf-8').decode('utf-8')
         })
示例#2
0
def get_boards(lines, position, hierarchy):
    divs = []
    pattern = re.compile('([^\s]+)\s(.+)')
    while position < len(lines):
        line = lines[position]
        line = line.replace('\n', '')
        if line == '':
            position += 1
            continue
        match = pattern.search(line)
        if match is None:
            return divs, position
        hierarchy.append(match.group(1))
        cats, pos = get_categories(lines, position + 1, hierarchy)
        hierarchy.pop()
        divs.append(
            E.DIV(
                E.CLASS('fib'),
                E.A(match.group(2),
                    id='board',
                    target='main',
                    href='http://' + match.group(1)),
                E.A('[+]',
                    id='plus',
                    onclick="toggle(this, '" + match.group(2) + "');")))
        divs.append(E.DIV(*cats, style="display: none;", id=match.group(2)))
        position = pos
    return divs, position
示例#3
0
def process_jsonfiles(zipdir):
    """Process all JSON files in the resulting directory

    :param zipdir: zipdir name
    :type zipdir: Path | str
    """
    body = gen_html()

    for jfile in listjsonfiles(str(zipdir)):
        content = load_jsonfile(jfile)
        # Create title
        div = E.DIV(E.H1(content.get("date_journal")))

        # Create date:
        div.append(E.H5(content.get("address")))

        # Create photos:
        divimg = E.DIV()
        for image in content.get('photos'):
            img = E.IMG(
                src=image,
                width="600",
            )
            divimg.append(img)
        div.append(divimg)

        # Create text:
        text = content["text"] = markdown.markdown(content["text"])
        texthtml = fromstring(text)
        div.append(E.P(texthtml))

        body.append(div)
    return body
示例#4
0
def make_short_papers(p_list, count=None):
    authors_dict = json.load(open("authors.json"))

    def gen_author_link(a):
        if a in authors_dict:
            return "<a href=\"" + authors_dict[a] + "\">" + a + "</a>"
        else:
            return a

    tag_list = []
    for paper in p_list[:count]:

        authors = gen_author_link(paper.authors[0])
        for a in paper.authors[1:-1]:
            authors += ", " + gen_author_link(a)
        if len(paper.authors) > 1:
            authors += " and " + gen_author_link(paper.authors[-1])

        links = []

        for key in paper.links:
            links += [builder.A(key, href=paper.links[key])]

        tag_list.append(
            builder.DIV(
                builder.H1(paper.title, builder.CLASS("paper-title")),
                builder.DIV(html.fromstring(authors),
                            builder.CLASS("paper-authors")),
                builder.DIV(paper.date.strftime("%d %b. %Y"),
                            builder.CLASS("paper-date")),
                builder.DIV(*links, builder.CLASS("paper-links")),
                builder.CLASS("paper-container")))
    return tag_list
示例#5
0
def gen_posts(p_list):
    index = builder.HTML(
        builder.HEAD(*make_head()),
        builder.BODY(make_menu(),
                     builder.DIV(
                         builder.H1("Posts", builder.CLASS("section-title")),
                         *make_short_posts(p_list), builder.CLASS("section")),
                     style="background-color:#f7f7f7"))
    print(html.etree.tostring(index, pretty_print=True,
                              method='html').decode("utf-8"),
          file=open(os.path.join(base_path, "posts.html"), "w"))

    for post in p_list:
        html_content = builder.DIV(
            builder.H1(post.title, builder.CLASS("full-post-title")),
            builder.DIV(post.date.strftime("%d %B %Y, %H:%M"),
                        builder.CLASS("full-post-date")),
            builder.DIV(html.fromstring(post.content),
                        builder.CLASS("full-post-content")),
            builder.CLASS("full-post-container"))

        page = builder.HTML(
            builder.HEAD(
                *make_head(),
                builder.SCRIPT("", src=base_url + "js/table.js"),
            ), builder.BODY(make_menu(), html_content))
        print(html.etree.tostring(page, pretty_print=True,
                                  method='html').decode("utf-8"),
              file=open(
                  os.path.join(base_path, "posts", post.id, "index.html"),
                  "w"))
示例#6
0
    def test_field_tail(self):
        replacement = ET.tostring(h.LI(
            h.SPAN(
                "+12 3456789",
                attrs(model='res.company',
                      id=1,
                      type='char',
                      field='phone',
                      expression="edmund")), "whop whop"),
                                  encoding="utf-8")
        self.view_id.save(value=replacement, xpath='/div/div[2]/ul/li[3]')

        self.eq(
            ET.fromstring(self.view_id.arch.encode('utf-8')),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI(
                            h.SPAN(
                                "My Company",
                                attrs(model='res.company',
                                      id=1,
                                      field='name',
                                      type='char'))),
                        h.LI(h.SPAN({'t-field': "edmund"}), "whop whop"),
                    ))))
示例#7
0
    def body(self):
        """The BODY of the html document"""
        reports = E.OL(id='reports')
        code = self.code()

        for i, (state_html, state_problem) in enumerate(self.states(), 1):
            reports.append(
                E.LI(
                    E.ATTR(id="state{0}".format(i)),
                    E.E.header(
                        E.DIV(
                            E.CLASS('error'),
                            state_problem,
                        ),
                        E.DIV(
                            E.CLASS('report-count'),
                            E.H3('Report'),
                            str(i),
                        ),
                    ),
                    E.DIV(
                        E.CLASS('body'),
                        E.DIV(
                            E.CLASS('source'),
                            deepcopy(code),
                        ),
                        state_html,
                    ),
                ), )

        return E.BODY(
            self.header(),
            reports,
            self.footer(),
        )
示例#8
0
    def test_fixup_arch(self):
        replacement = h.H1("I am the greatest title alive!")

        result = self.registry('ir.ui.view').replace_arch_section(
            self.cr, self.uid, self.view_id, '/div/div[1]/h3', replacement)

        self.eq(
            result,
            h.DIV(
                h.DIV(h.H3("I am the greatest title alive!"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI(
                            h.SPAN(
                                "My Company",
                                attrs(model='res.company',
                                      id=1,
                                      field='name',
                                      type='char'))),
                        h.LI(
                            h.SPAN(
                                "+00 00 000 00 0 000",
                                attrs(model='res.company',
                                      id=1,
                                      field='phone',
                                      type='char')))))))
示例#9
0
def template(name, contents):

    cpu_class = 'active' if name == 'cpu' else ''
    wc_class = 'active' if name == 'wc' else ''
    help_class = 'active' if name == 'help' else ''

    return E.HTML(
        E.HEAD(
            E.LINK(rel='stylesheet',
                   type='text/css',
                   href='bootstrap/css/bootstrap.css'),
            E.LINK(rel='stylesheet', type='text/css', href='profile.css'),
            E.SCRIPT(src='bootstrap/js/bootstrap.min.js'),
            E.TITLE('RUM Job Profile')),
        E.BODY(
            E.DIV(E.DIV(E.DIV(E.A(E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  E.SPAN(CLASS='icon-bar'),
                                  CLASS='btn btn-navbar'),
                              E.A('RUM Profile', CLASS='brand', href='#'),
                              E.DIV(E.UL(E.LI(E.A('CPU time', href='cpu.html'),
                                              CLASS=cpu_class),
                                         E.LI(E.A('Wallclock time',
                                                  href='wc.html'),
                                              CLASS=wc_class),
                                         E.LI(E.A('Help', href='help.html'),
                                              CLASS=help_class),
                                         CLASS='nav'),
                                    CLASS='nav-collapse collapse'),
                              CLASS='container'),
                        CLASS='navbar-inner'),
                  CLASS='navbar navbar-inverse navbar-fixed-top'), E.BR(),
            E.BR(), E.BR(), E.DIV(contents, CLASS='container')))
示例#10
0
def list_bans_menu(ban_list, purpose):
    """need to put bans and boards table creating to a joint function in future"""
    tablerows = [E.TR(E.TD(str(b.id)),
                      E.TD(b.ip),
                      E.TD(b.initiator),
                      E.TD(time.strftime('%d/%m/%Y %H:%M', time.localtime(b.date))),
                      E.TD(str(b.level)),
                      E.TD(E.BUTTON('Снять', type = 'button', onclick = 'remove_ban(this);'))
                      )for b in ban_list]
    #purpose will be applyed later
    html = E.HTML(
        E.HEAD(
            E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), 
            E.TITLE("Creating board"),
            E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js
            ),
        E.BODY(
            E.DIV(E.CLASS('adminupdiv'),
                E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')),
                E.H2(E.CLASS("heading"), "Listing bans"),
                ),
            E.TABLE(
                E.CLASS("boardstable"),
                E.TR(E.TH('ID'),
                     E.TH('IP'),
                     E.TH('Забанивший'),
                     E.TH('Дата'),
                     E.TH('Уровень'),
                     E.TH('')
                     ),
                *tablerows
                )
            )
        )
    return lxml.html.tostring(html)
示例#11
0
    def test_save(self):
        Company = self.env['res.company']
        View = self.env['ir.ui.view']

        # create a view with an xmlid, like the file import would
        with self.env.norecompute():
            self.view_id = View.create({
                'name': "Test View",
                'type': 'qweb',
                'arch': ET.tostring(self.arch, encoding='utf-8').decode('utf-8')
            })
        imd = self.env['ir.model.data'].create({
            'module': 'website',
            'name': 'test_view',
            'model': 'ir.ui.view',
            'res_id': self.view_id,
        })

        # the xml_id of the view should not be flagged as 'noupdate'
        self.assertEqual(self.view_id.model_data_id, imd)
        self.assertFalse(imd.noupdate)

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(h.SPAN("Acme Corporation", attrs(model='res.company', id=1, field='name', expression="bob", type='char'))),
                h.LI(h.SPAN("+12 3456789", attrs(model='res.company', id=1, field='phone', expression="edmund", type='char'))),
            )
        ), encoding='utf-8')
        self.view_id.save(value=replacement, xpath='/div/div[2]')

        # the xml_id of the view should be flagged as 'noupdate'
        self.assertTrue(imd.noupdate)

        company = Company.browse(1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(self.view_id.arch.encode('utf-8')),
            h.DIV(
                h.DIV(
                    h.H3("Column 1"),
                    h.UL(
                        h.LI("Item 1"),
                        h.LI("Item 2"),
                        h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(
                        h.LI("wob wob wob"),
                        h.LI(h.SPAN({'t-field': "bob"})),
                        h.LI(h.SPAN({'t-field': "edmund"}))
                    ))
            )
        )
示例#12
0
	def html(self):
		from lxml.html import builder as E
		return E.DIV(
			E.CLASS("treeObject tree"+self.__class__.__name__),
			self.__tag,
			E.DIV(
				E.CLASS("treeObject treeLeaf"+self.__class__.__name__),
				self.__name
			)
		)
示例#13
0
    def visit_Component(self, node):
        inst = getattr(self, 'inst', None)
        if inst:
            title = 'Instance {} of {} Register Map'.format(inst, node.name)
        else:
            title = 'Base {} Register Map'.format(node.name)
        self.title = title

        # Create the main content by sweeping the tree.
        bc = E.DIV(id='breadcrumbs')
        try:
            if self.breadcrumbs is not None:
                bc.append(self.breadcrumbs)
        except AttributeError:
            pass

        ww = node.width // 8
        an = ((node.size - 1).bit_length() + 3) // 4
        with self.tempvars(wordwidth=ww, address_nibbles=an, hlev=2):
            nodes = ([E.H1(title, id='title'), bc] +
                     [E.P(d) for d in node.description] +
                     [c
                      for c in self.visitchildren(node)] + [self.footer(node)])
            contentnode = E.DIV(*nodes, id='content')

        # Add a table of contents sidebar.  We'll assume that everything that
        # wants to be in the TOC is already a heading and just work from there.
        h2list = E.UL()
        for elem in contentnode.iter('h2', 'h3'):
            id = escape(elem.text)
            elem.attrib['id'] = id
            if elem.tag == 'h2':
                h2node = E.LI(E.A(elem.text, href='#' + id))
                h2list.append(h2node)
                h3list = None
            else:
                if h3list is None:
                    h3list = E.UL()
                    h2list.append(h3list)
                h3list.append(E.LI(E.A(elem.text, href='#' + id)))

        # Put it all together.
        return E.HTML(
            E.HEAD(
                E.TITLE(title),
                E.LINK(rel='stylesheet',
                       type='text/css',
                       href=htmlpathjoin(self.styledir, 'reg.css'))),
            E.BODY(
                E.DIV(E.DIV(E.P(E.A(title, href='#title')),
                            h2list,
                            id='sidebar'),
                      contentnode,
                      id='wrapper')),
        )
示例#14
0
    def test_save(self):
        Company = self.env['res.company']

        # create an xmlid for the view
        imd = self.env['ir.model.data'].create({
            'module': 'website',
            'name': 'test_view',
            'model': self.view_id._name,
            'res_id': self.view_id.id,
        })
        self.assertEqual(self.view_id.model_data_id, imd)
        self.assertFalse(imd.noupdate)

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(
                    h.SPAN(
                        "Acme Corporation",
                        attrs(model='res.company',
                              id=1,
                              field='name',
                              expression="bob",
                              type='char'))),
                h.LI(
                    h.SPAN(
                        "+12 3456789",
                        attrs(model='res.company',
                              id=1,
                              field='phone',
                              expression="edmund",
                              type='char'))),
            )),
                                  encoding='unicode')
        self.view_id.save(value=replacement, xpath='/div/div[2]')

        # the xml_id of the view should be flagged as 'noupdate'
        self.assertTrue(imd.noupdate)

        company = Company.browse(1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(self.view_id.arch),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(h.LI("wob wob wob"), h.LI(h.SPAN({'t-field': "bob"})),
                         h.LI(h.SPAN({'t-field': "edmund"}))))))
示例#15
0
def make_short_posts(p_list):
    tag_list = []
    for post in p_list:
        tag_list.append(
            builder.DIV(
                builder.H1(
                    builder.A(post.title, href=base_url + "posts/" + post.id),
                    builder.CLASS("post-title")),
                html.fromstring(post.summary),
                builder.DIV(post.date.strftime("%d %b. %Y, %H:%M"),
                            builder.CLASS("post-date")),
                builder.CLASS("post-container")))
    return tag_list
示例#16
0
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)
示例#17
0
def list_boards_menu(board_list, purpose):
    """need to put boards table creating to a separate function in future"""
    posts_num_cell = E.DIV(E.SPAN('????', style = 'display:inline-block; width:4em; text-align:center;'),
                           E.INPUT(type='number', size='6', min='0', value='1', style = 'width: 6em;'),
                           E.SELECT(E.OPTION('Секунды', value='1'),
                                    E.OPTION('Минуты', value='60'),
                                    E.OPTION('Часы', value='3600'),
                                    E.OPTION('Дни', value='86400', selected='')
                                    ),
                           E.BUTTON('GET', onclick='get_posts_num_from_time(this)', type = 'button'))
    tablerows = [E.TR(E.TD(E.A(b.address, href = '/'+b.address)),
                      E.TD(b.tablename),
                      E.TD(str(b.name)),
                      E.TD(str(b.fullname)),
                      E.TD(str(b.description)),
                      E.TD(str(b.category)),
                      E.TD(str(b.pictures)),
                      E.TD(str(b.bumplimit)),
                      E.TD(str(b.maxthreads)),
                      E.TD(copy.copy(posts_num_cell))
                      )for b in board_list]
    #purpose will be applyed later
    html = E.HTML(
        E.HEAD(
            E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"), 
            E.TITLE("Creating board"),
            E.SCRIPT(type = 'text/javascript', src = '/adminscript.js') #js
            ),
        E.BODY(
            E.DIV(E.CLASS('adminupdiv'),
                E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')),
                E.H2(E.CLASS("heading"), "Listing boards"),
                ),
            E.TABLE(
                E.CLASS("boardstable"),
                E.TR(E.TH('Адрес'),
                     E.TH('Таблица'),
                     E.TH('Название'),
                     E.TH('Полное название'),
                     E.TH('Описание'),
                     E.TH('Категория'),
                     E.TH('Максимум картинок'),
                     E.TH('Бамплимит'),
                     E.TH('Максимум тредов'),
                     E.TH('Постов за последнее время')
                     ),
                *tablerows
                )
            )
        )
    return lxml.html.tostring(html)
示例#18
0
    def header(self):
        """Make the header bar of the webpage"""

        return E.E.header(
            E.ATTR(id='header'),
            E.DIV(
                E.ATTR(id='title'),
                E.H1(
                    E.A(
                        'GCC Python Plugin',
                        href='http://gcc-python-plugin.readthedocs.org/',
                    ),
                ),
                E.DIV(
                    E.ATTR(id='info'),
                    E.SPAN(
                        E.CLASS('label'),
                        'Filename: ',
                    ),
                    self.data['filename'],
                    E.SPAN(
                        E.CLASS('label'),
                        'Function: ',
                    ),
                    self.data['function']['name'],
                ),
                E.DIV(
                    E.ATTR(id='report-pagination'),
                    E.SPAN(
                        E.CLASS('label'),
                        'Report: ',
                    ),
                    *(
                        E.A(str(i + 1), href="#state{0}".format(i + 1))
                        for i in range(len(self.data['reports']))
                    )
                ),
                E.DIV(
                    E.ATTR(id='prev'),
                    E.IMG(
                        src=data_uri('image/png', 'images/arrow-180.png'),
                    ),
                ),
                E.DIV(
                    E.ATTR(id='next'),
                    E.IMG(
                        src=data_uri('image/png', 'images/arrow.png'),
                    ),
                ),
            ),
        )
示例#19
0
def board_creation_menu(): #here is the html board creation menu
    html = E.HTML(
        E.HEAD(
            E.LINK(rel="stylesheet", href="/css/deeplight.css", type="text/css"),
            E.TITLE("Creating board")
            ),
        E.BODY(
            E.DIV(E.CLASS('adminupdiv'),
                E.DIV(E.CLASS('logout'), E.A('Logout', href='/admin/logout')),
                E.H2(E.CLASS("heading"), "Create new board"),
                ),
            E.DIV(E.CLASS("boardcreateform"),
            E.FORM(
                   E.INPUT(type = 'hidden', name = 'action', value = 'create'),
                   E.INPUT(type = 'hidden', name = 'instance', value = 'board'),
                   E.TABLE(
                       E.TR(E.TD('Address'),
                            E.TD(E.INPUT(type = 'text', name = 'address', value = ''))
                            ),
                       E.TR(E.TD('Tablename'),
                            E.TD(E.INPUT(type = 'text', name = 'tablename', value = ''))
                            ),
                       E.TR(E.TD('Name'),
                            E.TD(E.INPUT(type = 'text', name = 'name', value = ''))
                            ),
                       E.TR(E.TD('Fullname'),
                            E.TD(E.INPUT(type = 'text', name = 'fullname', value = ''))
                            ),
                       E.TR(E.TD('Description'),
                            E.TD(E.INPUT(type = 'text', name = 'description', value = ''))
                            ),
                       E.TR(E.TD('Pics number'),
                            E.TD(E.INPUT(type = 'number', name = 'picsnum', value = '', min = '0', max = '10'))
                            ),
                       E.TR(E.TD('Bumplimit'),
                            E.TD(E.INPUT(type = 'number', name = 'bumplimit', value = '', min = '0'))
                            ),
                       E.TR(E.TD('Max threads'),
                            E.TD(E.INPUT(type = 'number', name = 'maxthreads', value = '', min = '-1'))
                            ),
                       E.TR(E.TD(E.INPUT(type='checkbox', name='delposts', value='1', checked='checked'), 'Удаление постов', colspan='2', style='text-align:center;')),
                       E.TR(E.TD(E.INPUT(type='checkbox', name='delopposts', value='1', checked='checked'), 'Удаление тредов', colspan='2', style='text-align:center;')),
                       ),
                   E.INPUT(type = 'submit', value = 'Create'),
                   method='POST',
                   action='/admin/'
                   )
            )
            )
        )
    return lxml.html.tostring(html)
示例#20
0
 def html(self):
     from lxml.html import builder as E
     return E.TABLE(
         E.CLASS("instruct"),
         E.TR(E.TH("Instruction", colspan="2")),
         E.TR(
             E.TD(str(tuple(self.outPointers)) + " ← " + self.name +
                  str(tuple(self.inPointers)),
                  colspan="2")),
         E.TR(
             E.TD(*[E.DIV(str(k)) for k in self.outData]),
             E.TD(*[E.DIV(str(k)) for k in self.inData]),
         ),
     )
示例#21
0
def main(results_file):
    summary = {}
    with open(results_file, 'r') as f:
        summary = json.loads(f.read())
        summary['directory'] = os.path.dirname(results_file)

    date = datetime.datetime.fromtimestamp(
        summary['timestamp']).strftime('%Y-%m-%d-%H:%M:%S')

    token_create_rps = summary['token_creation']['requests_per_second']
    token_create_tps = summary['token_creation']['time_per_request']
    token_validate_rps = summary['token_validation']['requests_per_second']
    token_validate_tps = summary['token_validation']['time_per_request']

    index = e.HTML(
        e.HEAD(e.LINK(rel='stylesheet', type='text/css', href='theme.css'),
               e.TITLE('OpenStack Keystone Performance')),
        e.BODY(
            e.DIV(e.H1('OpenStack Keystone Performance'),
                  e.P('Published reports after each merged patch.',
                      CLASS('subtitle')),
                  id='header'),
            e.DIV(
                e.P('Last run date: ' + date, ),
                e.P(
                    'keystone SHA: ',
                    e.A(summary['sha'],
                        target='_blank',
                        href=KEYSTONE_LINK + summary['sha'])),
                e.P(
                    'os_keystone SHA: ',
                    e.A(summary['osa_sha'],
                        target='_blank',
                        href=OSA_LINK + summary['osa_sha'])),
                e.P(e.A('Performance Data', href=PERF_LINK, target='_blank')),
                e.DIV(CLASS('left'), e.H2('Create Token'),
                      e.P(e.STRONG(token_create_rps), ' requests per second'),
                      e.P(e.STRONG(token_create_tps), ' ms per request')),
                e.DIV(
                    CLASS('right'), e.H2('Validate Token'),
                    e.P(e.STRONG(token_validate_rps), ' requests per second'),
                    e.P(e.STRONG(token_validate_tps), ' ms per request')),
                id='content'),
            e.DIV(e.P(
                'Results provided by the ',
                e.A('OSIC Performance Bot', target='_blank', href=BOT_LINK)),
                  id='footer')))

    with open(os.path.join(summary['directory'], 'index.html'), 'w') as f:
        f.write(et.tostring(index))
示例#22
0
    def test_replace_arch_2(self):
        replacement = h.DIV(h.P("Wheee"))

        result = self.registry('ir.ui.view').replace_arch_section(
            self.cr, self.uid, self.view_id, None, replacement)

        self.eq(result, replacement)
示例#23
0
    def ToString(self):
        result = E.DIV()
        result.attrib['class'] = 'center'

        ul = E.UL()
        result.append(ul)
        ul.attrib['class'] = 'mktree'
        ul.attrib['id'] = 'diffRoot'

        #  Insert xml declarations

        n = E.LI()
        n.attrib['whereLeft'] = "L0_0"
        n.attrib['whereRight'] = "R0_0"
        leftText = '<?xml version="{0}" encoding="{1}"?>'.format(
            self.xml.docinfo.xml_version, self.xml.docinfo.encoding)
        rightText = '<?xml version="{0}" encoding="{1}"?>'. \
            format(self.matchNode.xml.docinfo.xml_version,
                   self.matchNode.xml.docinfo.encoding)
        self.diffTextToHtml(leftText, rightText, n)
        ul.append(n)

        # Insert DTD declaration if one exists
        n = E.LI()
        if self.xml.docinfo.doctype or self.matchNode.xml.docinfo.doctype:
            self.diffTextToHtml(self.xml.docinfo.doctype,
                                self.matchNode.xml.docinfo.doctype, n)
            ul.append(n)

        # now put all of the children into HTML

        for child in self.children:
            child.ToHtml(ul)

        return self._serialize(result)
示例#24
0
    def _create_html_root(self, hhcpath, log, encoding):

        hhcdata = self._read_file(hhcpath)
        hhcdata = hhcdata.decode(encoding)
        hhcdata = xml_to_unicode(hhcdata, verbose=True,
                                 strip_encoding_pats=True,
                                 resolve_entities=True)[0]
        hhcroot = html.fromstring(hhcdata)
        toc = self._process_nodes(hhcroot)
        log.debug('Found %d section nodes' % toc.count())
        htmlpath = os.path.splitext(hhcpath)[0] + ".html"
        base = os.path.dirname(os.path.abspath(htmlpath))

        def unquote(x):
            if isinstance(x, str):
                x = x.encode('utf-8')
            return _unquote(x).decode('utf-8')

        def unquote_path(x):
            y = unquote(x)
            if (not os.path.exists(os.path.join(base, x)) and
                    os.path.exists(os.path.join(base, y))):
                x = y
            return x

        def donode(item, parent, base, subpath):
            for child in item:
                title = child.title
                if not title:
                    continue
                raw = unquote_path(child.href or '')
                rsrcname = os.path.basename(raw)
                rsrcpath = os.path.join(subpath, rsrcname)
                if (not os.path.exists(os.path.join(base, rsrcpath)) and
                        os.path.exists(os.path.join(base, raw))):
                    rsrcpath = raw

                if '%' not in rsrcpath:
                    rsrcpath = urlquote(rsrcpath)
                if not raw:
                    rsrcpath = ''
                c = builder.DIV(builder.A(title, href=rsrcpath))
                donode(child, c, base, subpath)
                parent.append(c)

        with open(htmlpath, 'wb') as f:
            if toc.count() > 1:
                path0 = toc[0].href
                path0 = unquote_path(path0)
                subpath = os.path.dirname(path0)
                base = os.path.dirname(f.name)
                root = builder.DIV()
                donode(toc, root, base, subpath)
                raw = html.tostring(builder.HTML(builder.BODY(root)),
                                    encoding='utf-8',
                                    pretty_print=True)
                f.write(raw)
            else:
                f.write(as_bytes(hhcdata))
        return htmlpath, toc
示例#25
0
    def show_report(self):
        """Override base class, because we're not using the Report class.

        Loop back to the cascading form for names if we don't have an id.
        """

        if not self.id:
            self.show_form()
        buttons = (
            self.HTMLPage.button(self.SUBMENU),
            self.HTMLPage.button(self.ADMINMENU),
            self.HTMLPage.button(self.LOG_OUT),
        )
        opts = dict(
            buttons=buttons,
            session=self.session,
            action=self.script,
            banner=self.title,
            footer=self.footer,
            subtitle=self.subtitle,
        )
        report = self.HTMLPage(self.title, **opts)
        instructions = builder.DIV(
            "Click term name to view formatted term document.", builder.BR(),
            "Click document ID to navigate tree.")
        report.body.append(instructions)
        for table in self.tree.tables:
            report.body.append(table)
        report.body.append(self.footer)
        report.add_css("\n".join(self.CSS))
        report.send()
示例#26
0
    def test_save(self):
        Company = self.registry('res.company')
        View = self.registry('ir.ui.view')

        replacement = ET.tostring(h.DIV(
            h.H3("Column 2"),
            h.UL(
                h.LI("wob wob wob"),
                h.LI(
                    h.SPAN(
                        "Acme Corporation",
                        attrs(model='res.company',
                              id=1,
                              field='name',
                              expression="bob",
                              type='char'))),
                h.LI(
                    h.SPAN(
                        "+12 3456789",
                        attrs(model='res.company',
                              id=1,
                              field='phone',
                              expression="edmund",
                              type='char'))),
            )),
                                  encoding='utf-8')
        View.save(self.cr,
                  self.uid,
                  res_id=self.view_id,
                  value=replacement,
                  xpath='/div/div[2]')

        company = Company.browse(self.cr, self.uid, 1)
        self.assertEqual(company.name, "Acme Corporation")
        self.assertEqual(company.phone, "+12 3456789")
        self.eq(
            ET.fromstring(
                View.browse(self.cr, self.uid,
                            self.view_id).arch.encode('utf-8')),
            h.DIV(
                h.DIV(h.H3("Column 1"),
                      h.UL(h.LI("Item 1"), h.LI("Item 2"), h.LI("Item 3"))),
                h.DIV(
                    h.H3("Column 2"),
                    h.UL(h.LI("wob wob wob"), h.LI(h.SPAN({'t-field': "bob"})),
                         h.LI(h.SPAN({'t-field': "edmund"}))))))
示例#27
0
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)
示例#28
0
def html_file_section_handler_github(item: Dict[str, Any]) -> Any:
    filepath = item["file"]
    file_url = item.get("file_url", filepath)
    change_elements = [
        render_change_as_html(change, filepath, 0, 2)
        for change in item["changes"]
    ]
    file_summary_element = E.A(filepath, href=file_url)
    file_elements = [
        E.B("Changes:"),
        E.UL(*change_elements),
    ]
    file_elements_div = E.DIV(*file_elements)
    file_details_element = E.DIV(
        lxml.html.fromstring(
            f"<details><summary>{lxml.html.tostring(file_summary_element).decode()}</summary>"
            f"{lxml.html.tostring(file_elements_div).decode()}</details>"))
    return file_details_element
示例#29
0
def build_locale_content():
    main = template_keys['mirror.locale.main']
    content = E.DIV(E.P("Browse in ", _locale_link(main), ", or:"))
    ul = E.UL()
    for locale in locales:
        ul.append(E.LI(_locale_link(locale)))
    content.append(ul)
    template_keys['mirror.locale.content'] = html.tostring(content).decode(
        'utf-8')
示例#30
0
 def __init__(self, datas, lang, freeze, title, css_path):
     super().__init__(datas, lang, freeze)
     self._html = builder.HTML(
         builder.HEAD(
             builder.META(charset="utf-8"),
             builder.TITLE(title),
             builder.LINK(rel="stylesheet", href=css_path),
         ),
         builder.BODY(builder.DIV(id="text_area")),
     )