Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deform2: Add buttons to select form layout #25

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add buttons to change form.bootstrap_form_style
  • Loading branch information
dairiki committed Oct 4, 2013
commit c591e613f5368594770336d6baf8690bb182ef67
11 changes: 11 additions & 0 deletions deformdemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,19 @@ def __init__(self, request):
self.request = request
self.macros = get_renderer('templates/main.pt').implementation().macros

if 'bs_form_style' in self.request.GET:
session = self.request.session
bs_form_style = self.request.GET['bs_form_style']
if bs_form_style not in ('form-horizontal', 'form-inline'):
bs_form_style = None
session['bootstrap_form_style'] = bs_form_style

def render_form(self, form, appstruct=colander.null, submitted='submit',
success=None, readonly=False, is_i18n=False):

session = self.request.session
form.bootstrap_form_style = session.get('bootstrap_form_style')

captured = None

if submitted in self.request.POST:
Expand Down Expand Up @@ -118,6 +128,7 @@ def render_form(self, form, appstruct=colander.null, submitted='submit',
'end':end,
'is_i18n':is_i18n,
'locale': locale_name,
'bs_form_style': form.bootstrap_form_style,
'demos':self.get_demos(),
'title':self.get_title(),
'css_links':reqts['css'],
Expand Down
31 changes: 25 additions & 6 deletions deformdemo/templates/main.pt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,33 @@

<body id="public">

<div class="navbar navbar-default" role="navigation">
<div class="container">
<a class="navbar-brand" href="/"><span class="glyphicon glyphicon-info-sign"></span> Deform 2 Demo</a>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<a class="navbar-brand" href="/"><span class="glyphicon glyphicon-info-sign"></span> Deform 2 Demo</a>
<p class="navbar-text pull-right">
Form Layout
<span class="btn-group">
<a tal:define="active not bs_form_style"
class="btn btn-default ${active and 'active' or ''}"
href="${request.path_url}?bs_form_style=">
Default
</a>
<a tal:define="active bs_form_style == 'form-horizontal'"
class="btn btn-default ${active and 'active' or ''}"
href="${request.path_url}?bs_form_style=form-horizontal">
Horizontal
</a>
<a tal:define="active bs_form_style == 'form-inline'"
class="btn btn-default ${active and 'active' or ''}"
href="${request.path_url}?bs_form_style=form-inline">
Inline
</a>
</span>
</p>
</div>
</div>

<div class="container">
</div>

<div class="container">
<div class="row" style="margin-top: 10px">
<div class="col-3 col-lg-3 col-sm-3">
<div class="list-group">
Expand Down