예제 #1
0
def formvalue(formname, fieldname, value):
    """
    >> formvalue <formname> <field> <value>

    Set value of a form field.

    There are some ambiguities in the way formvalue deals with lists:
    'formvalue' will *add* the given value to a list of multiple selection,
    for lists that allow it.

    Forms are matched against 'formname' as follows:
      1. regexp match to actual form name;
      2. if 'formname' is an integer, it's tried as an index.

    Form controls are matched against 'fieldname' as follows:
      1. unique exact match to control name;
      2. unique regexp match to control name;
      3. if fieldname is an integer, it's tried as an index;
      4. unique & exact match to submit-button values.

    Formvalue ignores read-only fields completely; if they're readonly,
    nothing is done, unless the config options ('config' command) are
    changed.

    'formvalue' is available as 'fv' as well.
    """
    form = browser.get_form(formname)
    if form is None:
        raise TwillAssertionError("no matching forms!")

    control = browser.get_form_field(form, fieldname)

    browser.clicked(form, control)
    if isinstance(control, html.CheckboxGroup):
        pass

    elif 'readonly' in control.attrib.keys() and \
        _options['readonly_controls_writeable']:
        print>>OUT, 'forcing read-only form field to writeable'
        del control.attrib['readonly']
        
    elif 'readonly' in control.attrib.keys() or \
        (hasattr(control, 'type') and control.type == 'file'):
        print>>OUT, 'form field is read-only or ignorable; nothing done.'
        return

    if hasattr(control, 'type') and control.type == 'file':
        raise TwillException(
                    'form field is for file upload; use "formfile" instead'
                )

    set_form_control_value(control, value.decode(sys.getdefaultencoding()))
예제 #2
0
def formvalue(formname, fieldname, value):
    """
    >> formvalue <formname> <field> <value>

    Set value of a form field.

    There are some ambiguities in the way formvalue deals with lists:
    'formvalue' will *add* the given value to a list of multiple selection,
    for lists that allow it.

    Forms are matched against 'formname' as follows:
      1. regexp match to actual form name;
      2. if 'formname' is an integer, it's tried as an index.

    Form controls are matched against 'fieldname' as follows:
      1. unique exact match to control name;
      2. unique regexp match to control name;
      3. if fieldname is an integer, it's tried as an index;
      4. unique & exact match to submit-button values.

    Formvalue ignores read-only fields completely; if they're readonly,
    nothing is done, unless the config options ('config' command) are
    changed.

    'formvalue' is available as 'fv' as well.
    """
    form = browser.get_form(formname)
    if form is None:
        raise TwillAssertionError("no matching forms!")

    control = browser.get_form_field(form, fieldname)

    browser.clicked(form, control)
    if isinstance(control, html.CheckboxGroup):
        pass

    elif 'readonly' in control.attrib.keys() and \
        _options['readonly_controls_writeable']:
        print>>OUT, 'forcing read-only form field to writeable'
        del control.attrib['readonly']
        
    elif 'readonly' in control.attrib.keys() or \
        (hasattr(control, 'type') and control.type == 'file'):
        print>>OUT, 'form field is read-only or ignorable; nothing done.'
        return

    if hasattr(control, 'type') and control.type == 'file':
        raise TwillException(
                    'form field is for file upload; use "formfile" instead'
                )

    set_form_control_value(control, value)
예제 #3
0
def formvalue(formname, fieldname, value):
    """
    >> formvalue <formname> <field> <value>

    Set value of a form field.

    There are some ambiguities in the way formvalue deals with lists:
    'formvalue' will *add* the given value to a list of multiple selection,
    for lists that allow it.

    Forms are matched against 'formname' as follows:
      1. regexp match to actual form name;
      2. if 'formname' is an integer, it's tried as an index.

    Form controls are matched against 'fieldname' as follows:
      1. unique exact match to control name;
      2. unique regexp match to control name;
      3. if fieldname is an integer, it's tried as an index;
      4. unique & exact match to submit-button values.

    Formvalue ignores read-only fields completely; if they're readonly,
    nothing is done, unless the config options ('config' command) are
    changed.

    'formvalue' is available as 'fv' as well.
    """
    form = browser.get_form(formname)
    if not form:
        raise TwillAssertionError("no matching forms!")

    control = browser.get_form_field(form, fieldname)

    browser.clicked(form, control)

    if control.readonly and _options['readonly_controls_writeable']:
        print>>OUT, 'forcing read-only form field to writeable'
        control.readonly = False
        
    if control.readonly or isinstance(control, ClientForm.IgnoreControl):
        print>>OUT, 'form field is read-only or ignorable; nothing done.'
        return

    if isinstance(control, ClientForm.FileControl):
        raise TwillException('form field is for file upload; use "formfile" instead')

    set_form_control_value(control, value)