]>
git.ipfire.org Git - people/ms/westferry.git/blob - src/westferry/ui/tabs.py
d4b94568bbea89839198594864cc11ef5ab6ecd7
2 ###############################################################################
4 # Westferry - The IPFire web user interface #
5 # Copyright (C) 2021 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 ###############################################################################
28 class TabsModule(base
.BaseUIModule
):
29 def render(self
, tabs
):
30 return self
.render_string("modules/tabs.html", tabs
=tabs
)
34 def __init__(self
, handler
, id=None):
35 self
.handler
= handler
37 # Store ID or generate a random one
38 self
.id = id or uuid
.uuid4()
42 def __getattr__(self
, key
):
46 raise AttributeError(key
) from e
52 def add_tab(self
, id, *args
, **kwargs
):
53 # Check if a tab with this ID already exists
55 # raise ValueError("Tab with ID '%s' already exists" % id)
58 self
.tabs
[id] = tab
= Tab(self
.handler
, id, *args
, **kwargs
)
63 def get_form(self
, id):
65 Returns the form with a matching ID
68 for item
in tab
.items
:
69 if isinstance(item
, forms
.Form
):
75 def __init__(self
, handler
, id, title
):
76 self
.handler
= handler
78 # TODO Check format of ID
83 # List to store all items that have been added to this tab
86 def _add_item(self
, cls
, *args
, **kwargs
):
87 item
= cls(self
.handler
, *args
, **kwargs
)
88 self
.items
.append(item
)
92 def add_form(self
, *args
, **kwargs
):
93 return self
._add
_item
(forms
.Form
, *args
, **kwargs
)
95 def add_graph(self
, *args
, **kwargs
):
96 return self
._add
_item
(graphs
.Graph
, *args
, **kwargs
)