dolmen.widget.file is a package that walks hand-in-hand with dolmen.file. It provides a useable and pluggable way to render the dolmen.file.FileField in a z3c.form.Form, using Grok (through megrok.z3cform.base)
Example
We are going to develop here a small example, to demonstrate the use of dolmen.widget.file. First, we need to create a model content with a file field:
>>> import dolmen.file >>> import grokcore.component as grok >>> from zope.interface import Interface >>> from zope.schema.fieldproperty import FieldProperty >>> class ITravelMount(Interface): ... luggage = dolmen.file.FileField(title=u'Luggages') >>> class Mammoth(grok.Context): ... grok.implements(ITravelMount) ... luggage = FieldProperty(ITravelMount['luggage'])
We now have a travel mammoth on which we can add a luggage. Now, we need a form to edit the animal:
>>> from megrok.z3cform.base import EditForm
>>> class EditMammoth(EditForm):
... grok.name('edit')
... grok.context(ITravelMount)
>>> grok.testing.grok_component('edit', EditMammoth)
True
Let’s instanciate a Mammoth and try to call the form on it:
>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> manfred = Mammoth()
>>> request = TestRequest()
>>> form = getMultiAdapter((manfred, request), name='edit')
>>> form.updateWidgets()
>>> print form.widgets['luggage'].render()
<span id="form-widgets-luggage"
class="file-widget required filefield-field">
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<input type="file" id="form-widgets-luggage-input"
name="form.widgets.luggage" />
<BLANKLINE>
<BLANKLINE>
</span>
<BLANKLINE>
Now, let’s try with a value:
>>> manfred.luggage = "A nice data"
>>> form = getMultiAdapter((manfred, request), name='edit')
>>> form.updateWidgets()
>>> print form.widgets['luggage'].render()
<span id="form-widgets-luggage"
class="file-widget required filefield-field">
<BLANKLINE>
<div style="padding-top: 1em;">
<input type="radio" value="nochange" checked="checked"
class="noborder"
name="form.widgets.luggage.nochange"
onclick="document.getElementById('form-widgets-luggage-input').disabled=true"
id="form-widgets-luggage-nochange" />
<label for="form-widgets-luggage-nochange">Keep existing file</label>
<br />
<BLANKLINE>
<label for="form-widgets-luggage-delete">Delete existing file</label>
<br />
<input type="radio" value="" class="noborder"
name="form.widgets.luggage.nochange"
onclick="document.getElementById('form-widgets-luggage-input').disabled=false"
id="form-widgets-luggage-replace" />
<label for="form-widgets-luggage-replace">Replace with new file</label>
</div>
<div style="padding-left: 1.5em; padding-top: 0.5em;">
<input type="file" id="form-widgets-luggage-input"
name="form.widgets.luggage" />
<script type="text/javascript">document.getElementById('form-widgets-luggage-input').disabled=true;</script>
</div>
</span>
<BLANKLINE>
Changelog
0.2 (2010-03-01)
Code base has been cleaned to be pep8 compliant.
We are now using the zope.size.ISized adaptation to get the size of the file to display.
Cleaned dependencies. zope.app dependencies have been severed when possible.
0.1 (2009-10-21)
Initial release
Metadata
Release files for dolmen.widget.file 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dolmen.widget.file-0.2.tar.gz | 6.6 kB | Without provenance | Details |
Release files / dolmen.widget.file-0.2.tar.gz
| Download URL | dolmen.widget.file-0.2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c84525457eb6362cbac0e6a067884e6d8683dffeb070ef1d3e42005a12a4b555
|
|
BLAKE2b-256 checksum How to use checksums |
5a413cd42f377d229a7e53be929a9060d0579ba26940f8c65ce6724bd2e8da56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for dolmen.widget.file 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.