예제 #1
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 = "\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)
예제 #2
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])
예제 #3
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])
예제 #4
0
    def getAdrActions(self, principal):
        rc = []
        adr = principal.getAddress()

        address = {
            'name1': adr.name1,
            'name2': adr.name2,
            'name3': adr.name3,
            'street': adr.street,
            'number': adr.number,
            'zip_code': adr.zip_code,
            'city': adr.city,
            }

        oid = principal.oid
        if not adr or isinstance(adr, (models.AddressTraeger, models.AddressEinrichtung)):
            rc.append(
                    HTML.tag(
                        'a',
                        href="%s/addresses/add?form.field.oid=%s&form.field.mnr=%s" % (self.application_url(), oid, adr.mnr),
                        c="Neue Adresse anlegen",)
                    )
        elif isinstance(adr, models.Address):
            rc.append(
                    HTML.tag(
                        'a',
                        href="%s/addresses/%s/edit" % (self.application_url(), oid),
                        c="Adresse bearbeiten",)
                    )
        return address, rc
예제 #5
0
 def getErrorTag(self, name):
     if self.is_error(name):
         attrs = {}
         attrs['class'] = 'error_list'
         li = HTML.tag('li', self.errors_for(name)[0])
         return HTML.tag('ul', li, **attrs)
     return ''
예제 #6
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)
예제 #7
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)
예제 #8
0
 def render(self, **kwargs):
     html = ''
     checked = kwargs['options'][0][1]
     for label, value in kwargs['options']:
         r = tags.radio(self.name, value, checked=value == checked)
         t = HTML.tag('span', c=label)
         l = HTML.tag('label', c=r+' '+t)
         html += HTML.tag('li', c=l)
     return HTML.tag('ul', class_='inputs-list', c=html)
예제 #9
0
 def render(self, **kwargs):
     html = ''
     checked = kwargs['options'][0][1]
     for label, value in kwargs['options']:
         r = tags.radio(self.name, value, checked=value == checked)
         t = HTML.tag('span', c=label)
         l = HTML.tag('label', c=r+' '+t)
         html += HTML.tag('li', c=l)
     return HTML.tag('ul', class_='inputs-list', c=html)
예제 #10
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)
예제 #11
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)
예제 #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)
예제 #13
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)
예제 #14
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)
예제 #15
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)
예제 #16
0
 def pager(self, q=None):
     '''Returns pager html - for navigating between the pages.
        e.g. Something like this:
          <ul class='pagination pagination-alphabet'>
              <li class="active"><a href="/package/list?page=A">A</a></li>
              <li><a href="/package/list?page=B">B</a></li>
              <li><a href="/package/list?page=C">C</a></li>
                 ...
              <li class="disabled"><a href="/package/list?page=Z">Z</a></li>
              <li><a href="/package/list?page=Other">Other</a></li>
          </ul>
     '''
     if self.item_count < self.paging_threshold:
         return ''
     pages = []
     page = q or self.page
     for letter in self.letters:
         href = url_for(controller=self.controller_name,
                        action='index',
                        page=letter)
         link = HTML.a(href=href, c=letter)
         if letter != page:
             li_class = ''
         else:
             li_class = 'active'
         attributes = {'class_': li_class} if li_class else {}
         page_element = HTML.li(link, **attributes)
         pages.append(page_element)
     ul = HTML.tag('ul', *pages)
     div = HTML.div(ul, class_='pagination pagination-alphabet')
     return div
예제 #17
0
 def pager(self, q=None):
     '''Returns pager html - for navigating between the pages.
        e.g. Something like this:
          <div class='pager'>
              <span class="pager_curpage">A</span>
              <a class="pager_link" href="/package/list?page=B">B</a>
              <a class="pager_link" href="/package/list?page=C">C</a>
                 ...
              <a class="pager_link" href="/package/list?page=Z">Z</a
              <a class="pager_link" href="/package/list?page=Other">Other</a
          </div>
     '''
     if self.item_count < self.paging_threshold:
         return ''
     pages = []
     page = q or self.page
     letters = [char for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] + [self.other_text]
     for letter in letters:
         if letter != page:
             if self.available.get(letter, 0):
                 page_element = HTML.a(class_='pager_link', href=url_for(controller=self.controller_name, action='index', page=letter),c=letter)
             else:
                 page_element = HTML.span(class_="pager_empty", c=letter)
         else:
             page_element = HTML.span(class_='pager_curpage', c=letter)
         pages.append(page_element)
     div = HTML.tag('div', class_='pager', *pages)
     return div
예제 #18
0
    def generate_header_link(self, column_number, column, label_text):
        """ This handles generation of link and then decides to call
        self.default_header_ordered_column_format 
        or 
        self.default_header_column_format 
        based on if current column is the one that is used for sorting or not
        """
        from pylons import url
        # this will handle possible URL generation
        request_copy = dict(self.request.copy().GET)
        self.order_column = request_copy.pop("order_col", None)
        self.order_dir = request_copy.pop("order_dir", None)

        if column == self.order_column and self.order_dir == "asc":
            new_order_dir = "dsc"
        else:
            new_order_dir = "asc"

        url_href = url.current(order_col=column,
                               order_dir=new_order_dir,
                               **request_copy)
        label_text = HTML.tag("a", href=url_href, c=label_text)
        # Is the current column the one we're ordering on?
        if column == self.order_column:
            return self.default_header_ordered_column_format(
                column_number, column, label_text)
        else:
            return self.default_header_column_format(column_number, column,
                                                     label_text)
예제 #19
0
 def generate_header_link(self, column_number, column, label_text):
     """ This handles generation of link and then decides to call
     self.default_header_ordered_column_format 
     or 
     self.default_header_column_format 
     based on if current column is the one that is used for sorting or not
     """ 
     from pylons import url
     # this will handle possible URL generation
     request_copy = dict(self.request.copy().GET) 
     self.order_column = request_copy.pop("order_col", None)
     self.order_dir = request_copy.pop("order_dir", None)
     
     if column == self.order_column and self.order_dir == "asc":
         new_order_dir = "dsc"
     else:
         new_order_dir = "asc"
     
     url_href = url.current(order_col=column, order_dir=new_order_dir,
                            **request_copy)
     label_text = HTML.tag("a", href=url_href, c=label_text)
     # Is the current column the one we're ordering on?
     if column == self.order_column:
         return self.default_header_ordered_column_format(column_number,
                                                          column,
                                                          label_text)
     else:
         return self.default_header_column_format(column_number, column,
                                                  label_text)
예제 #20
0
 def pager(self, q=None):
     '''Returns pager html - for navigating between the pages.
        e.g. Something like this:
          <div class='pager'>
              <span class="pager_curpage">A</span>
              <a class="pager_link" href="/package/list?page=B">B</a>
              <a class="pager_link" href="/package/list?page=C">C</a>
                 ...
              <a class="pager_link" href="/package/list?page=Z">Z</a
              <a class="pager_link" href="/package/list?page=Other">Other</a
          </div>
     '''
     if self.item_count < self.paging_threshold:
         return ''
     pages = []
     page = q or self.page
     letters = [char for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'] + [self.other_text]
     for letter in letters:
         if letter != page:
             page = HTML.a(class_='pager_link', href=url_for(controller='tag', action='index', page=letter), c=letter)
         else:
             page = HTML.span(class_='pager_curpage', c=letter)
         pages.append(page)                           
     div = HTML.tag('div', class_='pager', *pages)
     return div
예제 #21
0
파일: form.py 프로젝트: lowks/pyramid_orb
    def label(self, name, label=None, **attrs):
        if 'for_' not in attrs:
            attrs['for_'] = self._id(None, name.lower())

        column = self.record().schema().column(name)
        label = label or column.displayName()
        return HTML.tag('label', label, **attrs)
예제 #22
0
 def pager(self, q=None):
     '''Returns pager html - for navigating between the pages.
        e.g. Something like this:
          <ul class='pagination pagination-alphabet'>
              <li class="active"><a href="/package/list?page=A">A</a></li>
              <li><a href="/package/list?page=B">B</a></li>
              <li><a href="/package/list?page=C">C</a></li>
                 ...
              <li class="disabled"><a href="/package/list?page=Z">Z</a></li>
              <li><a href="/package/list?page=Other">Other</a></li>
          </ul>
     '''
     if self.item_count < self.paging_threshold:
         return ''
     pages = []
     page = q or self.page
     for letter in self.letters:
         href = url_for(controller=self.controller_name, action='index', page=letter)
         link = HTML.a(href=href, c=letter)
         if letter != page:
             li_class = ''
         else:
             li_class = 'active'
         attributes = {'class_': li_class} if li_class else {}
         page_element = HTML.li(link, **attributes)
         pages.append(page_element)
     ul = HTML.tag('ul', *pages)
     div = HTML.div(ul, class_='pagination pagination-alphabet')
     return div
예제 #23
0
 def getAccountActions(self, account):
     rc = []
     oid = self.request.principal.oid
     rc.append(
             HTML.tag(
                 'a',
                 href="%s/accounts/add?form.field.oid=%s" % (self.application_url(), oid),
                 c="Neuen Benutzer anlegen",)
             )
     if not account:
         rc.append(
                 HTML.tag(
                     'a',
                     href="%s/accounts/add" % self.application_url(),
                     c="Neuen Benutzer anlegen",)
                 )
     return rc
예제 #24
0
파일: forms.py 프로젝트: gmalik9/samplesdb
 def column(self, name, content, cols, inner_cols=None, errors=True):
     "Wraps content in a Foundation column"
     error_content = ''
     if errors:
         error_content = self.error_small(name, cols=inner_cols)
     return HTML.tag(
         'div', tags.literal(content), error_content,
         class_='small-%d columns %s' % (
             cols, 'error' if error_content else ''))
예제 #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.

        :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;")
예제 #26
0
 def column(self, name, content, cols, inner_cols=None, errors=True):
     "Wraps content in a Foundation column"
     error_content = ''
     if errors:
         error_content = self.error_small(name, cols=inner_cols)
     return HTML.tag('div',
                     tags.literal(content),
                     error_content,
                     class_='small-%d columns %s' %
                     (cols, 'error' if error_content else ''))
예제 #27
0
 def getCatActions(self):
     rc = []
     oid = self.request.principal.oid
     session = get_session('ukhvoucher')
     category = session.query(models.Category).get(oid)
     if category:
         rc.append(
                 HTML.tag(
                     'a',
                     href="%s/categories/%s/edit" % (self.application_url(), oid),
                     c="Kontingente bearbeiten",)
                 )
     else:
         rc.append(
                 HTML.tag(
                     'a',
                     href="%s/categories/add?form.field.oid=%s" % (self.application_url(), oid),
                     c="Neue Kontingente anlegen",)
                 )
     return rc
예제 #28
0
def recursive_class_tag(tags, content, **keywords):
    """
    Builds a tag hierarchy where the tags have the
    same attributes.  Order the tags from outer to
    inner.

    Returns a literal object.
    """
    shell = list(reversed(tags))
    shell.insert(0, content)
    return reduce(lambda inner, outer: HTML.tag(outer, c=inner, **keywords), shell)
예제 #29
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.

        :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;")
예제 #30
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.
		"""
		attrs['for_'] = self._fix_id(attrs.get('for_') or name)

		label = label or name.capitalize()
		return HTML.tag("label", label, **attrs)
예제 #31
0
 def getVoucherActions(self):
     rc = []
     oid = self.request.principal.oid
     rc.append(
             HTML.tag(
                 'a',
                 href="%s/account/%s/ask.vouchers" % (self.application_url(), oid),
                 c=u"Zusätzliche Berechtigungsscheine erzeugen",)
             )
     rc.append(
             HTML.tag(
                 'a',
                 href="%s/account/%s/disable.vouchers" % (self.application_url(), oid),
                 c=u"Berechtigungsscheine sperren",)
             )
     rc.append(
             HTML.tag(
                 'a',
                 href="%s/account/%s/disable.charge" % (self.application_url(), oid),
                 c=u"Charge sperren",)
             )
     return rc
예제 #32
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)
예제 #33
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)
예제 #34
0
파일: form.py 프로젝트: yoshrote/columns2
 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 not self.id_prefix \
             else self.id_prefix + name.lower()
         attrs['for_'] = for_
         
     label = label or name.capitalize()
     return HTML.tag("label", label, **attrs)
예제 #35
0
 def due_date_td(self, col_num, i, item):
     """Generate the column for the due date.
     """
     if item.due_date is None:
         return HTML.td('')
     span_class = 'due-date badge'
     if item.past_due:
         span_class += ' badge-important'
     due_date = localize_datetime(item.due_date, self.user_tz)
     span = HTML.tag(
         "span",
         c=HTML.literal(due_date.strftime('%Y-%m-%d %H:%M:%S')),
         class_=span_class,
     )
     return HTML.td(span)
예제 #36
0
    def tags_td(self, col_num, i, item):
        """Generate the column for the tags.
        """
        tag_links = []

        for tag in item.sorted_tags:
            tag_url = '%s/tags/%s' % (self.request.application_url, tag.name)
            tag_class = 'label'
            if self.selected_tag and tag.name == self.selected_tag:
                tag_class += ' label-warning'
            else:
                tag_class += ' label-info'
            anchor = HTML.tag("a", href=tag_url, c=tag.name, class_=tag_class)
            tag_links.append(anchor)
        return HTML.td(*tag_links, _nl=True)
예제 #37
0
파일: forms.py 프로젝트: gmalik9/samplesdb
    def hidden_tag(self, *names):
        """
        Convenience for printing all hidden fields in a form inside a hidden
        DIV. Will also render the CSRF and referal hidden fields if they
        haven't been output explicitly already.

        :versionadded: 0.4
        """
        inputs = [self.hidden(name) for name in names]
        if not self._csrf_done:
            inputs.append(self.csrf())
        if not self._came_from_done:
            inputs.append(self.came_from())
        return HTML.tag(
            'div', tags.literal(''.join(inputs)), style='display:none;')
예제 #38
0
 def due_date_td(self, col_num, i, item):
     """Generate the column for the due date.
     """
     if item.due_date is None:
         return HTML.td('')
     span_class = 'due-date badge'
     if item.past_due:
         span_class += ' badge-important'
     due_date = localize_datetime(item.due_date, self.user_tz)
     span = HTML.tag(
         "span",
         c=HTML.literal(due_date.strftime('%Y-%m-%d %H:%M:%S')),
         class_=span_class,
     )
     return HTML.td(span)
예제 #39
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 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)
예제 #40
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 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)
예제 #41
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.
        """
        label = label or name.capitalize()

        if self.prefix:
            name = self.prefix + name
        if 'for_' not in attrs:
            attrs['for_'] = name

        return HTML.tag("label", label, **attrs)
예제 #42
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:
            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)
예제 #43
0
    def hidden_tag(self, *names):
        """
        Convenience for printing all hidden fields in a form inside a hidden
        DIV. Will also render the CSRF and referal hidden fields if they
        haven't been output explicitly already.

        :versionadded: 0.4
        """
        inputs = [self.hidden(name) for name in names]
        if not self._csrf_done:
            inputs.append(self.csrf())
        if not self._came_from_done:
            inputs.append(self.came_from())
        return HTML.tag('div',
                        tags.literal(''.join(inputs)),
                        style='display:none;')
예제 #44
0
    def tags_td(self, col_num, i, item):
        """Generate the column for the tags.
        """
        tag_links = []

        for tag in item.sorted_tags:
            tag_url = '%s/tags/%s' % (self.request.application_url, tag.name)
            tag_class = 'label'
            if self.selected_tag and tag.name == self.selected_tag:
                tag_class += ' label-warning'
            else:
                tag_class += ' label-info'
            anchor = HTML.tag("a", href=tag_url, c=tag.name,
                              class_=tag_class)
            tag_links.append(anchor)
        return HTML.td(*tag_links, _nl=True)
예제 #45
0
    def tags_td(self, col_num, i, item):
        """Generate the column for the tags.
        
        Apply special tag CSS for currently selected tag matched route '/tags/{tag_name}' 
        """
        tag_links = []

        for tag in item.sorted_tags:
            tag_url = self.request.route_url('taglist', tag_name=tag.name)
            tag_class = 'label'
            if self.selected_tag and tag.name == self.selected_tag:
                tag_class += ' label-warning'
            else:
                tag_class += ' label-info'
            anchor = HTML.tag("a", href=tag_url, c=tag.name, class_=tag_class)
            tag_links.append(anchor)
        return HTML.td(*tag_links, _nl=True)
예제 #46
0
 def due_date_td(self, col_num, i, item):
     """Generate the column for the due date.
     
     Time-Zone Localization is done in the model
     """
     if item.due_date is None:
         return HTML.td('')
     span_class = 'due-date badge'
     if item.past_due:
         span_class += ' badge-important'
     due_date = item.due_date
     span = HTML.tag(
         "span",
         c=HTML.literal(due_date.strftime('%Y-%m-%d %H:%M:%S')),
         class_=span_class,
     )
     return HTML.td(span)
예제 #47
0
 def due_date_td(self, col_num, i, item):
     """Generate the column for the due date.
     
     Time-Zone Localization is done in the model
     """
     if item.due_date is None:
         return HTML.td('')
     span_class = 'due-date badge'
     if item.past_due:
         span_class += ' badge-important'
     due_date = item.due_date 
     span = HTML.tag(
         "span",
         c=HTML.literal(due_date.strftime('%Y-%m-%d %H:%M:%S')),
         class_=span_class,
     )
     return HTML.td(span)
예제 #48
0
파일: forms.py 프로젝트: gmalik9/samplesdb
    def error_small(self, name, cols=None, **attrs):
        """
        Renders the specified error next to a Foundation form control

        `name` : errors for name.
        """
        errors = self.errors_for(name)
        if not errors:
            return ''
        content = []
        for error in errors:
            content.append(HTML(error))
            content.append(tags.BR)
        content = content[:-1]
        attrs = css_add_class(attrs, 'error')
        if cols:
            attrs = css_add_class(attrs, 'small-%d' % cols)
        return HTML.tag('small', *content, **attrs)
예제 #49
0
파일: forms.py 프로젝트: gmalik9/samplesdb
    def label(self, name, label=None, cols=2, inner_cols=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 if label is not None else name.capitalize()
        if inner_cols:
            attrs = css_add_class(attrs, 'small-%d' % inner_cols)
        result = HTML.tag('label', label, **attrs)
        if cols:
            return self.column(name, result, cols, inner_cols, errors=False)
        else:
            return result
예제 #50
0
    def error_small(self, name, cols=None, **attrs):
        """
        Renders the specified error next to a Foundation form control

        `name` : errors for name.
        """
        errors = self.errors_for(name)
        if not errors:
            return ''
        content = []
        for error in errors:
            content.append(HTML(error))
            content.append(tags.BR)
        content = content[:-1]
        attrs = css_add_class(attrs, 'error')
        if cols:
            attrs = css_add_class(attrs, 'small-%d' % cols)
        return HTML.tag('small', *content, **attrs)
예제 #51
0
    def label(self, name, label=None, cols=2, inner_cols=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 if label is not None else name.capitalize()
        if inner_cols:
            attrs = css_add_class(attrs, 'small-%d' % inner_cols)
        result = HTML.tag('label', label, **attrs)
        if cols:
            return self.column(name, result, cols, inner_cols, errors=False)
        else:
            return result
예제 #52
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)
예제 #53
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(TodoGrid,
                  self).generate_header_link(column_number, column,
                                             label_text)
예제 #54
0
 def default_column_format(self, column_number, i, record, column_name):
     class_name = "c%s" % (column_number)
     return HTML.tag("td", getattr(record, column_name), class_=class_name)
예제 #55
0
 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;")
예제 #56
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)
예제 #57
0
 def default_header_record_format(self, headers):
     return HTML.tag("tr", headers, class_="header")
예제 #58
0
 def numbered_column_format(self, column_number, i, record):
     class_name = "c%s" % (column_number)
     return HTML.tag("td", i, class_=class_name)