예제 #1
0
파일: HTML.py 프로젝트: anarchivist/pyflag
 def __str__(self):
     attributes = "".join([expand(" %s='%s'",(k,iri_to_uri(v))) for k,v \
                           in self.attributes.items() if v != None ])
     
     if self.type == 'selfclose':
         return expand("<%s%s/>", (self.name, attributes))
     else:
         return expand("<%s%s>%s</%s>", (self.name, attributes,
                                   self.innerHTML(), self.name))
예제 #2
0
파일: HTML.py 프로젝트: johnmccabe/pyflag
    def __str__(self):
        attributes = "".join([expand(" %s='%s'",(k,iri_to_uri(v))) for k,v \
                              in self.attributes.items() if v != None ])

        if self.type == 'selfclose':
            return expand("<%s%s/>", (self.name, attributes))
        else:
            return expand("<%s%s>%s</%s>",
                          (self.name, attributes, self.innerHTML(), self.name))
예제 #3
0
파일: HTML.py 프로젝트: anarchivist/pyflag
    def __str__(self):
        postfix = ''
        ## Some tags are never allowed to be outputted
        if self.name not in self.allowable_tags:
            if self.name in self.forbidden_tag:
                return ''
            #print "Rejected tag %s" % self.name
            return self.innerHTML()

        if self.name == 'head':
            self.children = [self.header,] + self.children
        elif self.name =='body':
            self.children = [self.body_extra, ] + self.children

        ## Frames without src are filtered because IE Whinges:
        if self.name == 'iframe' and 'src' not in self.attributes:
		return ''

        attributes = "".join([" %s='%s'" % (k,v) for k,v \
                              in self.attributes.items() if k in \
                              self.allowable_attributes])

	if 'style' in self.attributes:
            attributes += ' style=%r' % self.css_filter(self.attributes['style'] or '')

        if 'http-equiv' in self.attributes:
            if self.attributes['http-equiv'].lower() == "content-type":
                ## PF _always_ outputs in utf8
                attributes += ' http-equiv = "Content-Type" content="text/html; charset=UTF-8"'
                
        if 'src' in self.attributes:
            attributes += ' src=%s' % self.resolve_reference(self.attributes['src'])

        try:
            if 'href' in self.attributes:
                if self.name == 'link':
                    attributes += " href=%s" % self.resolve_reference(self.attributes['href'], 'text/css')
                else:
                    attributes += DB.expand(' href="javascript: alert(%r)"',
                                            iri_to_uri(DB.expand("%s",self.attributes['href'])[:100]))
                    postfix = self.mark_link(self.attributes['href'])
        except: pass
        
        ## CSS needs to be filtered extra well
        if self.name == 'style':
            return expand("<style %s>%s</style>" , (attributes,
                                             self.css_filter(self.innerHTML())))
        
        if self.type == 'selfclose':
            return expand("<%s%s/>%s" , (self.name, attributes, postfix))
        else:
            return expand("<%s%s>%s</%s>%s", (self.name, attributes,
                                            self.innerHTML(),
                                            self.name,postfix))
예제 #4
0
파일: HTML.py 프로젝트: anarchivist/pyflag
 def tree(self, width=''):
     result = expand("%s%s\n", (width, self.name))
     width += ' '
     for c in self.children:
         try:
             result += c.tree(width)
         except AttributeError:
             result += "%sCDATA: %r\n" % (width, c)
             
     return result
예제 #5
0
파일: HTML.py 프로젝트: anarchivist/pyflag
    def to_unicode(self, code):
        child_result = ''
        for c in self.children:
            if type(c)==str:
                child_result += c.encode(code)
            else:
                child_result += c.to_unicode(code)

        attributes = "".join([expand(" %s='%s'",(k,iri_to_uri(v))) for k,v \
                              in self.attributes.items() if v != None ])

        if self.type == 'selfclose':
            result = expand("<%s%s/>", (self.name, attributes))
        else:
            result = expand("<%s%s>%s</%s>", (self.name.encode("utf8"), attributes,
                                              child_result, self.name))

        result = result.encode("latin1")
        return result
예제 #6
0
파일: HTML.py 프로젝트: johnmccabe/pyflag
    def tree(self, width=''):
        result = expand("%s%s\n", (width, self.name))
        width += ' '
        for c in self.children:
            try:
                result += c.tree(width)
            except AttributeError:
                result += "%sCDATA: %r\n" % (width, c)

        return result
예제 #7
0
파일: HTMLBundle.py 프로젝트: ntvis/pyflag
    def toc(self):
        page_template = u"""<html><head><link media="all" href="images/pyflag.css" type="text/css" rel="stylesheet">
        <title>Table of Content</title>
        <style>
        body {
        overflow: auto;
        height: 100%%;
        }

        div.PyFlagPage {
        overflow: visible;
        width: 100%%;
        }
        </style>
        </head>
        <body>
        <div id="PyFlagPage" class="PyFlagPage">
        %s
        </div>
        </body></html>"""

        toc = HTMLUI.HTMLUI(initial=True)
        toc.heading("Case %s" % self.case)

        toc.start_table(**{"class": "PyFlagTable"})
        toc.raw("<thead><th>Filename</th><th>Description</th></thead>")
        dbh = DB.DBO(self.case)
        pages = dict()
        dbh.execute("select * from reporting order by page_name")
        for row in dbh:
            m = re.match("^([^\d]+)(\d+).html", row["page_name"])
            pages[m.group(1)] = row["description"]

        page_names = pages.keys()
        page_names.sort()

        for page_name in page_names:
            toc.row(expand("<a href='%s_toc.html'>%s</a>", (page_name, page_name)))

        page = page_template % toc
        self.add_file_from_string("toc.html", page.encode("utf8"))

        for page_name in page_names:
            dbh = DB.DBO(self.case)
            dbh.execute("select * from reporting where page_name like '%s%%' order by page_name", page_name)
            result = HTMLUI.HTMLUI(initial=True)
            result.heading("Case %s" % self.case)

            result.start_table(**{"class": "PyFlagTable"})
            result.raw("<thead><th>Filename</th><th>Description</th><th>From</th><th>To</th></thead>")

            for row in dbh:
                if row["start_value"] == "None":
                    continue

                result.row(
                    expand("<a href=%r>%s</a>", (row["page_name"], row["page_name"])),
                    row["description"],
                    row["start_value"],
                    row["end_value"],
                    **{"class": "hoverRow"}
                )

            result.end_table()

            result.raw("<p><p>\n<font size='-5' color=red>Report Produced using PyFlag Ver. %s</font>" % config.VERSION)

            page = page_template % result
            m = re.match("^([^\d]+)(\d+).html", row["page_name"])
            self.add_file_from_string("%s_toc.html" % m.group(1), page.encode("utf8"))
예제 #8
0
파일: UI.py 프로젝트: backupManager/pyflag
    def render_table(self, query, result):
        """ Renders the actual table itself """
        result.result+='''<table class="PyFlagTable" >
        <thead><tr>'''

        ## Get a generator for the rows:
        g = self.generate_rows(query)
        
        ## Make the table headers with suitable order by links:
        hiddens = [ int(x) for x in query.getarray(self.hidden) ]

        self.column_names = []
        for e in range(len(self.elements)):
            if e in hiddens: continue
            new_query = query.clone()
            ui = result.__class__(result)
            n = self.elements[e].column_decorator(self.table, self.sql, query, ui)
            n = n or ui
            self.column_names.append(n)
            
            if self.order==e:
                if query.get('direction','1')=='1':
                    tmp = result.__class__(result)
                    new_query.set('order', e)
                    new_query.set('direction',0)
                    tmp.link("%s<img src='images/increment.png'>" % n, target= new_query, pane='pane')
                    result.result+="<th>%s</th>" % tmp
                else:
                    tmp = result.__class__(result)
                    new_query.set('order', e)
                    new_query.set('direction',1)
                    tmp.link("%s<img src='images/decrement.png'>" % n, target= new_query, pane='pane')
                    result.result+="<th>%s</th>" % tmp
            else:
                tmp = result.__class__(result)
                new_query.set('order', e)
                new_query.set('direction',1)
                tmp.link(n, target= new_query, pane='pane')
                result.result+="<th>%s</th>" % tmp

        result.result+='''</tr></thead><tbody class="scrollContent">'''

        old_sorted = None
        old_sorted_style = ''

        ## Total number of rows
        self.row_count=0

        for row in g:
            row_elements = []
            tds = ''

            ## Render each row at a time:
            for i in range(len(self.elements)):
                if i in hiddens: continue

                ## Give the row to the column element to allow it
                ## to translate the output suitably:
                value = row[self.elements[i].name]
                try:
                    cell_ui = result.__class__(result)
                    ## Elements are expected to render on cell_ui
                    tmp = self.elements[i].display(value,row,cell_ui)
                    if tmp: cell_ui = tmp
                except Exception, e:
                    pyflaglog.log(pyflaglog.ERROR, expand("Unable to render %r: %s" , (value , e)))

                ## Render the row styles so that equal values on
                ## the sorted column have the same style
                if i==self.order and value!=old_sorted:
                    old_sorted=value
                    if old_sorted_style=='':
                        old_sorted_style='alternateRow'
                    else:
                        old_sorted_style=''

                ## Render the sorted column with a different style
                if i==self.order:
                    tds+="<td class='sorted-column'>%s</td>" % (FlagFramework.smart_unicode(cell_ui))
                else:
                    tds+=DB.expand("<td class='table-cell'>%s</td>",cell_ui)

            result.result+="<tr class='%s'> %s </tr>\n" % (old_sorted_style,tds)
            self.row_count += 1
예제 #9
0
파일: HTML.py 프로젝트: johnmccabe/pyflag
    def __str__(self):
        postfix = ''
        ## Some tags are never allowed to be outputted
        if self.name not in self.allowable_tags:
            if self.name in self.forbidden_tag:
                return ''
            #print "Rejected tag %s" % self.name
            return self.innerHTML()

        if self.name == 'head':
            self.children = [
                self.header,
            ] + self.children
        elif self.name == 'body':
            self.children = [
                self.body_extra,
            ] + self.children

        ## Frames without src are filtered because IE Whinges:
        if self.name == 'iframe' and 'src' not in self.attributes:
            return ''

        attributes = "".join([" %s='%s'" % (k,v) for k,v \
                              in self.attributes.items() if k in \
                              self.allowable_attributes])

        if 'style' in self.attributes:
            attributes += ' style=%r' % self.css_filter(
                self.attributes['style'] or '')

        if 'http-equiv' in self.attributes:
            if self.attributes['http-equiv'].lower() == "content-type":
                ## PF _always_ outputs in utf8
                attributes += ' http-equiv = "Content-Type" content="text/html; charset=UTF-8"'

        if 'src' in self.attributes:
            attributes += ' src=%s' % self.resolve_reference(
                self.attributes['src'])

        try:
            if 'href' in self.attributes:
                if self.name == 'link':
                    attributes += " href=%s" % self.resolve_reference(
                        self.attributes['href'], 'text/css')
                else:
                    attributes += DB.expand(
                        ' href="javascript: alert(%r)"',
                        iri_to_uri(
                            DB.expand("%s", self.attributes['href'])[:100]))
                    postfix = self.mark_link(self.attributes['href'])
        except:
            pass

        ## CSS needs to be filtered extra well
        if self.name == 'style':
            return expand("<style %s>%s</style>",
                          (attributes, self.css_filter(self.innerHTML())))

        if self.type == 'selfclose':
            return expand("<%s%s/>%s", (self.name, attributes, postfix))
        else:
            return expand(
                "<%s%s>%s</%s>%s",
                (self.name, attributes, self.innerHTML(), self.name, postfix))