def render_field(parser, token):
    """
    Render a form field using given attribute-value pairs

    Takes form field as first argument and list of attribute-value pairs for
    all other arguments.  Attribute-value pairs should be in the form of
    attribute=value or attribute="a value" for assignment and attribute+=value
    or attribute+="value" for appending.
    """
    error_msg = '%r tag requires a form field followed by a list of attributes and values in the form attr="value"' % token.split_contents()[0]
    try:
        bits = token.split_contents()
        tag_name = bits[0]
        form_field = bits[1]
        attr_list = bits[2:]
    except ValueError:
        raise TemplateSyntaxError(error_msg)

    form_field = parser.compile_filter(form_field)

    set_attrs = []
    append_attrs = []
    for pair in attr_list:
        match = ATTRIBUTE_RE.match(pair)
        if not match:
            raise TemplateSyntaxError(error_msg + ": %s" % pair)
        dct = match.groupdict()
        attr, sign, value = \
            dct['attr'], dct['sign'], parser.compile_filter(dct['value'])
        if sign == "=":
            set_attrs.append((attr, value))
        else:
            append_attrs.append((attr, value))

    return FieldAttributeNode(form_field, set_attrs, append_attrs)
def render_field ( parser , token ) : error_msg = '%r tag requires a form field followed by a list of attributes and values in the form attr="value"' % token . split_contents ( ) [ 0 ] try : bits = token . split_contents ( ) tag_name = bits [ 0 ] form_field = bits [ 1 ] attr_list = bits [ 2 : ] except ValueError : raise TemplateSyntaxError ( error_msg ) form_field = parser . compile_filter ( form_field ) set_attrs = [ ] append_attrs = [ ] for pair in attr_list : match = ATTRIBUTE_RE . match ( pair ) if not match : raise TemplateSyntaxError ( error_msg + ": %s" % pair ) dct = match . groupdict ( ) attr , sign , value = dct [ 'attr' ] , dct [ 'sign' ] , parser . compile_filter ( dct [ 'value' ] ) if sign == "=" : set_attrs . append ( ( attr , value ) ) else : append_attrs . append ( ( attr , value ) ) return FieldAttributeNode ( form_field , set_attrs , append_attrs )
Render a form field using given attribute-value pairs

    Takes form field as first argument and list of attribute-value pairs for
    all other arguments.  Attribute-value pairs should be in the form of
    attribute=value or attribute="a value" for assignment and attribute+=value
    or attribute+="value" for appending.