Skip to main content

Fanstatic packaging of deform

Project description

js.deform

Introduction

This library packages deform for fanstatic.

This requires integration between your web framework and fanstatic, and making sure that the original resources (shipped in the resources directory in js.deform) are published to some URL.

Included resources

js.deform is different from most js. packages in that it doesn’t include any resources itself. It references the resources from deform instead. The only resources that are made available from js.deform are deform.js, form.css and beautify.css. All other resources that are part of the deform distribution are available separately:

How to use?

JS

You can import deform_js from js.deform and need it where you want these resources to be included on a page:

>>> from js.deform import deform_js
>>> deform_js.need()

CSS

You can import deform_css from js.deform and need it where you want these resources to be included on a page:

>>> from js.deform import deform_css
>>> deform_css.need()

All

You can import deform from js.deform and need it where you want these resources to be included on a page:

>>> from js.deform import deform
>>> deform.need()

Auto-needing Resources

You can avoid needing to manually import and need() each Fanstatic dependency of your Deform form by use of the auto_need function provided in this package.

>>> import js.deform
>>> import colander
>>> import deform
>>> schema = colander.Schema()
>>> form = deform.Form(schema)
>>> js.deform.auto_need(form)

By doing the above, any widget requirements - including those of Deform itself - will be included for Fanstatic.

So, you may have a form that requires a deform.widget.RichTextWidget for one of its fields. This type of widget requires resources relating to TinyMCE. js.deform.auto_need will use js.tinymce for this requirement.

This is all best illustrated in the following example.

Initialise Fanstatic so we can see resources being included:

>>> import fanstatic
>>> dummy = fanstatic.init_needed()
>>> len(fanstatic.get_needed().resources())
0

Create a demonstration schema and form:

>>> schema = colander.Schema()
>>> node = colander.SchemaNode(colander.String(),
...                            widget=deform.widget.RichTextWidget())
>>> schema.add(node)
>>> form = deform.Form(schema)

Check the form’s resource requirements:

>>> form.get_widget_requirements()
[('deform', None), ('tinymce', None)]

Ask auto_need to include the resources for us:

>>> js.deform.auto_need(form)

So we can now see the resources that have been included:

>>> needed = fanstatic.get_needed()
>>> needed.resources()
[<Resource 'css/beautify.css' in library 'deform'>, <Resource 'css/form.css' in library 'deform'>, <Resource 'jquery.js' in library 'jquery'>, <Resource 'tiny_mce_src.js' in library 'tinymce'>, <Resource 'scripts/deform.js' in library 'deform'>]

The above resources will automatically be included on your page once Fanstatic is configured accordingly.

Patching deform to automatically need the resources for a widget

If you don’t want to have to call auto_need(form) for every form instance in your application, you can patch deform (e.g. on application startup) to automagically need() everything for you where required.

Let’s reinit fanstatic…

>>> dummy = fanstatic.init_needed()
>>> len(fanstatic.get_needed().resources())
0

…and patch deform this time:

>>> from js.deform import patch_deform
>>> patch_deform()

Note that you only have too do this once, e.g on application startup.

Now do the same as above, but without calling auto_need. Note that the need() calls are not issued before rendering the form.

>>> schema = colander.Schema()
>>> node = colander.SchemaNode(colander.String(),
...                            widget=deform.widget.RichTextWidget())
>>> schema.add(node)
>>> form = deform.Form(schema)
>>> needed = fanstatic.get_needed()
>>> needed.resources()
[]
>>> html = form.render()
>>> needed = fanstatic.get_needed()
>>> needed.resources()
[<Resource 'jquery.js' in library 'jquery'>, <Resource 'tiny_mce_src.js' in library 'tinymce'>, <Resource 'scripts/deform.js' in library 'deform'>]

Tests for the other widgets that need some resources:

  • AutocompleteInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.AutocompleteInputWidget())
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'ui/jquery.ui.core.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.position.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.widget.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.autocomplete.js' in library 'jqueryui'>]
    
  • CheckedInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.CheckedInputWidget(mask='__'))
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'jquery.maskedinput.js' in library 'jquery.maskedinput'>]
    
  • DateInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.DateInputWidget())
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'ui/jquery.ui.core.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.datepicker.js' in library 'jqueryui'>]
    
  • DateTimeInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.DateTimeInputWidget())
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'ui/jquery.ui.core.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.widget.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.datepicker.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.mouse.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.slider.js' in library 'jqueryui'>, <Resource 'jquery-ui-timepicker-addon.js' in library 'jquery-timepicker-addon'>]
    
  • MappingWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.MappingWidget())
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>]
    
  • MoneyInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.MoneyInputWidget())
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'jquery.maskmoney.js' in library 'jquery-maskmoney'>]
    
  • SequenceWidget:

    >>> dummy = fanstatic.init_needed()
    >>> class Phone(colander.MappingSchema):
    ...     number = colander.SchemaNode(colander.String())
    >>>
    >>> class Phones(colander.SequenceSchema):
    ...     phone = Phone()
    >>>
    >>> class Person(colander.MappingSchema):
    ...     phones = Phones()
    >>>
    >>> schema = Person()
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>, <Resource 'ui/jquery.ui.core.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.widget.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.mouse.js' in library 'jqueryui'>, <Resource 'ui/jquery.ui.sortable.js' in library 'jqueryui'>]
    
  • TextInputWidget:

    >>> dummy = fanstatic.init_needed()
    >>> schema = colander.Schema()
    >>> node = colander.SchemaNode(colander.String(),
    ...                            widget=deform.widget.TextInputWidget(mask='__'))
    >>> schema.add(node)
    >>> form = deform.Form(schema)
    >>> html = form.render()
    >>> needed = fanstatic.get_needed()
    >>> needed.resources()
    [<Resource 'jquery.js' in library 'jquery'>, <Resource 'scripts/deform.js' in library 'deform'>]
    

CHANGES

0.9.5-2

  • Add auto_need method for automatically including Fanstatic resources for a given Deform form instance.

  • Add patch_deform function for automagically including Fanstatic resources. This feature will vanish when deform gets a FormRender event which we can subscribe to.

0.9.5-1

  • Make the CSS resources available separately as well as combined with the JS resource.

0.9.5

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

js.deform-0.9.5-2.tar.gz (6.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page