Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcuswhybrow/django-modals
Want multiple forms per page? Love abstraction? Make things easy with django-multi-form!
https://github.com/marcuswhybrow/django-modals
Last synced: 27 days ago
JSON representation
Want multiple forms per page? Love abstraction? Make things easy with django-multi-form!
- Host: GitHub
- URL: https://github.com/marcuswhybrow/django-modals
- Owner: marcuswhybrow
- Created: 2012-11-22T20:33:15.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-11-23T02:30:13.000Z (about 12 years ago)
- Last Synced: 2024-05-02T00:10:20.792Z (8 months ago)
- Size: 109 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Django Modals
=============Do you want modal forms? Love abstraction? Make things easy with django-modals!
I really love [Twitter's bootstrap][bootstrap], and use [modals][modals] all the time to display forms. Manually adding forms to a view is a giant pain. You've got to override `get_context_data()` and slip in your form, and then do the same with `post()` to grap the result.
That all sounds easy enough the first time. But then you add another form to the same view, and you find yourself distinuishing between forms by the submit button name, or a hidden field. **It's time to abstract!**
Django Modal's `ModalMixin` tidies up that messy code, and allows you to neatly define subclasses of `Modal`, instances of which are included in the template context. A `Modal` subclass defines a template to use for rendering the modal in HTML, only handles data from a specific modal form, and defines methods for valid and invalid form data handling:
```
import modalsclass MyThingModal(modals.Modal):
form_class = MyThingForm
template_name = 'app/my_thing_modal.html'def valid(self, form):
form.save()
# Do other work heredef invalid(self, form):
# Take other action
```I'm figuring out the best approach, and it's not functional yet. But I think this is a useful abstraction to make.
[bootstrap]: http://twitter.github.com/bootstrap/
[modals]: http://twitter.github.com/bootstrap/javascript.html#modals