Exemple #1
0
 def default_header_ordered_column_format(self, column_number, column_name,
                                          header_label):
     header_label = HTML(header_label, HTML.tag("span", class_="marker"))
     if column_name == "_numbered":
         column_name = "numbered"
     class_name = "c%s ordering %s %s" % (column_number, self.order_dir, column_name)
     return HTML.tag("td", header_label, class_=class_name)
    def errorlist(self, name=None, **attrs):
        """
        Renders errors in a <ul> element if there are multiple, otherwise will
        use a div. Unless specified in attrs, class will be "Alert".

        If no errors present returns an empty string.

        `name` : errors for name. If **None** all errors will be rendered.
        """

        if name is None:
            errors = self.all_errors()
        else:
            errors = self.errors_for(name)

        if not errors:
            return ""

        if "class_" not in attrs:
            attrs["class_"] = "Alert"

        if len(errors) > 1:
            content = "\n".join(HTML.tag("li", error) for error in errors)

            return HTML.tag("ul", tags.literal(content), **attrs)

        return HTML.tag("div", errors[0], **attrs)
Exemple #3
0
    def errorlist(self, name=None, **attrs):
        """
        Renders errors in a <ul> element. Unless specified in attrs, class
        will be "error".

        If no errors present returns an empty string.

        `name` : errors for name. If **None** all errors will be rendered.
        """

        if not self.form:
            return None

        if name is None:
            errors = self.form.all_errors()
        else:
            errors = self.form.errors_for(name)

        if not errors:
            return ''

        content = "\n".join(HTML.tag("li", error) for error in errors)

        if 'class_' not in attrs:
            attrs['class_'] = "error"

        return HTML.tag("ul", tags.literal(content), **attrs)
Exemple #4
0
    def errorlist(self, name=None, **attrs):
        """
        Renders errors in a <ul> element if there are multiple, otherwise will
        use a div. Unless specified in attrs, class will be "Alert".

        If no errors present returns an empty string.

        `name` : errors for name. If **None** all errors will be rendered.
        """

        if name is None:
            errors = self.all_errors()
        else:
            errors = self.errors_for(name)

        if not errors:
            return ''

        if 'class_' not in attrs:
            attrs['class_'] = "Alert"

        if len(errors) > 1:
            content = Markup("\n").join(HTML.tag("li", error) for error in errors)

            return HTML.tag("ul", tags.literal(content), **attrs)

        return Markup('''
            <div class="ui-widget clearfix" style="margin: 0.25em;">
                <div class="ui-state-error error-field-wrapper">
                <span class="ui-icon ui-icon-alert error-notice-icon"></span>%s
                </div>
            </div>
            ''') % errors[0]
Exemple #5
0
    def errorlist(self, name=None, **attrs):
        _ = self.form.request.translate
        """
        Renders errors in a <ul> element if there are multiple, otherwise will
        use a div. Unless specified in attrs, class will be "Alert".

        If no errors present returns an empty string.

        `name` : errors for name. If **None** all errors will be rendered.
        """

        if name is None:
            errors = self.all_errors()
        else:
            errors = self.errors_for(name)

        if not errors:
            return ''

        if 'class_' not in attrs:
            attrs['class_'] = "Alert"

        if len(errors) > 1:
            content = Markup("\n").join(
                HTML.tag("li", error) for error in errors)

            return HTML.tag("ul", tags.literal(content), **attrs)

        return Markup('''
            <div class="ui-widget clearfix" style="margin: 0.25em;">
                <div class="ui-state-error error-field-wrapper">
                <span class="ui-icon ui-icon-alert error-notice-icon">%s</span>%s
                </div>
            </div>
            ''') % (_('Error'), errors[0])
Exemple #6
0
 def default_header_column_format(self, column_number, column_name, header_label):
     if column_name == "_numbered":
         column_name = "numbered"
     if column_name in self.exclude_ordering:
         class_name = "c%s %s" % (column_number, column_name)
         return HTML.tag("td", header_label, class_=class_name)
     else:
         header_label = HTML(header_label, HTML.tag("span", class_="marker"))
         class_name = "c%s ordering %s" % (column_number, column_name)
         return HTML.tag("td", header_label, class_=class_name)
Exemple #7
0
 def default_header_ordered_column_format(
     self, column_number, column_name, header_label
 ):
     dir_char = "&#9650;" if self.order_dir == "asc" else "&#9660;"
     header_label = HTML(
         header_label, HTML.tag("span", literal(dir_char), class_="marker")
     )
     if column_name == "_numbered":
         column_name = "numbered"
     class_name = "c%s ordering %s %s" % (column_number, self.order_dir, column_name)
     return HTML.tag("td", header_label, class_=class_name)
Exemple #8
0
    def selected_td(self, col_num, i, item):
        from string import Template
        from webhelpers2.html.builder import HTML

        icon_class = "glyphicon glyphicon-thumbs-down"
        if item['selected'] == True:
            icon_class = "glyphicon glyphicon-thumbs-up"
        div = Template("""\
        <button class="btn btn-mini select" data-value="${identifier}"><i class="${icon_class}"></i></button>
        """)
        return HTML.td(HTML.literal(div.substitute({'identifier': item['identifier'], 'icon_class': icon_class} )))
Exemple #9
0
    def errorlist(self, name):
        """
        Return a list of errors for the given field as a ``ul`` tag.
        """
        name = self._get_name(name)
        errors = self.errors_for(name)

        if not errors:
            return ''

        content = "\n".join(HTML.tag("li", error) for error in errors)
        return HTML.tag("ul", tags.literal(content), class_='error')
Exemple #10
0
    def errorlist(self, name):
        """
        Return a list of errors for the given field as a ``ul`` tag.
        """
        name = self._get_name(name)
        errors = self.errors_for(name)

        if not errors:
            return ''

        content = "\n".join(HTML.tag("li", error) for error in errors)
        return HTML.tag("ul", tags.literal(content), class_='error')
    def selected_td(self, col_num, i, item):
        from string import Template
        from webhelpers2.html.builder import HTML

        icon_class = "glyphicon glyphicon-thumbs-down"
        if item.get('selected') == True:
            icon_class = "glyphicon glyphicon-thumbs-up"
        div = Template("""\
        <a class="select" data-value="${recordid}" href="#"><i class="${icon_class}"></i></a>
        """)
        return HTML.td(HTML.literal(div.substitute({'recordid': item['identifier'],
                                                    'icon_class': icon_class} )))
Exemple #12
0
 def default_header_ordered_column_format(self, column_number, column_name, header_label):
     """Override of the ObjectGrid to use <th> and to add an icon
     that represents the sort order for the column.
     """
     icon_direction = self.order_dir == 'asc' and 'up' or 'down'
     icon_class = 'icon-chevron-%s' % icon_direction
     icon_tag = HTML.tag("i", class_=icon_class)
     header_label = HTML(header_label, " ", icon_tag)
     if column_name == "_numbered":
         column_name = "numbered"
     class_name = "c%s ordering %s %s" % (
         column_number, self.order_dir, column_name)
     return HTML.tag("th", header_label, class_=class_name)
Exemple #13
0
 def default_header_column_format(self, column_number, column_name,
     header_label):
     """Override of the ObjectGrid to use <th> for header columns
     """
     if column_name == "_numbered":
         column_name = "numbered"
     if column_name in self.exclude_ordering:
         class_name = "c%s %s" % (column_number, column_name)
         return HTML.tag("th", header_label, class_=class_name)
     else:
         header_label = HTML(
             header_label, HTML.tag("span", class_="marker"))
         class_name = "c%s ordering %s" % (column_number, column_name)
         return HTML.tag("th", header_label, class_=class_name)
Exemple #14
0
 def default_header_ordered_column_format(self, column_number, column_name,
                                          header_label):
     """Override of the ObjectGrid to use <th> and to add an icon
     that represents the sort order for the column.
     """
     icon_direction = self.order_dir == 'asc' and 'up' or 'down'
     icon_class = 'icon-chevron-%s' % icon_direction
     icon_tag = HTML.tag("i", class_=icon_class)
     header_label = HTML(header_label, " ", icon_tag)
     if column_name == "_numbered":
         column_name = "numbered"
     class_name = "c%s ordering %s %s" % (column_number, self.order_dir,
                                          column_name)
     return HTML.tag("th", header_label, class_=class_name)
Exemple #15
0
 def render_timestamp_td(self, timestamp):
     import datetime
     if timestamp is None:            
         return HTML.td('')
     if type(timestamp) is not datetime.datetime:
         from dateutil import parser as datetime_parser
         timestamp = datetime_parser.parse(str(timestamp))
     span_class = 'due-date badge'
     
     span = HTML.tag(
         "span",
         c=HTML.literal(timestamp.strftime('%Y-%m-%d %H:%M:%S')),
         class_=span_class,
     )
     return HTML.td(span)
Exemple #16
0
 def _column_format(column_number, i, record):
     from webhelpers2.number import format_byte_size
     size_in_bytes = get_value(record, attribute)
     size = ''
     if size_in_bytes is not None:
         size = format_byte_size(size_in_bytes)
     return HTML.td(size)
Exemple #17
0
 def _column_format(column_number, i, record):
     from webhelpers2.number import format_byte_size
     size_in_bytes = get_value(record, attribute)
     size = ''
     if size_in_bytes is not None:
         size = format_byte_size(size_in_bytes)
     return HTML.td(size)
Exemple #18
0
    def default_header_column_format(self, column_number, column_name, header_label):
        """Override of the ObjectGrid to use <th> for header columns
        """
        if column_name == "_numbered":
            column_name = "numbered"

        if column_name == "_checkbox":
            header_label = checkbox(name="children", title="Select / deselect all", data_toggle="checkbox")
            return HTML.tag("th", header_label)
        elif column_name in self.exclude_ordering:
            class_name = "c%s %s" % (column_number, column_name)
            return HTML.tag("th", header_label, class_=class_name)
        else:
            header_label = HTML(header_label, HTML.tag("span", class_="marker"))
            class_name = "c%s ordering %s" % (column_number, column_name)
            return HTML.tag("th", header_label, class_=class_name)
Exemple #19
0
 def default_column_format(self, column_number, i, record, column_name):
     class_name = "c%s" % column_number
     # first try to lookup property
     col_value = getattr(record, column_name, GRID_NOT_FOUND)
     # if this fails lookup via __getattr__
     if col_value is GRID_NOT_FOUND:
         col_value = getattr(record, "get", dummy_value)(column_name)
     return HTML.tag("td", col_value, class_=class_name)
Exemple #20
0
 def render_format_td(self, format, source):
     span_class = 'label'
     if format is None:
         format = 'unknown'
     if 'wps' in format.lower():
         span_class += ' label-warning'
     elif 'wms' in format.lower():
         span_class += ' label-info'
     elif 'netcdf' in format.lower():
         span_class += ' label-success'
     else:
         span_class += ' label-default'
     anchor = string.Template("""\
     <a class="${span_class}" href="${source}" data-format="${format}">${format}</a>
     """)
     return HTML.td(HTML.literal(anchor.substitute(
         {'source': source, 'span_class': span_class, 'format': format} )))
Exemple #21
0
 def _column_format(column_number, i, record):
     # TODO: avoid database access ... maybe store additional info at job
     userid = get_value(record, attribute)
     label = 'Unknown'
     if userid:
         user = self.request.db.users.find_one(dict(identifier=userid))
         if user:
             label = user.get('login_id')
     return HTML.td(label)
Exemple #22
0
        def _column_format(column_number, i, record):
            import datetime

            timestamp = get_value(record, attribute)

            if timestamp is None:
                return HTML.td('')
            if type(timestamp) is not datetime.datetime:
                from dateutil import parser as datetime_parser
                timestamp = datetime_parser.parse(str(timestamp))
            span_class = 'due-date badge'

            span = HTML.tag(
                "span",
                c=HTML.literal(timestamp.strftime('%Y-%m-%d %H:%M:%S')),
                class_=span_class,
            )
            return HTML.td(span)
Exemple #23
0
 def _column_format(column_number, i, record):
     # TODO: avoid database access ... maybe store additional info at job
     userid = get_value(record, attribute)
     label = 'Unknown'
     if userid:
         user = self.request.db.users.find_one(dict(identifier=userid))
         if user:
             label = user.get('login_id')
     return HTML.td(label)
Exemple #24
0
        def _column_format(column_number, i, record):
            import datetime

            timestamp = get_value(record, attribute)

            if timestamp is None:
                return HTML.td('')
            if type(timestamp) is not datetime.datetime:
                from dateutil import parser as datetime_parser
                timestamp = datetime_parser.parse(str(timestamp))
            span_class = 'due-date badge'

            span = HTML.tag(
                "span",
                c=HTML.literal(timestamp.strftime('%Y-%m-%d %H:%M:%S')),
                class_=span_class,
            )
            return HTML.td(span)
Exemple #25
0
 def hidden_tag(self, *names):
     """
     Convenience for printing all hidden fields in a form inside a
     hidden DIV. Will also render the CSRF hidden field.
     """
     inputs = [self.hidden(name) for name in names]
     inputs.append(self.csrf())
     return HTML.tag("div",
                     tags.literal("".join(inputs)),
                     style="display:none;")
Exemple #26
0
 def __html__(self):
     """Override of the ObjectGrid to use a <thead> so that bootstrap
     renders the styles correctly
     """
     records = []
     # first render headers record
     headers = self.make_headers()
     r = self.default_header_record_format(headers)
     # Wrap the headers in a thead
     records.append(HTML.tag('thead', r))
     # now lets render the actual item grid
     for i, record in enumerate(self.itemlist):
         columns = self.make_columns(i, record)
         if hasattr(self, 'custom_record_format'):
             r = self.custom_record_format(i + 1, record, columns)
         else:
             r = self.default_record_format(i + 1, record, columns)
         records.append(r)
     return HTML(*records)
Exemple #27
0
    def default_header_column_format(self, column_number, column_name,
                                     header_label):
        """Override of the ObjectGrid to use <th> for header columns
        """
        if column_name == "_numbered":
            column_name = "numbered"

        if column_name == "_checkbox":
            header_label = checkbox(name="children",
                                    title="Select / deselect all",
                                    data_toggle="checkbox")
            return HTML.tag("th", header_label)
        elif column_name in self.exclude_ordering:
            class_name = "c%s %s" % (column_number, column_name)
            return HTML.tag("th", header_label, class_=class_name)
        else:
            header_label = HTML(header_label, HTML.tag("span",
                                                       class_="marker"))
            class_name = "c%s ordering %s" % (column_number, column_name)
            return HTML.tag("th", header_label, class_=class_name)
Exemple #28
0
 def group_td(self, col_num, i, item):
     from webhelpers2.html.builder import HTML
     group = item.get('group')
     label = "???"
     if group == Admin:
         label = "Admin"
     elif group == User:
         label = "User"
     elif group == Guest:
         label = "Guest"
     return HTML.td(label)
Exemple #29
0
    def label(self, name, label=None, **attrs):
        """
        Outputs a <label> element.

        `name`  : field name. Automatically added to "for" attribute.

        `label` : if **None**, uses the capitalized field name.
        """
        if 'for_' not in attrs:
            attrs['for_'] = name
        label = label or name.capitalize()
        return HTML.tag("label", label, **attrs)
    def hidden_tag(self, *names):
        """
        Convenience for printing all hidden fields in a form inside a 
        hidden DIV. Will also render the CSRF hidden field.

        :versionadded: 0.4
        """
        inputs = [self.hidden(name) for name in names]
        inputs.append(self.csrf())
        return HTML.tag("div", 
                        tags.literal("".join(inputs)), 
                        style="display:none;")
    def label(self, name, label=None, **attrs):
        """
        Outputs a <label> element.

        `name`  : field name. Automatically added to "for" attribute.

        `label` : if **None**, uses the capitalized field name.
        """
        attrs["for_"] = self._fix_id(attrs.get("for_") or name)

        label = label or name.capitalize()
        return HTML.tag("label", label, **attrs)
Exemple #32
0
 def group_td(self, col_num, i, item):
     from webhelpers2.html.builder import HTML
     group = item.get('group')
     label = "???"
     if group == Admin:
         label = "Admin"
     elif group == Developer:
         label = "Developer"
     elif group == User:
         label = "User"
     elif group == Guest:
         label = "Guest"
     return HTML.td(label)
Exemple #33
0
 def render_format_td(self, format, source):
     span_class = 'label'
     if format is None:
         format = 'unknown'
     if 'wps' in format.lower():
         span_class += ' label-warning'
     elif 'wms' in format.lower():
         span_class += ' label-info'
     elif 'netcdf' in format.lower():
         span_class += ' label-success'
     else:
         span_class += ' label-default'
     anchor = string.Template("""\
     <a class="${span_class}" href="${source}" data-format="${format}">${format}</a>
     """)
     return HTML.td(
         HTML.literal(
             anchor.substitute({
                 'source': source,
                 'span_class': span_class,
                 'format': format
             })))
Exemple #34
0
    def label(self, name, label=None, **attrs):
        """
        Outputs a <label> element.

        `name`  : field name. Automatically added to "for" attribute.

        `label` : if **None**, uses the capitalized field name.
        """
        if 'for_' not in attrs:
            attrs['for_'] = name

        # attrs['for_'] = tags._make_safe_id_component(attrs['for_'])
        label = label or name.capitalize()
        return HTML.tag("label", label, **attrs)
    def errorlist(self, name=None, **attrs):
        """
        Renders errors in a <ul> element. Unless specified in attrs, class
        will be "error".

        If no errors present returns an empty string.

        `name` : errors for name. If **None** all errors will be rendered.
        """

        if name is None:
            errors = self.all_errors()
        else:
            errors = self.errors_for(name)

        if not errors:
            return ''

        content = "\n".join(HTML.tag("li", error) for error in errors)
        
        if 'class_' not in attrs:
            attrs['class_'] = "error"

        return HTML.tag("ul", tags.literal(content), **attrs)
    def label(self, name, label=None, **attrs):
        """
        Outputs a <label> element. 

        `name`  : field name. Automatically added to "for" attribute.

        `label` : if **None**, uses the capitalized field name.
        """
        if 'for_' not in attrs:
            for_ = name.lower()
            if self.id_prefix:
                for_ = self.id_prefix + for_
            attrs['for_'] = for_
            
        label = label or name.capitalize()
        return HTML.tag("label", label, **attrs)
Exemple #37
0
 def __html__(self):
     """Override of the ObjectGrid to use a <thead> so that bootstrap
     renders the styles correctly
     """
     records = []
     # first render headers record
     headers = self.make_headers()
     r = self.default_header_record_format(headers)
     # Wrap the headers in a thead
     records.append(HTML.tag('thead', r))
     # now lets render the actual item grid
     for i, record in enumerate(self.itemlist):
         columns = self.make_columns(i, record)
         if hasattr(self, 'custom_record_format'):
             r = self.custom_record_format(i + 1, record, columns)
         else:
             r = self.default_record_format(i + 1, record, columns)
         records.append(r)
     return HTML(*records)
Exemple #38
0
 def generate_header_link(self, column_number, column, label_text):
     """Override of the ObjectGrid to customize the headers. This is
     mostly taken from the example code in ObjectGrid itself.
     """
     GET = dict(self.request.copy().GET)
     self.order_column = GET.pop("order_col", None)
     self.order_dir = GET.pop("order_dir", None)
     # determine new order
     if column == self.order_column and self.order_dir == "desc":
         new_order_dir = "asc"
     else:
         new_order_dir = "desc"
     self.additional_kw['order_col'] = column
     self.additional_kw['order_dir'] = new_order_dir
     new_url = self.url_generator(_query=self.additional_kw)
     # set label for header with link
     label_text = HTML.tag("a", href=new_url, c=label_text)
     return super(CustomGrid,
                  self).generate_header_link(column_number, column,
                                             label_text)
Exemple #39
0
 def generate_header_link(self, column_number, column, label_text):
     """Override of the ObjectGrid to customize the headers. This is
     mostly taken from the example code in ObjectGrid itself.
     """
     GET = dict(self.request.copy().GET)
     self.order_column = GET.pop("order_col", None)
     self.order_dir = GET.pop("order_dir", None)
     # determine new order
     if column == self.order_column and self.order_dir == "desc":
         new_order_dir = "asc"
     else:
         new_order_dir = "desc"
     self.additional_kw['order_col'] = column
     self.additional_kw['order_dir'] = new_order_dir
     new_url = self.url_generator(_query=self.additional_kw)
     # set label for header with link
     label_text = HTML.tag("a", href=new_url, c=label_text)
     return super(MyGrid, self).generate_header_link(column_number,
                                                     column,
                                                     label_text)
Exemple #40
0
 def numbered_column_format(self, column_number, i, record):
     class_name = "c%s" % (column_number)
     return HTML.tag("td", i, class_=class_name)
Exemple #41
0
 def _column_format(column_number, i, record):
     from phoenix.utils import time_ago_in_words
     timestamp = get_value(record, attribute)
     return HTML.td(time_ago_in_words(timestamp))
Exemple #42
0
 def checkbox_column_format(self, column_number, i, record):
     return HTML.td(
         checkbox(name="children",
                  value=record.get('identifier'),
                  title="Select item"))
Exemple #43
0
 def default_column_format(self, column_number, i, record, column_name):
     class_name = "c%s" % (column_number)
     return HTML.tag("td", record[int(column_name)], class_=class_name)
Exemple #44
0
 def render_td(self, renderer, **data):
     mytemplate = mylookup.get_template(renderer + ".mako")
     return HTML.td(HTML.literal(mytemplate.render(**data)))
Exemple #45
0
 def _column_format(column_number, i, record):
     label = get_value(record, attribute, default or "Missing")
     return HTML.td(label)
 def csrf_token(self, name=None):
     """
     Convenience function. Returns CSRF hidden tag inside hidden DIV.
     """
     return HTML.tag("div", self.csrf(name), style="display:none;")
Exemple #47
0
 def csrf_token(self, name=None):
     """
     Return a hidden field containing the CSRF token, wrapped in an
     invisible div, so that it is valid HTML regardless of context.
     """
     return HTML.tag('div', self.csrf(name), style='display:none;')
Exemple #48
0
 def csrf_token(self, name=None):
     """
     Return a hidden field containing the CSRF token, wrapped in an
     invisible div, so that it is valid HTML regardless of context.
     """
     return HTML.tag('div', self.csrf(name), style='display:none;')
Exemple #49
0
 def default_record_format(self, i, record, columns):
     if i % 2 == 0:
         class_name = "even r%s" % i
     else:
         class_name = "odd r%s" % i
     return HTML.tag("tr", columns, class_=class_name)
Exemple #50
0
 def default_header_record_format(self, headers):
     return HTML.tag("tr", headers, class_="header")
Exemple #51
0
 def render_td(self, renderer, **data):
     mytemplate = self.lookup.get_template(renderer)
     return HTML.td(HTML.literal(mytemplate.render(**data)))
Exemple #52
0
 def _column_format(column_number, i, record):
     from phoenix.utils import time_ago_in_words
     timestamp = get_value(record, attribute)
     return HTML.td(time_ago_in_words(timestamp))