Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install dolmen.widget.file

How to install dolmen.widget.file

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install dolmen.widget.file
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0b2 Available View build log
1.0b1 Available View build log
Windows (64-bit)
1.0b2 Available View build log
1.0b1 Available View build log
Mac OS X (10.5+)
1.0b2 Available View build log
1.0b1 Available View build log
Linux (32-bit)
1.0b2 Available View build log
1.0b1 Available View build log
Linux (64-bit)
1.0b2 Available View build log
1.0b1 Available View build log
 
License
GPL
Depended by
Lastest release
version 1.0b2 on Jan 5th, 2011

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 zeam.form Form.

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 zeam.form.ztk import Form, Fields

>>> class EditMammoth(Form):
...    grok.name('edit')
...    grok.context(ITravelMount)
...    ignoreContent = False
...    fields = Fields(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.fieldWidgets.get('form.field.luggage').render()
<div id="form-field-luggage">
    <input type="file" id="form-field-luggage-input"
           name="form.field.luggage" />
</div>

Now, let's try with a value:

>>> manfred.luggage = "A nice data"
>>> form = getMultiAdapter((manfred, request), name='edit')
>>> form.updateWidgets()
>>> print form.fieldWidgets.get('form.field.luggage').render()
<div id="form-field-luggage">
  <div>
    <input type="radio" value="keep" checked="checked"
           class="noborder" name="form.field.luggage.action"
           onclick="document.getElementById('form-field-luggage-input').disabled=true"
           id="form-field-luggage-action" />
    <label for="form-field-luggage-action">Keep existing file</label>
    <br />
    <input type="radio" value="delete" class="noborder"
           name="form.field.luggage.action"
           onclick="document.getElementById('form-field-luggage-input').disabled=true"
           id="form-field-luggage-delete" />
    <label for="form-field-luggage-delete">Delete existing file</label>
    <br />
    <input type="radio" value="replace" class="noborder"
           name="form.field.luggage.action"
           onclick="document.getElementById('form-field-luggage-input').disabled=false"
           id="form-field-luggage-replace" />
        <label for="form-field-luggage-replace">Replace with new file</label>
    </div>
  <div>
    <input type="file" id="form-field-luggage-input"
           name="form.field.luggage" />
    <script type="text/javascript">document.getElementById('form-field-luggage-input').disabled=true;</script>
  </div>
</div>

Changelog

1.0b2 (2010-11-22)
  • We now retrieve the form content using the proper API (getContentData / getContent).
1.0b1 (2010-07-05)
  • The field adapter is now registered using the latest zeam.form.base entry points system. This solves definitly the priority problems in the registration process.
  • The widget mode registration is now done using the __str__ representation of the appropriate markers.
1.0a3 (2010-06-25)
  • We no longer user the registerField function from zeam.form.ztk, but directly provide the adapter thanks to Grok, instead. This solves initialisation priority preventing the correct field registration.
1.0a2 (2010-06-19)
  • Corrected a bug that allowed actions to appear when form submission errors occured.
1.0a1 (2010-05-14)
  • Major change : the widget is now meant to be used in zeam.form. Dolmen is no longer using z3c.form.
  • French translations have been added.
  • The HTML code of the widget has been improved.
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

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:8

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.