Exemplo n.º 1
0
 def buttons(form):
     if not form.submit_fields: return ''
     result = [ htmltag('div', _class='buttons', align=form.buttons_align) ]
     buttons = [ f.html for f in form.submit_fields ]
     result.extend(buttons)
     result.append(Html('\n</div>'))
     return htmljoin(result)
Exemplo n.º 2
0
 def buttons(form):
     if not form.submit_fields: return ''
     result = [htmltag('div', _class='buttons', align=form.buttons_align)]
     buttons = [f.html for f in form.submit_fields]
     result.extend(buttons)
     result.append(Html('\n</div>'))
     return htmljoin(result)
def format_line(frame, line, syntax_error_offset=None):
    if frame is not None:
        f_locals = frame.f_locals
        f_globals = frame.f_globals
    else: f_locals = f_globals = {}
    result = []
    prev = __undefined__
    for kind, start, end, x in parse_line(line):
        if syntax_error_offset is not None and start <= syntax_error_offset < end:
            i = syntax_error_offset - start
            if x[i] != '\n': y = x[:i] + syntax_error_html % x[i] + x[i+1:]
            else: y = x[:i] + syntax_error_html % ' ' + x[i:]
        else: y = x
        if kind == 'string': result.append(str_html % y)
        elif kind == 'comment': result.append(comment_html % y)
        elif kind == 'other': result.append(y)
        elif kind == 'keyword': result.append(keyword_html % y); prev = __undefined__
        elif frame is None: result.append(y)
        else:
            if kind == 'identifier':
                obj = f_locals.get(x, __undefined__)
                if obj is __undefined__: obj = f_globals.get(x, __undefined__)
                if obj is __undefined__:
                    builtins = f_globals.get('__builtins__')
                    if isinstance(builtins, dict): obj = builtins.get(x, __undefined__)
                    else: obj = getattr(builtins, x, __undefined__)
            elif kind == 'attribute':
                if prev is __undefined__: obj = __undefined__
                else: obj = getattr(prev, x, __undefined__)
            else: assert False  # pragma: no cover
            if obj is __undefined__: title = 'undefined'
            else: title = repr2(obj)
            result.append(ident_html % (title, y))
            prev = obj
    return htmljoin(result)
Exemplo n.º 4
0
 def tag(field):
     result = []
     result.append(
         htmltag('input',
                 field.attrs,
                 name=field.name,
                 value='yes',
                 checked=bool(field.value),
                 type=field.HTML_TYPE))
     return htmljoin(result)
Exemplo n.º 5
0
 def table(form):
     result = []
     for f in form.fields:
         classes = f.__class__.__name__.lower() + '-field-row'
         if f.error_text: classes += ' has-error'
         result.extend((Html('\n<tr class="%s">\n<th>' % classes), f.label,
                        Html('</th>\n<td>'), f.tag))
         error = f.error
         if error: result.append(error)
         result.append(Html('</td></tr>'))
     return htmljoin(result)
Exemplo n.º 6
0
 def tag(field):
     result = [ htmltag('div', field.attrs, _class='checkboxes') ]
     selection = field.value
     for value, description, key in field.options:
         result.append(Html('<div class="checkboxgroup-item">'))
         result.append(htmltag('input', name=field.name, type='checkbox',
                               value=value, checked=(value in selection)))
         result.append(Html('<span class="value">%s</span></div>') % description)
     result.append(Html('</div>'))
     result.append(htmltag('input', name='.'+field.name, type='hidden', value=''))
     return htmljoin(result)
Exemplo n.º 7
0
 def tag(field):
     result = [ htmltag('div', field.attrs, _class='radiobuttons') ]
     selected = field.value
     for value, description, key in field.options:
         result.append(Html('<div class="radiobutton">'))
         result.append(htmltag('input', type='radio', name=field.name,
                               value=key, checked=(value==selected)))
         result.append(Html('<span class="value">%s</span></div>') % description)
     result.append(Html('</div>'))
     result.append(htmltag('input', name='.'+field.name, type='hidden', value=''))
     return htmljoin(result)
Exemplo n.º 8
0
 def __unicode__(form):
     if form.buttons_align is None:
           buttons = Html('\n<tr><td>&nbsp;</td><td>%s</td></tr>') % form.buttons
     else: buttons = Html('\n<tr><td colspan="2">%s</td></tr>') % form.buttons
     return htmljoin([ form.header, form.error,
                       Html('\n<table>'),
                       form.table,
                       buttons,
                       Html('\n</table>\n'),
                       form.footer,
                       Html('\n')])
Exemplo n.º 9
0
 def table(form):
     result = []
     for f in form.fields:
         classes = f.__class__.__name__.lower() + '-field-row'
         if f.error_text: classes += ' has-error'
         result.extend((Html('\n<tr class="%s">\n<th>' % classes),
                        f.label, Html('</th>\n<td>'), f.tag))
         error = f.error
         if error: result.append(error)
         result.append(Html('</td></tr>'))
     return htmljoin(result)
Exemplo n.º 10
0
 def tag(composite):
     result = [Html('\n<table><tr>')]
     if composite.show_headers:
         for i, field in enumerate(composite.fields):
             if isinstance(field, Submit): label = Html('&nbsp;')
             else: label = field._get_label(colon=False)
             result.append(Html('<th>%s</th>') % label)
         result.append(Html('</tr>\n<tr>'))
     for i, field in enumerate(composite.fields):
         result.append(Html('<td>%s</td>') % field.tag)
     result.append(Html('\n</tr></table>\n'))
     return htmljoin(result)
Exemplo n.º 11
0
 def tag(composite):
     result = [ Html('\n<table><tr>') ]
     if composite.show_headers:
         for i, field in enumerate(composite.fields):
             if isinstance(field, Submit): label = Html('&nbsp;')
             else: label = field._get_label(colon=False)
             result.append(Html('<th>%s</th>') % label)
         result.append(Html('</tr>\n<tr>'))
     for i, field in enumerate(composite.fields):
         result.append(Html('<td>%s</td>') % field.tag)
     result.append(Html('\n</tr></table>\n'))
     return htmljoin(result)
Exemplo n.º 12
0
 def __unicode__(form):
     if form.buttons_align is None:
         buttons = Html(
             '\n<tr><td>&nbsp;</td><td>%s</td></tr>') % form.buttons
     else:
         buttons = Html('\n<tr><td colspan="2">%s</td></tr>') % form.buttons
     return htmljoin([
         form.header, form.error,
         Html('\n<table>'), form.table, buttons,
         Html('\n</table>\n'), form.footer,
         Html('\n')
     ])
Exemplo n.º 13
0
 def tag(grid):
     result = [ Html('\n<table><tr>') ]
     for column in grid.columns:
         result.append(Html('<th>%s</th>') % column)
     result.append(Html('</tr>\n'))
     for row, row_class in izip(grid._rows, cycle(('odd', 'even'))):
         result.append(Html('<tr class="%s">') % row_class)
         for field in row:
             if field is None: result.append(Html('<td>&nbsp;</td>'))
             else: result.append(Html('<td>%s</td>') % field.tag)
         result.append(Html('</tr>\n'))
     result.append(Html('</table>\n'))
     return htmljoin(result)
Exemplo n.º 14
0
 def tag(grid):
     result = [Html('\n<table><tr>')]
     for column in grid.columns:
         result.append(Html('<th>%s</th>') % column)
     result.append(Html('</tr>\n'))
     for row, row_class in izip(grid._rows, cycle(('odd', 'even'))):
         result.append(Html('<tr class="%s">') % row_class)
         for field in row:
             if field is None: result.append(Html('<td>&nbsp;</td>'))
             else: result.append(Html('<td>%s</td>') % field.tag)
         result.append(Html('</tr>\n'))
     result.append(Html('</table>\n'))
     return htmljoin(result)
Exemplo n.º 15
0
 def tag(field): # for Select and MultiSelect
     result = [ htmltag('select', field.attrs, name=field.name, multiple=isinstance(field, MultiSelect)) ]
     value = field.value
     if isinstance(field, MultiSelect): selection = value
     elif value is None: selection = set()
     else: selection = set((value,))
     for value, description, key in field.options:
         if key == description: key = None
         result.append(htmltag('option', selected=(value in selection), value=key))
         result.append(description)
         result.append(Html('</option>'))
     result.append(Html('</select>'))
     return htmljoin(result)
Exemplo n.º 16
0
def link(*args, **kwargs):
    if not args:
        raise TypeError(
            'link() function requires at least one positional argument')
    attrs = None

    last = args[-1]
    if isinstance(last, BoundMarkup):
        description = last()
        args = (description, ) + args[:-1]

    first = args[0]
    if hasattr(first, 'routes'):
        func = first
        args = args[1:]
        if func.__doc__ is None: description = func.__name__
        else: description = Html(func.__doc__.split('\n', 1)[0])
    elif len(args) > 1 and hasattr(args[1], 'routes'):
        description = tostring(first)
        func = args[1]
        args = args[2:]
    elif len(args) > 2 and hasattr(args[2], 'routes'):
        attrs = args[1]
        if isinstance(attrs, basestring): attrs = {'class': attrs}
        elif not hasattr(attrs, 'items'):
            raise TypeError('Invalid second argument of link() function: %r' %
                            second)
        description = tostring(first)
        func = args[2]
        args = args[3:]
    elif isinstance(first, basestring):
        func = link_funcs.get(first)
        if func is not None: return func(*args[1:], **kwargs)
        if first.endswith('.css'):
            if kwargs: raise TypeError('Unexpected key arguments')
            return css_link(args)
        if first.endswith('.js'):
            if len(args) > 1:
                raise TypeError('Unexpected positional arguments')
            if kwargs: raise TypeError('Unexpected key arguments')
            return script_link(first)
        raise TypeError('Invalid arguments of link() function')

    href = url(func, *args, **kwargs)
    return htmljoin(
        [htmltag('a', attrs, href=href), description,
         Html('</a>')])
Exemplo n.º 17
0
 def tag(field):
     result = [htmltag('div', field.attrs, _class='radiobuttons')]
     selected = field.value
     for value, description, key in field.options:
         result.append(Html('<div class="radiobutton">'))
         result.append(
             htmltag('input',
                     type='radio',
                     name=field.name,
                     value=key,
                     checked=(value == selected)))
         result.append(
             Html('<span class="value">%s</span></div>') % description)
     result.append(Html('</div>'))
     result.append(
         htmltag('input', name='.' + field.name, type='hidden', value=''))
     return htmljoin(result)
Exemplo n.º 18
0
 def tag(field):
     result = [htmltag('div', field.attrs, _class='checkboxes')]
     selection = field.value
     for value, description, key in field.options:
         result.append(Html('<div class="checkboxgroup-item">'))
         result.append(
             htmltag('input',
                     name=field.name,
                     type='checkbox',
                     value=value,
                     checked=(value in selection)))
         result.append(
             Html('<span class="value">%s</span></div>') % description)
     result.append(Html('</div>'))
     result.append(
         htmltag('input', name='.' + field.name, type='hidden', value=''))
     return htmljoin(result)
Exemplo n.º 19
0
 def tag(field):  # for Select and MultiSelect
     result = [
         htmltag('select',
                 field.attrs,
                 name=field.name,
                 multiple=isinstance(field, MultiSelect))
     ]
     value = field.value
     if isinstance(field, MultiSelect): selection = value
     elif value is None: selection = set()
     else: selection = set((value, ))
     for value, description, key in field.options:
         if key == description: key = None
         result.append(
             htmltag('option', selected=(value in selection), value=key))
         result.append(description)
         result.append(Html('</option>'))
     result.append(Html('</select>'))
     return htmljoin(result)
Exemplo n.º 20
0
def link(*args, **kwargs):
    if not args: raise TypeError('link() function requires at least one positional argument')
    attrs = None

    last = args[-1]
    if isinstance(last, BoundMarkup):
        description = last()
        args = (description,) + args[:-1]

    first = args[0]
    if hasattr(first, 'routes'):
        func = first
        args = args[1:]
        if func.__doc__ is None: description = func.__name__
        else: description = Html(func.__doc__.split('\n', 1)[0])
    elif len(args) > 1 and hasattr(args[1], 'routes'):
        description = tostring(first)
        func = args[1]
        args = args[2:]
    elif len(args) > 2 and hasattr(args[2], 'routes'):
        attrs = args[1]
        if isinstance(attrs, basestring): attrs = {'class': attrs}
        elif not hasattr(attrs, 'items'):
            raise TypeError('Invalid second argument of link() function: %r' % second)
        description = tostring(first)
        func = args[2]
        args = args[3:]
    elif isinstance(first, basestring):
        func = link_funcs.get(first)
        if func is not None: return func(*args[1:], **kwargs)
        if first.endswith('.css'):
            if kwargs: raise TypeError('Unexpected key arguments')
            return css_link(args)
        if first.endswith('.js'):
            if len(args) > 1: raise TypeError('Unexpected positional arguments')
            if kwargs: raise TypeError('Unexpected key arguments')
            return script_link(first)
        raise TypeError('Invalid arguments of link() function')

    href = url(func, *args, **kwargs)
    return htmljoin([htmltag('a', attrs, href=href), description, Html('</a>')])
Exemplo n.º 21
0
def format_line(frame, line, syntax_error_offset=None):
    if frame is not None:
        f_locals = frame.f_locals
        f_globals = frame.f_globals
    else:
        f_locals = f_globals = {}
    result = []
    prev = __undefined__
    for kind, start, end, x in parse_line(line):
        if syntax_error_offset is not None and start <= syntax_error_offset < end:
            i = syntax_error_offset - start
            if x[i] != '\n': y = x[:i] + syntax_error_html % x[i] + x[i + 1:]
            else: y = x[:i] + syntax_error_html % ' ' + x[i:]
        else: y = x
        if kind == 'string': result.append(str_html % y)
        elif kind == 'comment': result.append(comment_html % y)
        elif kind == 'other': result.append(y)
        elif kind == 'keyword':
            result.append(keyword_html % y)
            prev = __undefined__
        elif frame is None:
            result.append(y)
        else:
            if kind == 'identifier':
                obj = f_locals.get(x, __undefined__)
                if obj is __undefined__: obj = f_globals.get(x, __undefined__)
                if obj is __undefined__:
                    builtins = f_globals.get('__builtins__')
                    if isinstance(builtins, dict):
                        obj = builtins.get(x, __undefined__)
                    else:
                        obj = getattr(builtins, x, __undefined__)
            elif kind == 'attribute':
                if prev is __undefined__: obj = __undefined__
                else: obj = getattr(prev, x, __undefined__)
            else: assert False  # pragma: no cover
            if obj is __undefined__: title = 'undefined'
            else: title = repr2(obj)
            result.append(ident_html % (title, y))
            prev = obj
    return htmljoin(result)
Exemplo n.º 22
0
 def __unicode__(composite):
     return htmljoin((composite.label, composite.tag, composite.error))
Exemplo n.º 23
0
 def __unicode__(field):
     return htmljoin((field.label, field.tag, field.error))
Exemplo n.º 24
0
 def __unicode__(field):
     return htmljoin((field.label, field.tag, field.error))
Exemplo n.º 25
0
 def tag(field):
     result = [htmltag('textarea', field.attrs, name=field.name)]
     if field.value is not None: result.append(field.value)
     result.append(Html('</textarea>'))
     return htmljoin(result)
Exemplo n.º 26
0
 def tag(field):
     result = [ htmltag('textarea', field.attrs, name=field.name) ]
     if field.value is not None: result.append(field.value)
     result.append(Html('</textarea>'))
     return htmljoin(result)
Exemplo n.º 27
0
 def tag(field):
     result = []
     result.append(htmltag('input', field.attrs, name=field.name,
                           value='yes', checked=bool(field.value),
                           type = field.HTML_TYPE))
     return htmljoin(result)
Exemplo n.º 28
0
 def __unicode__(composite):
     return htmljoin((composite.label, composite.tag, composite.error))
Exemplo n.º 29
0
 def hidden(composite):
     return htmljoin(field.html for field in composite.hidden_fields)
Exemplo n.º 30
0
 def hidden(composite):
     return htmljoin(field.html for field in composite.hidden_fields)