]> git.ipfire.org Git - people/ms/westferry.git/blob - src/westferry/handlers/demo.py
913cd65a699836537fc84193dc64964633212aaf
[people/ms/westferry.git] / src / westferry / handlers / demo.py
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
22 from . import base
23 from .. import ui
24
25 from ..i18n import N_, _
26
27 class BaseHandler(base.BaseHandler):
28 @property
29 def menu(self):
30 _ = self.locale.translate
31
32 m = ui.menus.Menu(self, _("Demo"))
33
34 # Overview
35 m.add_handler(OverviewHandler)
36
37 # Forms
38 m.add_handler(FormsHandler)
39
40 return m
41
42
43 class OverviewHandler(BaseHandler):
44 url = r"/demo"
45 title = N_("Overview")
46
47 def get(self):
48 self.render("demo/index.html")
49
50
51 class FormsHandler(BaseHandler):
52 url = r"/demo/forms"
53 title = N_("Forms")
54
55 def initialize(self):
56 _ = self.locale.translate
57
58 # Create a new tab
59 tab = self.tabs.add_tab("example-1", _("Example 1"))
60
61 # Add a form to the tab
62 form = tab.add_form("example-1")
63 form.submit_text = _("Order")
64
65 # First name
66 e = form.add_text_input("first_name", label=_("First Name"), placeholder="John")
67 e.help = _("Please enter your first name")
68
69 # Last name
70 e = form.add_text_input("last_name", label=_("Last Name"), placeholder="Doe")
71 e.help = _("Please enter your last name")
72
73 # We create a fieldset for the address
74 fs1 = form.add_fieldset(label=_("Address"))
75 fs1.help = _("Please enter your address")
76
77 e = fs1.add_text_input("street", label=_("Street"))
78 e = fs1.add_text_input("city", label=_("City"))
79 e = fs1.add_text_input("post_code", label=_("Postcode"))
80
81 # Fieldset without label
82 fs2 = form.add_fieldset()
83
84 # Donation amount
85 e = fs2.add_text_input("donation", label=_("Donation"),
86 placeholder=_("Donation"), suffix="€")
87
88 # Notes
89 e = fs2.add_multiline_text_input("notes", label=_("Notes"))
90
91 # Subscribe to newsletter?
92 e = fs2.add_yesno_input("subscribe_to_newsletter", description=_("Subscribe to newsletter?"))