Example #1
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
Example #2
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)
Example #3
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 ''
    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])
Example #5
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
 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
Example #7
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
Example #8
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)
Example #9
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
    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])
Example #11
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)
Example #12
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)
Example #13
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)
Example #14
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)
Example #15
0
 def _get_active_btn(self, appstruct):
     """
         return the show active button
     """
     active = appstruct['active']
     if active == 'N':
         url = self.request.current_route_path(_query=dict(active="Y"))
         link = HTML.a(u"Afficher les entreprises actives", href=url)
     else:
         url = self.request.current_route_path(_query=dict(active="N"))
         link = HTML.a(u"Afficher les entreprises désactivées", href=url)
     return StaticWidget(link)
Example #16
0
 def _get_archived_btn(self, appstruct):
     """
         return the show archived button
     """
     archived = appstruct['archived']
     if not archived:
         url = self.request.current_route_path(_query=dict(archived="true"))
         link = HTML.a(u"Afficher les projets archivés",  href=url)
     else:
         url = self.request.current_route_path(_query=dict(archived="false"))
         link = HTML.a(u"Afficher les projets actifs", href=url)
     return StaticWidget(link)
Example #17
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)
Example #18
0
 def _get_disabled_btn(self, appstruct):
     """
         return the button to show disabled users
     """
     disabled = appstruct['disabled']
     if disabled == '0':
         url = self.request.current_route_path(_query=dict(disabled="1"))
         link = HTML.a(u"Afficher les comptes désactivés",  href=url)
     else:
         url = self.request.current_route_path(_query=dict(disabled="0"))
         link = HTML.a(u"Afficher uniquement les comptes actifs", href=url)
     return StaticWidget(link)
Example #19
0
 def _get_active_btn(self, appstruct):
     """
         return the show active button
     """
     active = appstruct['active']
     if active == 'N':
         url = self.request.current_route_path(_query=dict(active="Y"))
         link = HTML.a(u"Afficher les entreprises actives",  href=url)
     else:
         url = self.request.current_route_path(_query=dict(active="N"))
         link = HTML.a(u"Afficher les entreprises désactivées", href=url)
     return StaticWidget(link)
Example #20
0
 def _get_disabled_btn(self, appstruct):
     """
         return the button to show disabled users
     """
     disabled = appstruct['disabled']
     if disabled == '0':
         url = self.request.current_route_path(_query=dict(disabled="1"))
         link = HTML.a(u"Afficher les comptes désactivés", href=url)
     else:
         url = self.request.current_route_path(_query=dict(disabled="0"))
         link = HTML.a(u"Afficher uniquement les comptes actifs", href=url)
     return StaticWidget(link)
Example #21
0
 def _get_archived_btn(self, appstruct):
     """
         return the show archived button
     """
     archived = appstruct['archived']
     if not archived:
         url = self.request.current_route_path(_query=dict(archived="true"))
         link = HTML.a(u"Afficher les projets archivés", href=url)
     else:
         url = self.request.current_route_path(_query=dict(
             archived="false"))
         link = HTML.a(u"Afficher les projets actifs", href=url)
     return StaticWidget(link)
Example #22
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)
 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)
Example #24
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)
 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)
Example #26
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)
Example #27
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)
Example #28
0
 def action_td(self, col_num, i, item):
     """Generate the column that has the actions in it.
     """
     return HTML.td(HTML.literal("""\
     <div class="btn-group">
       <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
       Action
       <span class="caret"></span>
       </a>
       <ul class="dropdown-menu" id="%s">
         <li><a class="todo-edit" href="#">Edit</a></li>
         <li><a class="todo-complete" href="#">Complete</a></li>
       </ul>
     </div>
     """ % item.id))
Example #29
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)
Example #30
0
 def submit(self,
            name='submit',
            value='Submit',
            id=None,
            cols=10,
            inner_cols=None,
            cancel=True,
            **attrs):
     """
     Outputs submit button.
     """
     id = id or name
     attrs = css_add_class(attrs, 'button')
     attrs = css_add_class(attrs, 'radius')
     if inner_cols:
         attrs = css_add_class(attrs, 'small-%d' % inner_cols)
     result = tags.submit(name, self.value(name, value), id, **attrs)
     if cancel and self.form.came_from:
         cancel_attrs = attrs.copy()
         cancel_attrs = css_add_class(cancel_attrs, 'secondary')
         result += literal(' ') + HTML.a(
             'Cancel', href=self.form.came_from, **cancel_attrs)
     if cols:
         return self.column(name, result, cols, inner_cols, errors=False)
     else:
         return result
Example #31
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)
Example #32
0
    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)
Example #33
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)
Example #34
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)
 def action_td(self, col_num, i, item):
     """Generate the column that has the actions in it.
     """
     return HTML.td(
         HTML.literal("""\
     <div class="btn-group">
       <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
       Action
       <span class="caret"></span>
       </a>
       <ul class="dropdown-menu" id="%s">
         <li><a class="todo-edit" href="#">Edit</a></li>
         <li><a class="todo-complete" href="#">Complete</a></li>
       </ul>
     </div>
     """ % item.id))
Example #36
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
 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)
    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)
Example #39
0
    def error_flashes(self, name=None, **attrs):
        """
        Renders errors as Foundation flash messages.

        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)
        content = [
            HTML.div(error, class_='alert-box alert', **attrs)
            for error in errors
        ]
        return HTML(*content)
 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)
Example #41
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 ''))
    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)
Example #43
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)
Example #44
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 ''))
Example #45
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;")
 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)
Example #47
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
Example #48
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)
Example #49
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;")
Example #50
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)
Example #51
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
Example #52
0
 def make_columns(self, i, record):
     columns = []
     for col_num, column in enumerate(self.columns):
         if column in self.column_formats:
             r = self.column_formats[column](col_num + 1,
                                             self.calc_row_no(i, column),
                                             record)
         else:
             r = self.default_column_format(col_num + 1,
                                            self.calc_row_no(i, column),
                                            record, column)
         columns.append(r)
     return HTML(*columns)
    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 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)
Example #55
0
 def tidy_value(cls, value):
     # objeto exposto
     if isinstance(value, ExposedObject):
         name = getattr(value, 'nome', getattr(value, 'descricao', False))
         ref = cls.tidy_label(value.__class__.__name__) + \
             (" %s" % unicode(value.id)) + \
             (u"" if not name else (u": %s" % name))
         uri = getattr(value, 'uri', False)
         return link_to_if(uri, ref, uri)
     # listas
     elif isinstance(value, Iterable) and \
             not isinstance(value, basestring) and \
             not isinstance(value, dict):
         return ul(cls.tidy_value(item) for item in value)
     # dicionarios
     elif isinstance(value, dict):
         return HTML.dl(HTML(*[
             HTML(*[HTML.dt(cls.tidy_label(k)), HTML.dd(cls.tidy_value(v))])
                 for k, v in value.items()]
         ))
     # datas
     elif isinstance(value, date):
         return value.strftime(u"%d/%m/%Y")
     # decimais (em geral, valores moeda)
     elif isinstance(value, Decimal):
         return u"R$ "+locale.format(u"%.02f",value, grouping=True, monetary=True)
     # booleanos
     elif isinstance(value, bool):
         return u"Verdadeiro" if value else u"Falso"
     # strings longas
     elif isinstance(value, unicode) and len(value) > 140:
         return format_paragraphs(value, preserve_lines=True)
     # caso geral
     else:
         uri = getattr(value, 'uri', False)
         return link_to_if(uri, value, uri)
    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)
Example #57
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)
Example #58
0
    def _get_archived_btn(self, appstruct):
        """
            return the show archived button
        """
        archived = appstruct['archived']
        args = self.request.GET.copy()
        args.pop('archived', None)
        if not archived:
            args['archived'] = 'true'
            msg = u"Afficher les projets archivés"
        else:
            msg = u"Afficher les projets actifs"

        url = self.request.current_route_path(_query=args)
        link = HTML.a(msg, href=url)
        return StaticWidget(link)
Example #59
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;')
Example #60
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)