Ejemplo n.º 1
0
 def prepare(self):
     action = make_url(self.request, node=self.model, resource='login')
     form = factory(
         u'form',
         name='loginform',
         props={
             'action': action
         })
     form['user'] = factory(
         'field:label:error:text',
         props = {
             'required': 'No username given',
             'label': 'Username',
         })    
     form['password'] = factory(
         'field:label:*credentials:error:password',
         props = {
             'required': 'No password given',
             'label': 'Password',
         },
         custom = {
             'credentials': ([self.login], [], [], []),
         })
     form['login'] = factory(
         'submit',
         props = {
             'action': 'login',
             'expression': True,
             'handler': self.noop,
             'next': self.next,
             'label': 'Login',
         })
     self.form = form
Ejemplo n.º 2
0
def array_with_array_with_array_with_leafs():
    form = factory("fieldset", name="yafowil.widget.array_with_array_with_array_with_leafs")
    value = [[["1", "2"], ["3"]], [["4", "5"]]]
    arr_1 = form["array_1"] = factory(
        "#array",
        value=value,
        props={"label": "Array 1", "help": "This is Array 1", "required": "Array 1 must not be empty"},
    )
    arr_2 = arr_1["array_2"] = factory(
        "help:error:array",
        props={"label": "Array 2", "help": "This is Array 2", "required": "Array 2 must not be empty"},
    )
    arr_3 = arr_2["array_3"] = factory(
        "help:error:array",
        props={"label": "Array 3", "help": "This is Array 3", "required": "Array 3 must not be empty"},
    )
    arr_3["textfield"] = factory(
        "#arrayfield:text",
        props={"label": "Text Field", "help": "This is the text field", "required": "Text Field is required"},
    )
    return {
        "widget": form,
        "doc": DOC_ARRAY_WITH_ARRAY_WITH_ARRAY_WITH_LEAFS,
        "title": "Single fields in 3-dimensional array",
    }
Ejemplo n.º 3
0
    def prepare(self):
        resource = 'add'
        if self.model.__name__ is not None:
            resource = 'edit'

            # XXX: tmp - load props each time they are accessed.
            self.model.attrs.context.load()

        action = make_url(self.request, node=self.model, resource=resource)
        form = factory(u'form',
                       name='userform',
                       props={
                           'action': action,
                           'class': 'ajax',
                       })
        settings = self.model.root['settings']
        attrmap = settings.attrs.users_form_attrmap
        if not attrmap:
            return form
        schema = self.schema
        required = self._required_fields
        protected = self._protected_fields
        default_chain = 'field:label:error:mode:text'
        for key, val in attrmap.items():
            field = schema.get(key, dict())
            chain = field.get('chain', default_chain)
            props = dict()
            props['label'] = val
            props['html5required'] = False
            if key in required:
                props['required'] = 'No %s defined' % val
            props.update(field.get('props', dict()))
            value = UNSET
            if resource == 'edit':
                if key in protected:
                    props['mode'] = 'display'
                value = self.model.attrs.get(key, u'')
            form[key] = factory(chain,
                                value=value,
                                props=props,
                                custom=field.get('custom', dict()))
        form['save'] = factory('submit',
                               props={
                                   'action': 'save',
                                   'expression': True,
                                   'handler': self.save,
                                   'next': self.next,
                                   'label': 'Save',
                               })
        if resource == 'add':
            form['cancel'] = factory('submit',
                                     props={
                                         'action': 'cancel',
                                         'expression': True,
                                         'handler': None,
                                         'next': self.next,
                                         'label': 'Cancel',
                                         'skip': True,
                                     })
        self.form = form
Ejemplo n.º 4
0
    def test_compound_blueprint_extraction(self):
        compound = factory('compound', name='COMPOUND')
        compound['inner'] = factory('text', value='value1')
        compound['inner2'] = factory('error:text',
                                     value='value2',
                                     props={'required': True})

        # Extract Compound with empty request
        data = compound.extract({})
        self.assertEqual(data.name, 'COMPOUND')
        self.assertEqual(data.value, UNSET)
        expected = odict()
        expected['inner'] = UNSET
        expected['inner2'] = UNSET
        self.assertEqual(data.extracted, expected)
        self.assertEqual(data.errors, [])

        inner_data = data['inner']
        self.assertEqual(inner_data.name, 'inner')
        self.assertEqual(inner_data.value, 'value1')
        self.assertEqual(inner_data.extracted, UNSET)
        self.assertEqual(inner_data.errors, [])

        # Extract with a value in request
        request = {
            'COMPOUND.inner': 'newvalue',
            'COMPOUND.inner2': '',
        }
        data = compound.extract(request)
        data_inner = data['inner']
        self.assertEqual(data_inner.name, 'inner')
        self.assertEqual(data_inner.value, 'value1')
        self.assertEqual(data_inner.extracted, 'newvalue')
        self.assertEqual(data_inner.errors, [])

        data_inner2 = data['inner2']
        self.assertEqual(data_inner2.name, 'inner2')
        self.assertEqual(data_inner2.value, 'value2')
        self.assertEqual(data_inner2.extracted, '')
        self.assertEqual(data_inner2.errors,
                         [ExtractionError('Mandatory field was empty')])

        expected = odict()
        expected['inner'] = 'newvalue'
        expected['inner2'] = ''
        self.assertEqual(data.extracted, expected)

        self.check_output(
            """
        <div>
          <input class="text" id="input-COMPOUND-inner" name="COMPOUND.inner"
                 type="text" value="newvalue"/>
          <div class="error">
            <div class="errormessage">Mandatory field was empty</div>
            <input class="required text" id="input-COMPOUND-inner2"
                   name="COMPOUND.inner2" required="required"
                   type="text" value=""/>
          </div>
        </div>
        """, fxml('<div>' + compound(data=data) + '</div>'))
Ejemplo n.º 5
0
    def form(self):
        form = factory('form',
            name='search',
            props={
                'action': self._form_action,
            })

        form['searchterm'] = factory(
            'field:label:error:text',
            props={
                'label': MessageFactory(u'Rechercher dans les projets:'),
                'field.class': 'myFieldClass',
                'text.class': 'myInputClass',
                'size': '20',
        })
        form['submit'] = factory(
            'field:submit',
            props={
                'label':  MessageFactory(u'Lancer la recherche'),
                'submit.class': '',
                'handler': self._form_handler,
                'action': 'search'
        })

        controller = Controller(form, self.request)
        return controller.rendered
Ejemplo n.º 6
0
 def test_compound_blueprint_value_via_compound(self):
     # Render Compound with values set via compound widget
     value = {
         'inner': 'Value 1 from parent',
         'inner2': 'Value 2 from parent',
     }
     compound = factory(
         'compound',
         name='COMPOUND',
         value=value)
     compound['inner'] = factory('text')
     compound['inner2'] = factory(
         'text',
         props={
             'required': True
         })
     self.check_output("""
     <div>
       <input class="text" id="input-COMPOUND-inner" name="COMPOUND.inner"
              type="text" value="Value 1 from parent"/>
       <input class="required text" id="input-COMPOUND-inner2"
              name="COMPOUND.inner2" required="required" type="text"
              value="Value 2 from parent"/>
     </div>
     """, fxml(tag('div', compound())))
Ejemplo n.º 7
0
 def prepare(self):
     if not readcookie(self.request):
         raise Redirect(self.context.absolute_url())
     checkout = self.form_context is CHECKOUT
     form_class = checkout and 'mode_edit' or 'mode_display'
     self.form = factory('#form', name='checkout', props={
         'action': self.form_action,
         'class_add': form_class})
     for fields_factory in self.provider_registry:
         fields_factory(self.context, self.request).extend(self.form)
     # checkout data input
     if checkout:
         self.form['checkout_back'] = factory('submit', props={
             'label': _('back', 'Back'),
             'action': 'checkout_back',
             'handler': None,
             'next': self.checkout_back,
             'skip': True})
         self.form['next'] = factory('submit', props={
             'label': _('next', 'Next'),
             'action': 'next',
             'handler': None,
             'next': self.checkout_summary})
     # checkout confirmation
     else:
         self.form['confirm_back'] = factory('submit', props={
             'label': _('back', 'Back'),
             'action': 'confirm_back',
             'handler': None,
             'next': self.confirm_back})
         self.form['finish'] = factory('submit', props={
             'label': _('finish', 'Order now'),
             'action': 'finish',
             'handler': self.finish,
             'next': self.checkout_done})
Ejemplo n.º 8
0
def index():
    #o = {}
    #o = WerkzeugRequestAdapter(request)
    # if request.method == 'POST':
    #     pass
    
    form = factory(u'form', name='helloworld', props={
        'action': url_for("index")})  # was app.config["URL"]

    form['hello'] = factory('field:label:error:text',
        value='preset value',
        props={
            'label': 'Enter some text',
            'required': 'Some Text is required in order to process'})

    form['file'] = factory('field:label:error:file', props={
        'label': 'File Upload',
        'required': 'File is required'})

    form['submit'] = factory('field:submit', props={
        'label': 'store value',
        'action': 'save',
        'handler': store,
        'next': next})
    
    #import pdb; pdb.set_trace() 
    controller = Controller(form, request)
    if controller.next:
        #redirect(controller.next)
        o = controller.next
    else:
        o = controller.rendered

    return render_template("index.html", session=session,o=o)
Ejemplo n.º 9
0
 def test_extract_dpi_max(self):
     # Maximum DPI
     image = factory(
         'image',
         name='image',
         props={
             'maxdpi': (60, 60)
         })
     request = {
         'image': {
             'file': StringIO(self.dummy_png),
             'mimetype': 'image/png'
         }
     }
     data = image.extract(request)
     self.assertEqual(
         data.errors,
         [ExtractionError('Image must have a maximum of 60 x 60 DPI')]
     )
     image = factory(
         'image',
         name='image',
         props={
             'maxdpi': (80, 80)
         })
     data = image.extract(request)
     self.assertEqual(data.errors, [])
Ejemplo n.º 10
0
 def test_extract_dpi_exact(self):
     # Exact DPI
     image = factory(
         'image',
         name='image',
         props={
             'mindpi': (60, 60),
             'maxdpi': (60, 60)
         })
     request = {
         'image': {
             'file': StringIO(self.dummy_png),
             'mimetype': 'image/png'
         }
     }
     data = image.extract(request)
     self.assertEqual(
         data.errors,
         [ExtractionError('Image must have a resolution of 60 x 60 DPI')]
     )
     image = factory(
         'image',
         name='image',
         props={
             'mindpi': (72, 72),
             'maxdpi': (72, 72)
         })
     data = image.extract(request)
     self.assertEqual(data.errors, [])
Ejemplo n.º 11
0
 def test_extract_size_exact(self):
     image = factory(
         'image',
         name='image',
         props={
             'minsize': (40, 40),
             'maxsize': (40, 40)
         })
     request = {
         'image': {
             'file': StringIO(self.dummy_png),
             'mimetype': 'image/png'
         }
     }
     data = image.extract(request)
     self.assertEqual(
         data.errors,
         [ExtractionError('Image must have a size of 40 x 40 pixel')]
     )
     image = factory(
         'image',
         name='image',
         props={
             'minsize': (50, 50),
             'maxsize': (50, 50)
         })
     data = image.extract(request)
     self.assertEqual(data.errors, [])
Ejemplo n.º 12
0
    def test_render_display(self):
        # Render in display mode
        form = factory(
            'form',
            name='myform',
            props={
                'action': 'myaction'
            })
        form['image'] = factory(
            'image',
            value={
                'file': StringIO(self.dummy_png),
                'mimetype': 'image/png'
            },
            props={
                'src': 'http://www.example.com/someimage.png',
                'alt': 'Alternative text'
            },
            mode='display')
        self.check_output("""
        <form action="myaction" enctype="multipart/form-data" id="form-myform"
              method="post" novalidate="novalidate">
          <img alt="Alternative text"
               src="http://www.example.com/someimage.png"/>
        </form>
        """, fxml(form()))

        # Rendering is skipped if no source
        form['image'].attrs['src'] = None
        self.check_output("""
        <form action="myaction" enctype="multipart/form-data"
              id="form-myform" method="post" novalidate="novalidate"/>
        """, fxml(form()))
Ejemplo n.º 13
0
 def test_render_with_preset_value_src_property_callable(self):
     # Src property can be callable
     form = factory(
         'form',
         name='myform',
         props={
             'action': 'myaction'
         })
     form['image'] = factory(
         'image',
         value={
             'file': StringIO(self.dummy_png),
             'mimetype': 'image/png'
         },
         props={
             'src': lambda w, d: 'http://www.example.com/otherimage.png',
             'alt': 'Alternative text'
         })
     self.check_output("""
     <form action="myaction" enctype="multipart/form-data" id="form-myform"
           method="post" novalidate="novalidate">
       <img alt="Alternative text" class="image-preview"
            id="image-preview-myform-image"
            src="http://www.example.com/otherimage.png?nocache=..."/>
       <input accept="image/*" class="image" id="input-myform-image"
              name="myform.image" type="file"/>
       ...
     </form>
     """, fxml(form()))
Ejemplo n.º 14
0
    def test_div_blueprint_compound_leaf(self):
        # Div blueprint as compound, but with ``leaf`` property set. Causes
        # ``hybrid_renderer`` and ``hybrid_extractor`` to skip auto delegating
        # to ``compound_renderer`` and ``compound_extractor``
        div = factory(
            'div',
            name='DIV_COMPOUND_LEAF',
            props={
                'leaf': True
            })
        div['inner'] = factory(
            'text',
            value='value1')
        div['inner2'] = factory(
            'text',
            value='value2',
            props={
                'required': True
            })
        self.assertEqual(div(), '<div></div>')

        data = div.extract({
            'DIV_COMPOUND_LEAF.inner': '1',
            'DIV_COMPOUND_LEAF.inner2': '2',
        })
        self.assertEqual(data.name, 'DIV_COMPOUND_LEAF')
        self.assertEqual(data.value, UNSET)
        self.assertEqual(data.extracted, UNSET)
        self.assertEqual(data.errors, [])
        self.assertEqual(data.keys(), [])
Ejemplo n.º 15
0
def image():
    name = 'yafowil.widget.image.image'
    image_name = name + '.jpg'
    image_path = os.path.join(runtime_images_dir(), image_name)
    def get_value(widget, data):
        image_value = UNSET
        if os.path.exists(image_path):
            image_data = read_image(name)
            image_value = {
                'file': StringIO(image_data),
                'mimetype': 'image/jpg',
            }
        return image_value
    def get_src(widget, data):
        if os.path.exists(image_path):
            return image_name
    form = factory('fieldset', name=name)
    form['image'] = factory('#field:image', value=get_value, props={
        'label': 'Image',
        'required': 'No Image uploaded',
        'maxsize': (1024, 768),
        'scales': {'default': (400, 400)},
        'src': get_src,
        'error.class': 'help-block',
    })
    return {
        'widget': form,
        'doc': DOC_IMAGE,
        'title': 'Image',
        'handler': save_image,
        'routes': {
            image_name: image_response,
        },
    }
Ejemplo n.º 16
0
 def prepare(self):
     self.form = form = factory('form', name='someform')
     form['somefield'] = factory(
         'text',
         props={
             'label': 'Field'
         })
Ejemplo n.º 17
0
    def test_fieldset_blueprint(self):
        compound = factory('fieldset',
                           'COMPOUND',
                           props={'legend': 'Some Test'})
        compound['inner'] = factory('text', 'inner', 'value')
        compound['inner2'] = factory('text', 'inner2', 'value2')
        self.check_output(
            """
        <fieldset id="fieldset-COMPOUND">
          <legend>Some Test</legend>
          <input class="text" id="input-COMPOUND-inner" name="COMPOUND.inner"
                 type="text" value="value"/>
          <input class="text" id="input-COMPOUND-inner2" name="COMPOUND.inner2"
                 type="text" value="value2"/>
        </fieldset>
        """, fxml(compound()))

        # Structural fieldset renders without id attribute
        compound = factory('fieldset', 'COMPOUND', props={'structural': True})
        self.assertEqual(compound(), '<fieldset></fieldset>')

        # Fieldset display renderers are the same as fieldset edit renderers
        compound = factory('fieldset',
                           'COMPOUND',
                           props={'legend': 'Some Test'},
                           mode='display')
        self.check_output(
            """
        <fieldset id="fieldset-COMPOUND">
          <legend>Some Test</legend>
        </fieldset>
        """, fxml(compound()))
Ejemplo n.º 18
0
 def test_render_with_preset_value_src_property(self):
     # If file URL of existing image is known, ``src`` property can be set
     # do display image above controls
     form = factory(
         'form',
         name='myform',
         props={
             'action': 'myaction'
         })
     form['image'] = factory(
         'image',
         value={
             'file': StringIO(self.dummy_png),
             'mimetype': 'image/png'
         },
         props={
             'src': 'http://www.example.com/someimage.png',
             'alt': 'Alternative text'
         })
     self.check_output("""
     <form action="myaction" enctype="multipart/form-data" id="form-myform"
           method="post" novalidate="novalidate">
       <img alt="Alternative text" class="image-preview"
            id="image-preview-myform-image"
            src="http://www.example.com/someimage.png?nocache=..."/>
       <input accept="image/*" class="image" id="input-myform-image"
              name="myform.image" type="file"/>
       ...
     </form>
     """, fxml(form()))
Ejemplo n.º 19
0
 def prepare(self):
     form = factory(
         u'form',
         name='addform',
         props={
             'action': self.nodeurl
         })
     form['id'] = factory(
         'field:label:text',
         props={
             'label': 'Id',
         })
     form['title'] = factory(
         'field:label:text',
         props={
             'label': 'Title',
         })
     form['add'] = factory(
         'submit',
         props={
             'action': 'add',
             'expression': True,
             'handler': self.add,
             'next': self.next,
             'label': 'Add',
         })
     self.form = form
Ejemplo n.º 20
0
 def form(self):
     form = factory(u'form',
                    name='loginform',
                    props={'action': self.nodeurl})
     form['__do_login'] = factory('hidden', value='true')
     form['user'] = factory(
         'field:label:error:text',
         props = {
             'required': 'No username given',
             'label': 'Username',
         })    
     form['password'] = factory(
         'field:label:*credentials:error:password',
         props = {
             'required': 'No password given',
             'label': 'Password',
         },
         custom = {
             'credentials': ([self.authenticated], [], [], []),
         })
     form['login'] = factory(
         'submit',
         props = {
             'action': 'login',
             'expression': True,
             'handler': None,
             'next': None,
             'label': 'Login',
         })
     return form
Ejemplo n.º 21
0
 def test_render_table(self):
     form = factory(
         'form',
         name='myform',
         props={
             'action': 'myaction',
         })
     form['table'] = factory('table')
     form['table']['row1'] = factory('tr')
     form['table']['row1']['field1'] = factory(
         'td:text',
         name='field1')
     self.check_output("""
     <form action="myaction" enctype="multipart/form-data" id="form-myform"
           method="post" novalidate="novalidate">
       <table>
         <tr>
           <td>
             <input class="text" id="input-myform-table-row1-field1"
                    name="myform.table.row1.field1" type="text" value=""/>
           </td>
         </tr>
       </table>
     </form>
     """, fxml(form()))
Ejemplo n.º 22
0
    def test_td_blueprint(self):
        td = factory(
            'td',
            name='foo')
        self.assertEqual(td(), '<td></td>')

        td = factory(
            'td',
            name='foo',
            mode='display')
        self.assertEqual(td(), '<td></td>')

        td = factory(
            'td',
            name='foo',
            props={
                'id': 'id',
                'class': 'css',
                'colspan': 2,
                'rowspan': 2,
            })
        self.assertEqual(
            td(),
            '<td class="css" colspan="2" id="id" rowspan="2"></td>'
        )
Ejemplo n.º 23
0
    def test_th_blueprint(self):
        th = factory(
            'th',
            name='foo')
        self.assertEqual(th(), '<th></th>')

        th = factory(
            'th',
            name='foo',
            mode='display')
        self.assertEqual(th(), '<th></th>')

        th = factory(
            'th',
            name='foo',
            props={
                'id': 'id',
                'class': 'css',
                'colspan': 2,
                'rowspan': 2,
            })
        self.assertEqual(
            th(),
            '<th class="css" colspan="2" id="id" rowspan="2"></th>'
        )
Ejemplo n.º 24
0
 def prepare(self):
     form = factory(
         u'form',
         name='subscriptionform',
         props={
             'action': self.nodeurl,
             'class': 'foo',
             'class_add': 'bar'
         })
     form['email'] = factory(
         'field:label:error:text',
         props={
             'required': 'No email given',
             'label': 'E-Mail',
         })
     form['subscribe'] = factory(
         'submit',
         props={
             'action': 'subscribe',
             'expression': True,
             'handler': self.subscribe,
             'next': self.next,
             'label': 'Subscribe',
         })
     self.form = form
Ejemplo n.º 25
0
def get_example():
    part1 = factory(u'fieldset', name='yafowilwidgetdynatree.local')
    part1['local'] = factory('#field:dynatree', props={
        'label': 'Select single value',
        'value': '',
        'source': sample_tree,
    })
    part2 = factory(u'fieldset', name='yafowilwidgetdynatree.remote')
    part2['remote'] = factory('#field:dynatree', props={
        'label': 'Select multiple',
        'value': '',
        'source': 'yafowil.widget.dynatree.json',
        'selectMode': 2,
    })
    routes = {
        'yafowil.widget.dynatree.json': json_response,
    }
    return [
        {
            'widget': part1,
            'doc': DOC_LOCAL,
            'title': 'Static Tree',
        }, {
            'widget': part2,
            'routes': routes,
            'doc': DOC_DYNAMIC,
            'title': 'Tree via JSON',
        },
    ]
def get_example():
    static_ac = factory('#field:autocomplete', name='static', props={
        'label': 'Enter some text (local, lorem ipsum)',
        'value': '',
        'source': lipsum,
    })
    json_ac = factory('#field:autocomplete', name='json', props={
        'label': 'Enter some text (remote listdir)',
        'value': '',
        'source': 'yafowil.widget.autocomplete.json',
        'minLength': 1,
    })
    routes = {
        'yafowil.widget.autocomplete.json': json_response,
    }
    return [{
        'widget': static_ac,
        'doc': DOC_STATIC,
        'title': 'Static autocomplete',
    }, {
        'widget': json_ac,
        'routes': routes,
        'doc': DOC_JSON,
        'title': 'JSON data autocomplete',
    }]
Ejemplo n.º 27
0
 def form(self):
     resource = 'add'
     if self.model.__name__ is not None:
         resource = 'edit'
         
         # XXX: tmp - load props each time they are accessed.
         self.model.attrs.context.load()
         
     action = make_url(self.request, node=self.model, resource=resource)
     form = factory(
         u'form',
         name='userform',
         props={'action': action})
     settings = self.model.root['settings']
     attrmap = settings.attrs.users_form_attrmap
     if not attrmap:
         return form
     schema = self.schema
     required = self._required_fields
     protected = self._protected_fields
     default_chain = 'field:error:label:mode:text'
     for key, val in attrmap.items():
         field = schema.get(key, dict())
         chain = field.get('chain', default_chain)
         props = dict()
         props['label'] = val
         if key in required:
             props['required'] = 'No %s defined' % val
         props.update(field.get('props', dict()))
         value = UNSET
         if resource == 'edit':
             if key in protected:
                 props['mode'] = 'display'
             value = self.model.attrs.get(key, u'')
         form[key] = factory(
             chain,
             value=value,
             props=props,
             custom=field.get('custom', dict()))
     form['save'] = factory(
         'submit',
         props = {
             'action': 'save',
             'expression': True,
             'handler': self.save,
             'next': self.next,
             'label': 'Save',
         })
     if resource =='add':
         form['cancel'] = factory(
             'submit',
             props = {
                 'action': 'cancel',
                 'expression': True,
                 'next': self.next,
                 'label': 'Cancel',
                 'skip': True,
             })
     return form
def get_example():
    part = factory(u'fieldset', name='yafowilwidgetautosuggest')
    part['text'] = factory('field:label:error:autosuggest', props={
        'label': 'Enter some text',
        'source': sorted((u'Weißburgunder', u'Welschriesling',
                          u'Sauvingnon Blanc', u'Sämling', u'Scheurebe',
                          u'Traminer', u'Morrilon', u'Muskateller'))})
    return [{'widget': part, 'doc': 'TODO'}]
Ejemplo n.º 29
0
def richtext():
    part = factory(u'fieldset', name='yafowilwidgetrichtext')
    part['richtext'] = factory('#field:richtext', props={
        'label': 'Richtext field',
        'required': 'Text is required'})
    return {'widget': part,
            'doc': DOC_RICHTEXT,
            'title': 'Richtext'}
Ejemplo n.º 30
0
 def test_compound_blueprint_value_conflict(self):
     # ValueError if value for a compound member is defined both
     value = {'inner': 'Value 1 from parent'}
     compound = factory('compound', name='COMPOUND', value=value)
     compound['inner'] = factory('text', value='value1')
     err = self.expect_error(ValueError, compound)
     msg = "Both compound and compound member provide a value for 'inner'"
     self.assertEqual(str(err), msg)
Ejemplo n.º 31
0
    def test_div_blueprint_as_leaf(self):
        # Div blueprint as leaf
        input = factory(
            'div:text',
            name='DIV',
            value='1')
        self.check_output("""
        <div>
          <input class="text" id="input-DIV" name="DIV"
                 type="text" value="1"/>
        </div>
        """, fxml(input()))

        data = input.extract({
            'DIV': '2',
        })
        self.assertEqual(data.name, 'DIV')
        self.assertEqual(data.value, '1')
        self.assertEqual(data.extracted, '2')
        self.assertEqual(data.errors, [])

        # Empty div
        input = factory(
            'div',
            name='DIV')
        self.assertEqual(input(), '<div></div>')

        # Div with data attributes
        input = factory(
            'div',
            name='DIV',
            props={
                'data': {
                    'foo': 'bar'
                }
            })
        self.assertEqual(input(), "<div data-foo='bar'></div>")

        # Display mode
        div = factory(
            'div',
            name='DIV',
            props={
                'class': 'foo'
            },
            mode='display')
        self.assertEqual(div(), '<div class="foo"></div>')

        input = factory(
            'div:text',
            name='DIV',
            value='1',
            mode='display')
        self.check_output("""
        <div>
          <div class="display-text" id="display-DIV">1</div>
        </div>
        """, fxml(input()))
Ejemplo n.º 32
0
    def test_edit_renderer(self):
        # Render widget
        widget = factory('cron', name='cronwidget')
        self.check_output(
            """
        <div class="crontab widget" id="input-cronwidget">
          <div class="cron-value minute">
            <input class="hidden" id="input-cronwidget-minute"
                   name="cronwidget.minute" type="hidden" value=""/>
            <button class="btn btn-sm edit">Minute</button>
          </div>
          <div class="cron-value hour">
            <input class="hidden" id="input-cronwidget-hour"
                   name="cronwidget.hour" type="hidden" value=""/>
            <button class="btn btn-sm edit">Hour</button>
          </div>
          <div class="cron-value dom">
            <input class="hidden" id="input-cronwidget-dom"
                   name="cronwidget.dom" type="hidden" value=""/>
            <button class="btn btn-sm edit">Day of Month</button>
          </div>
          <div class="cron-value month">
            <input class="hidden" id="input-cronwidget-month"
                   name="cronwidget.month" type="hidden" value=""/>
            <button class="btn btn-sm edit">Month</button>
          </div>
          <div class="cron-value dow">
            <input class="hidden" id="input-cronwidget-dow"
                   name="cronwidget.dow" type="hidden" value=""/>
            <button class="btn btn-sm edit">Day of Week</button>
          </div>
          <div class="cron-value year">
            <input class="hidden" id="input-cronwidget-year"
                   name="cronwidget.year" type="hidden" value=""/>
            <button class="btn btn-sm edit">Year</button>
          </div>
          <div class="editarea"/>
        </div>
        """, fxml(widget()))

        # Render with JS config properties
        widget = factory('cron',
                         name='cronwidget',
                         props={
                             'lang': 'de',
                             'start_year': 2010,
                             'end_year': 2020
                         })
        self.check_output(
            """
        <div class="crontab widget"
             data-end_year='2020'
             data-lang='de'
             data-start_year='2010'
             id="input-cronwidget">...</div>
        """, widget())
Ejemplo n.º 33
0
    def test_time_format_tuple(self):
        # Format tuple. Preset and extraction value is (hh, mm)
        widget = factory(
            'time',
            name='t',
            props={
                'format': 'tuple'
            })
        self.assertEqual(widget(), (
            '<input class="time timeinput" id="input-t" name="t" '
            'size="5" type="text" value="" />'
        ))
        data = widget.extract({'t': '2:30'})
        self.assertEqual(
            [data.name, data.value, data.extracted, data.errors],
            ['t', UNSET, (2, 30), []]
        )

        widget = factory(
            'time',
            name='t',
            value=(5, 30),
            props={
                'format': 'tuple'
            })
        self.assertEqual(widget(), (
            '<input class="time timeinput" id="input-t" name="t" size="5" '
            'type="text" value="05:30" />'
        ))
        data = widget.extract({'t': '2:30'})
        self.assertEqual(widget(data=data), (
            '<input class="time timeinput" id="input-t" name="t" size="5" '
            'type="text" value="02:30" />'
        ))

        widget = factory(
            'time',
            name='t',
            value=(0, 0),
            props={
                'format': 'tuple'
            })
        self.assertEqual(widget(), (
            '<input class="time timeinput" id="input-t" name="t" size="5" '
            'type="text" value="00:00" />'
        ))
        data = widget.extract({'t': ''})
        self.assertEqual(
            [data.name, data.value, data.extracted, data.errors],
            ['t', (0, 0), UNSET, []]
        )
        data = widget.extract({'t': '1:0'})
        self.assertEqual(
            [data.name, data.value, data.extracted, data.errors],
            ['t', (0, 0), (1, 0), []]
        )
Ejemplo n.º 34
0
    def test_time_display(self):
        # Render display mode without value
        widget = factory('time', 't', mode='display')
        self.assertEqual(widget(), '')

        # Render display mode with value
        widget = factory('time', 't', value='02:02', mode='display')
        self.assertEqual(widget(),
           '<div class="display-time" id="display-t">02:02</div>'
        )
Ejemplo n.º 35
0
def array_with_compounds():
    form = factory("fieldset", name="yafowil.widget.array.array_with_compounds")
    value = [{"f1": "Value 1.1 F1", "f2": "Value 1.2 F2"}, {"f1": "Value 2.1 F1", "f2": "Value 2.2 F2"}]
    arr = form["array"] = factory(
        "#array", value=value, props={"label": "Compound Array", "required": "Array must at least contain one entry"}
    )
    comp = arr["compound"] = factory("compound")
    comp["f1"] = factory("#arrayfield:text", props={"label": "Field 1"})
    comp["f2"] = factory("#arrayfield:text", props={"label": "Field 2", "required": "Field 2 is required"})
    return {"widget": form, "doc": DOC_ARRAY_WITH_COMPOUNDS, "title": "Compound field array"}
Ejemplo n.º 36
0
    def test_compound_blueprint_structural_children(self):
        # Compound with structural compound as child
        value = {
            'inner': 'Value 1 from parent',
            'inner2': 'Value 2 from parent',
        }
        compound = factory('compound', name='COMPOUND', value=value)
        structural = compound['STRUCTURAL'] = factory(
            'compound', props={'structural': True})
        structural['inner'] = factory('text')
        structural['inner2'] = factory('text', props={'required': True})
        self.check_output(
            """
        <div>
          <input class="text" id="input-COMPOUND-inner" name="COMPOUND.inner"
                 type="text" value="Value 1 from parent"/>
          <input class="required text" id="input-COMPOUND-inner2"
                 name="COMPOUND.inner2" required="required" type="text"
                 value="Value 2 from parent"/>
        </div>
        """, fxml(tag('div', compound())))

        self.assertEqual(compound.treerepr().split('\n'), [
            "<class 'yafowil.base.Widget'>: COMPOUND",
            "  <class 'yafowil.base.Widget'>: STRUCTURAL",
            "    <class 'yafowil.base.Widget'>: inner",
            "    <class 'yafowil.base.Widget'>: inner2", ""
        ])

        data = compound.extract({
            'COMPOUND.inner': 'newvalue',
            'COMPOUND.inner2': '',
        })
        self.assertEqual(data.name, 'COMPOUND')
        self.assertEqual(data.value, {
            'inner2': 'Value 2 from parent',
            'inner': 'Value 1 from parent'
        })
        expected = odict()
        expected['inner'] = 'newvalue'
        expected['inner2'] = ''
        self.assertEqual(data.extracted, expected)

        data_inner = data['inner']
        self.assertEqual(data_inner.name, 'inner')
        self.assertEqual(data_inner.value, 'Value 1 from parent')
        self.assertEqual(data_inner.extracted, 'newvalue')
        self.assertEqual(data_inner.errors, [])

        data_inner2 = data['inner2']
        self.assertEqual(data_inner2.name, 'inner2')
        self.assertEqual(data_inner2.value, 'Value 2 from parent')
        self.assertEqual(data_inner2.extracted, '')
        self.assertEqual(data_inner2.errors,
                         [ExtractionError('Mandatory field was empty')])
Ejemplo n.º 37
0
    def test_tbody_blueprint(self):
        tbody = factory(
            'tbody',
            name='foo')
        self.assertEqual(tbody(), '<tbody></tbody>')

        tbody = factory(
            'tbody',
            name='foo',
            mode='display')
        self.assertEqual(tbody(), '<tbody></tbody>')
Ejemplo n.º 38
0
    def test_thead_blueprint(self):
        thead = factory(
            'thead',
            name='foo')
        self.assertEqual(thead(), '<thead></thead>')

        thead = factory(
            'thead',
            name='foo',
            mode='display')
        self.assertEqual(thead(), '<thead></thead>')
Ejemplo n.º 39
0
    def test_PrincipalIdFieldFactory(self):
        class PrincipalAddForm(Tile):
            action_resource = 'add'

        class PrincipalEditForm(Tile):
            action_resource = 'edit'

        factory = PrincipalIdFieldFactory(PrincipalExistsExtractor)

        # principal add form
        form = PrincipalAddForm()
        form.model = BaseNode()
        form.request = self.layer.new_request()
        widget = factory(form, 'Principal ID', UNSET)
        self.assertEqual(widget.blueprints, [
            'field', '*ascii', '*exists', 'label', 'error', 'text'
        ])
        self.assertEqual(widget.getter, UNSET)
        self.assertEqual(widget.properties, {
            'label': 'Principal ID',
            'required': 'no_field_value_defined',
            'ascii': True
        })
        self.assertEqual(
            widget.custom['ascii']['extractors'],
            [ascii_extractor]
        )
        self.assertTrue(isinstance(
            widget.custom['exists']['extractors'][0],
            PrincipalExistsExtractor
        ))
        self.assertEqual(widget.mode, 'edit')

        # principal edit form
        form = PrincipalEditForm()
        form.model = BaseNode()
        form.request = self.layer.new_request()
        widget = factory(form, 'Principal ID', 'pid')
        self.assertEqual(widget.getter, 'pid')
        self.assertEqual(widget.properties, {
            'label': 'Principal ID',
            'required': 'no_field_value_defined',
            'ascii': True
        })
        self.assertEqual(
            widget.custom['ascii']['extractors'],
            [ascii_extractor]
        )
        self.assertTrue(isinstance(
            widget.custom['exists']['extractors'][0],
            PrincipalExistsExtractor
        ))
        self.assertEqual(widget.mode, 'display')
Ejemplo n.º 40
0
def password():
    comp = factory('compound', name='yafowil-password')
    comp['password'] = factory('#field:password',
                               props={
                                   'label': 'Password Input',
                                   'help': 'Field for password',
                               })
    return {
        'widget': comp,
        'doc': DOC_PASSWORD,
        'title': 'Password',
    }
Ejemplo n.º 41
0
def url():
    comp = factory('compound', name='yafowil-url')
    comp['password'] = factory('#field:url',
                               props={
                                   'label': 'URL Input',
                                   'help': 'Field for URL',
                               })
    return {
        'widget': comp,
        'doc': DOC_URL,
        'title': 'URL',
    }
Ejemplo n.º 42
0
def email():
    comp = factory('compound', name='yafowil-email')
    comp['email'] = factory('#field:email',
                            props={
                                'label': 'E-Mail Input',
                                'help': 'E-Mail Address Field',
                            })
    return {
        'widget': comp,
        'doc': DOC_EMAIL,
        'title': 'Email',
    }
Ejemplo n.º 43
0
def time_example():
    form = factory('fieldset', name='yafowil.widget.datetime.time')
    form['time'] = factory('#field:time',
                           props={
                               'label': 'Select time',
                               'required': 'Time Field is required',
                               'timepicker': True,
                           })
    return {
        'widget': form,
        'doc': DOC_TIME,
        'title': 'Time',
    }
Ejemplo n.º 44
0
def integer():
    comp = factory('compound', name='yafowil-integer')
    comp['intnumber'] = factory('#field:number',
                                props={
                                    'label': 'Number Input (int)',
                                    'datatype': 'integer',
                                    'help': 'Field for integer input',
                                })
    return {
        'widget': comp,
        'doc': DOC_INT,
        'title': 'Integer',
    }
Ejemplo n.º 45
0
def plaintext():
    comp = factory('compound', name='yafowil-plaintext')
    comp['plain'] = factory('#field:text',
                            props={
                                'label': 'Plain Text Input',
                                'required': 'Input is required',
                                'help': 'Simple Plain Text Field',
                            })
    return {
        'widget': comp,
        'doc': DOC_PLAIN_TEXT,
        'title': 'Plain Text',
    }
Ejemplo n.º 46
0
def textarea():
    comp = factory('compound', name='yafowil-textarea')
    comp['textarea'] = factory('#field:textarea',
                               props={
                                   'label': 'Textarea',
                                   'help': 'Textarea field',
                                   'rows': 5,
                               })
    return {
        'widget': comp,
        'doc': DOC_TEXTAREA,
        'title': 'Textarea',
    }
Ejemplo n.º 47
0
def number():
    comp = factory('compound', name='yafowil-number')
    comp['number'] = factory('#field:number',
                             props={
                                 'label': 'Number Input (float)',
                                 'help':
                                 'Field for floating point number input',
                             })
    return {
        'widget': comp,
        'doc': DOC_NUMBER,
        'title': 'Number',
    }
def get_example():
    part = factory(u'fieldset', name='yafowilwidgetautosuggest')
    part['text'] = factory('field:label:error:autosuggest',
                           props={
                               'label':
                               'Enter some text',
                               'source':
                               sorted((u'Weißburgunder', u'Welschriesling',
                                       u'Sauvingnon Blanc', u'Sämling',
                                       u'Scheurebe', u'Traminer', u'Morrilon',
                                       u'Muskateller'))
                           })
    return [{'widget': part, 'doc': 'TODO'}]
Ejemplo n.º 49
0
 def prepare(self):
     form = factory(
         u'form',
         name='protectedattributesform',
         props={
             'action': self.nodeurl,
         })
     form['protectedfield'] = factory(
         u'field:label:text',
         value=u'Protectedfield',
         mode=self.mode_for('protectedfield')
     )
     self.form = form
Ejemplo n.º 50
0
 def prepare(self):
     form = factory(
         u'form',
         name='camefromnextform',
         props={'action': self.nodeurl})
     form['next'] = factory(
         'submit',
         props={
             'action': 'next',
             'expression': True,
             'next': self.next,
             'label': 'Next',
         })
     self.form = form
Ejemplo n.º 51
0
    def test_reference_selected(self):
        request = self.layer.new_request()

        widget = factory('reference', name='ref')
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&selected="'
            ) > -1)

        widget.getter = ['3604702a-b177-42de-8694-d81e2d993633', 'Label']
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&'
                'selected=3604702a-b177-42de-8694-d81e2d993633"') > -1)

        request.params['ref'] = 'Item'
        request.params['ref.uid'] = '745dd2ed-74ad-449b-b55b-b240709b2b0e'
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&'
                'selected=745dd2ed-74ad-449b-b55b-b240709b2b0e"') > -1)

        request = self.layer.new_request()

        widget = factory('reference', name='ref', props={'multivalued': True})
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&selected="'
            ) > -1)
        del widget.attrs['vocabulary']

        widget.getter = ['5f94f75c-4aea-4dc7-a31b-6152e8f89d00']
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&'
                'selected=5f94f75c-4aea-4dc7-a31b-6152e8f89d00"') > -1)
        del widget.attrs['vocabulary']

        request.params['ref-exists'] = 'exists'
        request.params['ref'] = ['e2121521-60a9-4fe6-babf-0f86881c3d6a']
        data = widget.extract(request)
        self.assertTrue(
            widget(data=data).find(
                'ajax:target="http://example.com/?referencable=&root=/&'
                'selected=e2121521-60a9-4fe6-babf-0f86881c3d6a"') > -1)