]>
git.ipfire.org Git - people/ms/westferry.git/blob - src/westferry/handlers/base.py
774d9f23aedb6c1bf27a5c122aa7211fd0d534fc
2 ###############################################################################
4 # Westferry - The IPFire web user interface #
5 # Copyright (C) 2015 IPFire development team #
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. #
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. #
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/>. #
20 ###############################################################################
26 from ..i18n
import _
, N_
30 class HandlerRegistration(type):
31 def __init__(handler
, name
, bases
, dict):
32 type.__init
__(handler
, name
, bases
, dict)
34 # The main class from which is inherited is not registered
36 if name
.endswith("BaseHandler"):
39 if handler
.url
is None:
40 raise RuntimeError(_("Handler %s is improperly configured") % handler
)
42 _handlers
.append(handler
)
49 class BaseHandler(tornado
.web
.RequestHandler
, metaclass
=HandlerRegistration
):
52 title
= N_("No Title")
54 # Points to the menu map of the section in which the handler is in
60 Shortcut to access the backend
62 return self
.application
.backend
64 @functools.cached_property
66 return ui
.tabs
.Tabs(self
)
68 def get_template_namespace(self
):
69 ns
= tornado
.web
.RequestHandler
.get_template_namespace(self
)
71 # Add some global constants
73 "VERSION" : self
.backend
.version
,
83 def get_argument_int(self
, name
, *args
, **kwargs
):
84 val
= self
.get_argument(name
, *args
, **kwargs
)
92 raise tornado
.web
.HTTPError(400,
93 _("Invalid type for '%s', expected integer") % name
)
96 # Render the default view
97 self
.render("default.html")
101 This is the default handler which will find the correct form
104 form_id
= self
.get_argument("form")
107 form
= self
.tabs
.get_form(form_id
)
109 raise tornado
.web
.HTTPError(400, "Could not find form with ID '%s'" % form_id
)
111 # Execute the form action