Giter Site home page Giter Site logo

kotti / deform_bootstrap Goto Github PK

View Code? Open in Web Editor NEW
35.0 7.0 30.0 684 KB

Bootstrap compatible templates for the deform form library. (Merged into deform 2.)

Home Page: http://pypi.python.org/pypi/deform_bootstrap

Python 16.13% CSS 41.69% JavaScript 42.18%

deform_bootstrap's Introduction

deform_bootstrap

deform_bootstrap provides Twitter Bootstrap compatible widgets, templates and styles for the deform form library.

deform_bootstrap is developed on GitHub. Latest releases are available on PyPI.

How to use it

I just downloaded this and wanna use it

In your Paste Deploy configuration file (e.g. development.ini) add deform_bootstrap to the list of pyramid_includes, or add a this line if a pyramid.includes setting does not exist:

[app:main]
...
pyramid.includes = deform_bootstrap

This will put the templates in deform_bootstrap/templates into the deform search path.

I want to try it before using

If you want to quickly try out deform_bootstrap and see how it looks in practice you can run these commands, assuming that you have a virtualenv set up in your deform_bootstrap directory:

$ git clone https://github.com/Pylons/deformdemo.git
$ cd deformdemo
$ ../bin/python setup.py develop
$ cd ..
$ bin/pserve demo.ini

You should now be able to access the demo site at http://0.0.0.0:8521

Using tabs in forms

To make a tabbed form, use mapping. Each mapping will appear as a new tab, taking the title of the mapping as the name for the tab. If you specify no tabs for some information, it will default to a 'Basic' tab.

A form using the following Client schema will render with two tabs 'Person data' and 'Car stuffs':

import colander

class Person(colander.Schema):
    name = colander.SchemaNode(
        colander.String(),
        title='Name',
        )
    surname = colander.SchemaNode(
        colander.String(),
        title='Surname',
        )

class Car(colander.Schema):
    color = colander.SchemaNode(
        colander.String(),
        title='Color',
        )
    horsepower = colander.SchemaNode(
        colander.Integer(),
        title='Horsepower',
        )

class Client(colander.Schema):
    person = Person(title='Person data')
    car = Car(title='Car stuffs')

Additional widgets / getting rid of legacy stuff

jQueryUI

Deform depends on jQueryUI for these wigdgets:

  • AutocompleteInputWidget
  • DateInputWidget
  • DateTimeInputWidget

deform_bootstrap comes with widgets that replace these, and that are compatible with Bootstrap. If you don't use any of these, you can skip the remainder of this section and just delete jQueryUI from your CSS and JS imports. Otherwise you'll need to add bootstrap-typeahead.js and/or bootstrap-datepicker.js to your JS includes.

You can then use deform_bootstrap's TypeaheadInputWidget as a drop in replacement for deform's AutocompleteInputWidget.

Unfortunately things are a litte more complicated for DateInputWidget and DateTimeInputWidget, because bootstrap does not provide native widgets for that usecases (yet?). Therefore you will need to either use deform_bootstrap.css provided by deform_bootstrap or build your own bootstrap.css using LESS <http://lesscss.org/>. Once you have lessc installed it can be done like this:

$ cd deform_bootstrap/static
$ lessc deform_bootstrap.less

You'll then find your custom deform_bootstrap.css which immediately leads to a shiny new look for DateInputWidgets. For DateTimeInputWidgets you'll have to replace your existing imports. This is as easy as replacing from deform.widget import DateTimeInputWidget with from deform_bootstrap.widget import DateTimeInputWidget in your code.

<ul> / <li> markup

Deform uses <ul> / <li> markup for rendering sequences. Although one can argue, that this is semanticaly correct, it doesn't make much sense in the context of form rendering and requires quite some additional CSS to produce visually appealing results. Therefore deform_bootstrap removes all list markup and generates nice forms with no additional CSS required.

In order to make this work with not only with fixed length sequences, but also variable length sequences, 2 functions in deform.js needs to be patched. This can be done by simply adding the provided deform_bootstrap.js to your JS requirements. If your application doesn't use variable length sequences, you can safely skip this step.

Chosen by Harvest

A progressively enhanced replacement for HTML select elements, Chosen implements single and multiple selection modes that offer a much better UX than the standard widgets. It has autocomplete features, placeholder support and a slick style that looks good either with or without Bootstrap. See http://harvesthq.github.com/chosen/ for documentation and examples. Only the jQuery version is provided by this package.

Static resources

deform_bootstrap comes with a bunch of static resources, which might confuse you. Fortunately most of them are just needed to pass all the tests and most most of them (if any) won't be needed in your deform_bootstrap based application.

CSS

deform_bootstrap.css
This file contains the complete Bootstrap 2.0.1 CSS plus additional styles for the datepicker widget (see above). You may use it for your application (great for initial development), but might also want to consider rolling your own customized version for deployment.
jquery_chosen/chosen.css
The main style for ChosenSingleWidget and ChosenMultipleWidget.
chosen_bootstrap.css
This file contains a small fix for conflicts between chosen and bootstrap. Only needed if you make use of chosen, but harmless if you don't.
bootstrap-datepicker.css
The styles for the native bootstrap datepicker widget (see above).

Note that chosen_bootstrap.css and bootstrap-datepicker.css are included in deform_bootstrap.css, so you will only need them if you use some other version of the bootstrap css.

JS

bootstrap-datepicker.js
Only needed if you want to use the native bootstrap datepicker widget (see above).
bootstrap_typeahead.js
Only needed if you want to use the native bootstrap datepicker widget (see above).
bootstrap.min.js
Only needed as a direct dependency of the bootstrap_XXX.js files.
deform_bootstrap.js
Only needed as if you want to use variable length sequences (see "<ul> / <li> markup" above).
jquery-x.x.x.min.js
Only needed if you want to use any of the other JS resources.
jquery-ui-x.x.x.custom.min.js
Only needed if prefer using deform's orinial AutocompleteInputWidget over deform_bootstrap's TypeaheadInputWidget or deform's DateTimeInputWidget over deform_bootstrap's native version (see above).
jquery-ui-timepicker-addon-x.x.x.js
Same as for jquery-ui-x.x.x.custom.min.js.
jquery.form-2.96.js
Only needed if you want to use use_ajax=True with deform.Form.
jquery.maskedinput-x.x.js
Only needed if you want mask='...' with any of the deform widgets that support it.
jquery_chosen/chosen.jquery.js
Only needed if you use ChosenSingleWidget, ChosenOptGroupWidget, or ChosenMultipleWidget,

LESS / twitter_bootstrap

Not needed at all. Only used internally to build the custom deform_bootstrap.css with the additional datepicker styles.

Information for developers / contributors

Running unit tests

$ bin/python setup.py dev
$ bin/py.test

deformdemo

deform_bootstrap passes 100% of the deformdemo tests. Please do run the Selenium tests before submitting a patch.

However, bootstrap requires a newer version of jquery than deform ships with by default. This in turn would require a newer version of jquery.form (> 2.43) which unfortunately is backward incompatible in its ajax handling. Thus, deform_bootstrap cannot currently support deform's use_ajax feature. The corresponding selenium tests have therefore been disabled until deform catches up. Note, that you can still use jquery.form itself.

Running Selenium tests

  • Make sure you have a Java interpreter installed.

  • Download Selenium Server <http://seleniumhq.org/download/> standalone jar file.

  • Start the server with demo.ini.

  • In another terminal, run java -jar selenium-server-standalone-X.X.jar. Success is defined as seeing output on the console that ends like this:

    01:49:06.105 INFO - Started SocketListener on 0.0.0.0:4444 01:49:06.105 INFO - Started org.openqa.jetty.jetty.Server@7d2a1e44

  • In yet another terminal, run the tests with the command:

    $ bin/python deform_bootstrap/demo/test.py

API

input_prepend / input_append

Bootstrap has a nice feature to prepend/append text to input[type=text] form elements (see http://twitter.github.com/bootstrap/base-css.html#forms). To use it with deform_bootstrap you can simply pass input_prepend or input_append as keyword arguments to the widget constructor in your colander.Schema subclass:

class PersonSchema(colander.Schema):
    weight = colander.SchemaNode(
        colander.Integer(),
        title=u"Weight",
        widget=deform.widget.TextInputWidget(
            input_append="kg",
            css_class="span1",
        ))

bootstrap_form_style

Bootstrap supports four form styles. By default, deform_bootstrap uses the .form-horizontal style. You can specify one of the other styles be setting the bootstrap_form_style attribute of your Form:

myform = Form(myschema, bootstrap_form_style='form-vertical')

inline

Bootstrap supports inline checkbox and radio choices. Normally RadioChoiceWidgets and CheckboxChoiceWidgetss are displayed with one choice per line. To select the inline style, set the inline attribute of the choice widget to a trueish value:

class MySchema(colander.Schema):
    choice = colander.SchemaNode(
        colander.String(),
        widget=deform.widget.CheckboxChoiceWidget(
            values=[(u'a', u'Apple'),
                    (u'b', u'Bear'),
                    (u'c', u'Computer')],
            inline=True))

Thanks

deform_bootstrap was created by Daniel Nouri. Thanks to the following people for support, code, patches etc:

deform_bootstrap's People

Contributors

armooo avatar cguardia avatar dairiki avatar dholth avatar disko avatar dnouri avatar goodwillcoding avatar igudym avatar iksteen avatar jkoelker avatar mcdonc avatar nandoflorestan avatar nightmarebadger avatar pauleveritt avatar silviot avatar t2y avatar thruflo avatar tisdall avatar tomster avatar tseaver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

deform_bootstrap's Issues

404 Not Found !! The resource could not be found. /img/glyphicons-halflings.png

hi guys,

great afford for such beautiful app. Recently i have come across to this error

404 Not Found !! The resource could not be found. /img/glyphicons-halflings.png

What i found is that there no resource included in deform_boostrap package so i resolved my including these img files manually by placing this glyphicons-halflings.png & glyphicons-halflings-white.png files into static dir of deform_boostap and changed the path in deform_bootstrap.css.

So it will be great if you guys fix this so that everyone will not face the same problem.
screenshot from 2013-08-01 15 00 12

Missing clausing div in template

In the mapping.pt template :

<div tal:condition="field.description">
    ${field.description}

is missing the clausing div.
Example of consequence :
If I introduce the mappingSchema in a sequenceSchema, the appendsequence button is not working.

DateParts not working well with row-fluid

When some parent (or ancestor) has "row-fluid" class, the Date Parts widget gets its width messed up.
Changing from row to row-fluid in dateparts.pt worked, but only partially.

widget requirements causes errors in form rendering since they are not registered

The following

https://github.com/Kotti/deform_bootstrap/commit/45de9ca8738aabb7314cbfe8ef7f53668edeb0ff

introduced requirements on deform_bootstrap widgets causing the following error

  File "/.../lib/python2.7/site-packages/deform-0.9.5-py2.7.egg/deform/widget.py", line 1549, in __call__
    'Cannot resolve widget requirement %r' % requirement)
ValueError: Cannot resolve widget requirement 'chosen'

The requirements should be registered in the default_resource_registry.

images are missing from deform's copy of bootstrap

bootstrap iconglyphs are not included in the deforms version of bootstrap

Also, because bootstrap.css and .js is not in their respective .js and .css folders dropping the folder in does not help.

deform_bootstrap.css:1782:  background-image: url("../img/glyphicons-halflings.png");
deform_bootstrap.css:1793:  background-image: url("../img/glyphicons-halflings-white.png");

Solution 1:
Adjust image paths in deform_bootstrap.css

Solution 2:
Possible solution included moving bootstrap css/js into proper subfolders, and using symlinks to keep backward compatability

form.pt error

The following error happens when running a form in production environement which includes deform_bootstrap. This login form and all other forms work fine on my development machine with deform_bootstrap.
I tried using development form.pt from development partition and tried commenting out things in form.pt I do not understand enough to figure out. Thanks for any help,
Clemens Herschel

[cherschel@web39 phr]$ more pyramid.log
Starting server in PID 28077.
serving on http://0.0.0.0:42467
2014-02-25 21:50:20,863 ERROR [waitress][Dummy-1] Exception when serving /login
Traceback (most recent call last):
File "/home/cherschel/webapps/phr/lib/python2.7/waitress/channel.py", line 329
, in service
task.service()
File "/home/cherschel/webapps/phr/lib/python2.7/waitress/task.py", line 173, i
n service
self.execute()
File "/home/cherschel/webapps/phr/lib/python2.7/waitress/task.py", line 380, i
n execute
app_iter = self.channel.server.application(env, start_response)
File "/home/cherschel/webapps/phr/lib/python2.7/pyramid/router.py", line 187,
in call
response = self.handle_request(request)
File "/home/cherschel/webapps/phr/lib/python2.7/pyramid/tweens.py", line 20, i
n excview_tween
response = handler(request)
File "/home/cherschel/webapps/phr/lib/python2.7/site-packages/pyramid_tm-0.4-p
y2.7.egg/pyramid_tm/init.py", line 95, in tm_tween
response = handler(request)
File "/home/cherschel/webapps/phr/lib/python2.7/pyramid/router.py", line 164,
in handle_request
response = view_callable(context, request)
File "/home/cherschel/webapps/phr/lib/python2.7/pyramid/config/views.py", line
333, in rendered_view
result = view(context, request)
File "/home/cherschel/webapps/phr/lib/python2.7/pyramid/config/views.py", line
471, in _requestonly_view
response = view(request)
File "/home/cherschel/webapps/phr/Phr-0.0/phr/views/login.py", line 97, in log
in_view
return {'form':login_form.render(),"heading": 'Login'}
File "/home/cherschel/lib/python2.7/deform/field.py", line 433, in render
return self.serialize(cstruct, readonly=readonly)
File "/home/cherschel/lib/python2.7/deform/field.py", line 408, in serialize
return self.widget.serialize(self, cstruct=cstruct, readonly=readonly)
File "/home/cherschel/lib/python2.7/deform/widget.py", line 982, in serialize
null=null)
File "/home/cherschel/lib/python2.7/deform/template.py", line 117, in call
return self.load(template_name)(**kw)
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 125, in cal
l

return self.render(**kwargs)
File "/home/cherschel/lib/python2.7/chameleon/zpt/template.py", line 257, in r
ender
return super(PageTemplate, self).render(*vars)
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 169, in rende
r
self.cook_check()
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 293, in cook

check
self.cook(body)
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 147, in cook
program = self._cook(body, digest, names)
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 218, in _cook
source = self.make(body, builtins)
File "/home/cherschel/lib/python2.7/chameleon/template.py", line 249, in make
program = self.parse(body)
File "/home/cherschel/lib/python2.7/chameleon/zpt/template.py", line 202, in p
arse
trim_attribute_space=self.trim_attribute_space,
File "/home/cherschel/lib/python2.7/chameleon/zpt/program.py", line 145, in __
init

super(MacroProgram, self).init(_args, **kwargs)
File "/home/cherschel/lib/python2.7/chameleon/program.py", line 31, in _init
_
for kind, args in parser:
File "/home/cherschel/lib/python2.7/chameleon/parser.py", line 182, in _iter
_
item = self.parse(token)
File "/home/cherschel/lib/python2.7/chameleon/parser.py", line 190, in parse
return visitor(kind, token)
File "/home/cherschel/lib/python2.7/chameleon/parser.py", line 231, in visit_e
nd_tag
raise ParseError("Unexpected end tag.", token)
ParseError: Unexpected end tag.

  • String: ""
  • Filename: /home/cherschel/lib/python2.7/deform_bootstrap-0.2.9-py2.7.egg/de
    form_bootstrap/templates/form.pt
    .7.egg/deform_bootstrap/templates/form.pt

vmware partition-development
Ubuntu
python 2.7
pyramid 1.4
deform_bootstrap .2.1
deform .9.5
Mako .5

webfaction production
centos
python 2.75
pyramid 1.3
Mako .7
deform_bootstrap .2.1

readonly elements

There could be some bootstrap modifications made to the readonly templates. For example the readonly textinput could look like this:

<span id="${field.oid}" class="uneditable-input">${cstruct}</span>

Are you open to a pull request related to this? What are other people's thoughts on doing this?

Update to bootstrap 3

As bootstrap3 was released long back, i think it will be good if this project is updated to bs3.

fix resource registry, again

It looks like set_*_resources expects each resource as a new positional argument. To fix, change all the .resources.default_resources to sequences and use * as below.

http://deform.readthedocs.org/en/latest/api.html#deform.widget.ResourceRegistry.set_css_resources

deform_bootstrap.init:

def add_resources_to_registry():
"""
Register deform_bootstrap widget specific requirements to deform's
default resource registry
"""
registry = Form.default_resource_registry
for rqrt, versions in default_resources.items():
for version, resources in versions.items():
registry.set_js_resources(rqrt, version, *resources.get('js'))
registry.set_css_resources(rqrt, version, *resources.get('css'))

Placeholder Support

Hi would be nice if we can configure a placeholder for the widgets

        widget=TypeaheadInputWidget(
            size=60,
            min_length=3,
            placeholder="Agent",
            values='/agents/list.json'),
        description='Provide the AgentID or Agent Name')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.