]> git.ipfire.org Git - people/ms/westferry.git/blame - src/westferry/handlers/demo.py
demo: Add tabs to form examples
[people/ms/westferry.git] / src / westferry / handlers / demo.py
CommitLineData
f33e1d2f
MT
1#!/usr/bin/python3
2###############################################################################
3# #
4# Westferry - The IPFire web user interface #
5# Copyright (C) 2015 IPFire development team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
22from . import base
23from .. import backend
24from .. import ui
25
26from ..i18n import N_, _
27
28class DemoBaseHandler(base.BaseHandler):
29 @property
30 def menu(self):
31 _ = self.locale.translate
32
33 m = ui.menu.Menu(self, _("Demo"))
34
35 # Overview
36 m.add_handler(DemoOverviewHandler)
f33e1d2f
MT
37
38 # Forms
ba309c2c 39 m.add_handler(DemoFormsHandler)
f33e1d2f
MT
40
41 return m
42
43
44class DemoOverviewHandler(DemoBaseHandler):
45 url = r"/demo"
46 title = N_("Overview")
47
48 def get(self):
ba309c2c 49 self.render("demo/index.html")
f33e1d2f
MT
50
51
ba309c2c 52class DemoFormsHandler(DemoBaseHandler):
f33e1d2f
MT
53 url = r"/demo/forms"
54 title = N_("Forms")
55
cdcc050f 56 def initialize(self):
f33e1d2f
MT
57 _ = self.locale.translate
58
cdcc050f
MT
59 # Create a new tab
60 tab = self.tabs.add_tab("example-1", _("Example 1"))
61
62 # Add a form to the tab
63 form = tab.add_form()
f33e1d2f
MT
64 form.submit_text = _("Order")
65
66 # First name
67 e = form.add_text_input("first_name", label=_("First Name"), placeholder="John")
68 e.help = _("Please enter your first name")
69
70 # Last name
71 e = form.add_text_input("last_name", label=_("Last Name"), placeholder="Doe")
72 e.help = _("Please enter your last name")
73
74 # We create a fieldset for the address
75 fs1 = form.add_fieldset(label=_("Address"))
76 fs1.help = _("Please enter your address")
77
78 e = fs1.add_text_input("street", label=_("Street"))
79 e = fs1.add_text_input("city", label=_("City"))
80 e = fs1.add_text_input("post_code", label=_("Postcode"))
81
82 # Fieldset without label
83 fs2 = form.add_fieldset()
84
85 # Donation amount
86 e = fs2.add_text_input("donation", label=_("Donation"),
87 placeholder=_("Donation"), suffix="€")
88
89 # Notes
90 e = fs2.add_multiline_text_input("notes", label=_("Notes"))
91
92 # Subscribe to newsletter?
93 e = fs2.add_yesno_input("subscribe_to_newsletter", description=_("Subscribe to newsletter?"))