Skip to content

Commit

Permalink
Merge pull request #41 from Qwait/master
Browse files Browse the repository at this point in the history
Added option to allow overriding of the template used to render forms, added apex flash import shortcut.
  • Loading branch information
Qwait committed Oct 30, 2011
2 parents 0e4c5e5 + 8cf7343 commit 82dec9a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apex/__init__.py
Expand Up @@ -30,6 +30,14 @@
from apex.views import register
from apex.views import reset_password

"""
Allows flash messages to be called as:
::
from apex import flash
"""
from apex.lib.flash import flash

def includeme(config):
settings = config.registry.settings

Expand Down
10 changes: 8 additions & 2 deletions apex/lib/form.py
Expand Up @@ -4,6 +4,7 @@
from wtforms import validators

from pyramid.renderers import render
from pyramid.threadlocal import get_current_registry

class ExtendedForm(Form):
""" Base Model used to wrap WTForms for local use
Expand Down Expand Up @@ -42,9 +43,14 @@ def validate(self):
def render(self, **kwargs):
action = kwargs.pop('action', '')
submit_text = kwargs.pop('submit_text', 'Submit')
template = kwargs.pop('template', 'tableform')
template = kwargs.pop('template', False)

return render('apex:templates/forms/%s.mako' % template, {
if not template:
settings = get_current_registry().settings
template = settings.get('apex.form_template', \
'apex:templates/forms/tableform.mako')

return render(template, {
'form': self,
'action': action,
'submit_text': submit_text,
Expand Down
4 changes: 4 additions & 0 deletions docs/source/options.rst
Expand Up @@ -41,6 +41,10 @@ apex.provider_exclude = openid
apex.apex_template = project:templates/auth.mako
OPTIONAL, an optional template for rendering the authentication forms

apex.form_template = project:templates/form.mako
OPTIONAL, an optional template for changing the default template used when
rendering forms

apex.register_form_class = project.models.form_name
OPTIONAL, requires DOTTED notation, specifies overloaded form for
registration
Expand Down

0 comments on commit 82dec9a

Please sign in to comment.