Example #1
0
File: templates.py Project: p/midge
def _sortable_table_headings(wfile, path, titles,
                             variables, sorted_by, ordered):
    wfile.write('''
    <tr>''')
    for heading, variable in zip(titles, variables):
        if variable == sorted_by:
            new_order = {"ascending": "descending",
                         "descending": "ascending"}[ordered]
        else:
            new_order = "ascending"
        url = lib.html_entity_escape(
            lib.join_url(path, {"sort_by": variable,
                                "order": new_order}))
        if variable == variables[-1]:
            css_class = "last-column-heading"
        else:
            css_class = "column-heading"
        wfile.write('''
     <th class="%(css_class)s">
      <a href="%(url)s">
       %(heading)s
      </a>''' % {"heading": heading,
                        "url": url,
                        "css_class": css_class})
        if variable == sorted_by:
            direction = {"ascending": "up",
                         "descending": "down"}[ordered]
            wfile.write('''
      <img src="/images?name=%(direction)s.gif" alt="%(direction)s"/>''' % {"direction": direction})
        wfile.write('''
     </th>''')
    wfile.write('''                
    </tr>''')
Example #2
0
File: templates.py Project: p/midge
def format_comment(text):
    """Return text suitable for displaying as comment.

    This means:
      stripping leading newlines (but not spaces)
      stripping tailing whitespace
      escaping any html-like tags,
      replacing newlines with <br/>, and
      replacing leading spaces with hardspaces (&nbsp;).

    Also replace text to provide hyperlinks, as per midge.conf.

    """
    text = text.lstrip("\n")
    text = text.rstrip()
    text = lib.html_entity_escape(text)
    rows = []
    for row in text.split("\n"):
        n_leading_spaces = 0
        for c in row:
            if c == " ":
                n_leading_spaces += 1
            else:
                break
        rows.append(row.replace(" ", "&nbsp;", n_leading_spaces))
    text = "\n<br/>\n".join(rows)

    for name, pattern, substitute in config.CommentMappings.mappings:
        text = re.sub(pattern, substitute, text)

    return text
Example #3
0
File: locations.py Project: p/midge
    def _pretty_print_search(self, wfile, criteria, values):

        def clean_name(s):
            s = s.replace("regex", "(regex)")
            s = s.replace("_", " ")
            return s.capitalize()
        
        bullets = []
        for k,v in criteria.iteritems():
            bullets.append("%s = %s" % (clean_name(k),v))

        copy_of_values = values.copy()
        copy_of_values["refine"] = "yes"
        url = lib.html_entity_escape(lib.join_url(self.path, copy_of_values))
        bullets.append('<a href="%s">Refine search</a>' % url)

        templates.bullets(wfile, *bullets)