本文整理汇总了Python中yafowil.base.factory函数的典型用法代码示例。如果您正苦于以下问题:Python factory函数的具体用法?Python factory怎么用?Python factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了factory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: array_with_array_with_array_with_leafs
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",
}
开发者ID:bluedynamics,项目名称:yafowil.widget.array,代码行数:25,代码来源:example.py
示例2: image
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,
},
}
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:34,代码来源:example.py
示例3: form
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
开发者ID:renfers,项目名称:ageliaco.rd2,代码行数:26,代码来源:projets.py
示例4: test_compound_blueprint_value_via_compound
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())))
开发者ID:bluedynamics,项目名称:yafowil,代码行数:25,代码来源:test_compound.py
示例5: prepare
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})
开发者ID:kombinat,项目名称:bda.plone.checkout,代码行数:35,代码来源:form.py
示例6: index
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)
开发者ID:Dorianux,项目名称:flask-yafowil,代码行数:34,代码来源:srv.py
示例7: test_extract_dpi_max
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, [])
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:27,代码来源:tests.py
示例8: test_extract_dpi_exact
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, [])
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:29,代码来源:tests.py
示例9: test_extract_size_exact
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, [])
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:28,代码来源:tests.py
示例10: test_render_display
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()))
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:33,代码来源:tests.py
示例11: test_render_with_preset_value_src_property_callable
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()))
开发者ID:bluedynamics,项目名称:yafowil.widget.image,代码行数:29,代码来源:tests.py
示例12: test_div_blueprint_compound_leaf
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(), [])
开发者ID:bluedynamics,项目名称:yafowil,代码行数:30,代码来源:test_compound.py
示例13: prepare
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
开发者ID:AnneGilles,项目名称:cone.app,代码行数:33,代码来源:login.py
示例14: test_render_table
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()))
开发者ID:bluedynamics,项目名称:yafowil,代码行数:25,代码来源:test_table.py
示例15: form
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
开发者ID:attilaolah,项目名称:cone.app,代码行数:30,代码来源:authentication.py
示例16: test_td_blueprint
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>'
)
开发者ID:bluedynamics,项目名称:yafowil,代码行数:25,代码来源:test_table.py
示例17: get_example
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',
}]
开发者ID:bluedynamics,项目名称:yafowil.widget.autocomplete,代码行数:25,代码来源:example.py
示例18: prepare
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
开发者ID:bluedynamics,项目名称:cone.app,代码行数:25,代码来源:test_browser_form.py
示例19: prepare
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
开发者ID:bluedynamics,项目名称:cone.app,代码行数:27,代码来源:test_browser_authoring.py
示例20: get_example
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',
},
]
开发者ID:bluedynamics,项目名称:yafowil.widget.dynatree,代码行数:29,代码来源:example.py
注:本文中的yafowil.base.factory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论