上一博文开了一个头,简单的总结了下代码结构及Panel的增加,这一篇对Panelgroup的增加做一个详细的总结。
增加Panelgroup:
Panelgroup字面意思很好理解就是panel组,在openstack的界面中就是多个panel的集合。上一次的代码分析中其实已经有了对PanelGroup的简单介绍,这次就看看如何增加panelgroup。
这次直接查看Admin(管理员)Dashboard下的dashboard.py
1|-dashboard.py
2from django.utils.translation import ugettext_lazy as _
3
4import horizon
5
6
7class SystemPanels(horizon.PanelGroup):
8 slug = "admin"
9 name = _("System")
10 panels = ('overview', 'metering', 'hypervisors', 'aggregates',
11 'instances', 'volumes', 'flavors', 'images',
12 'networks', 'routers', 'defaults', 'metadata_defs', 'info', 'mypanel') #上一篇博文中增加的mypanel
13
14
15class Admin(horizon.Dashboard):
16 name = _("Admin")
17 slug = "admin"
18 panels = (SystemPanels,)
19 default_panel = 'overview'
20 permissions = ('openstack.roles.admin',)
21
22
23horizon.register(Admin)
以上代码中的class SystemPanels继承的是horizon的PanelGroup,说明该类就是描述‘系统’这个panelgroup的。现在模仿这个增加一个。
修改后的dashboard.py:
1from django.utils.translation import ugettext_lazy as _
2
3import horizon
4
5
6class SystemPanels(horizon.PanelGroup):
7 slug = "systempanel"
8 name = _("System")
9 panels = ('overview', 'metering', 'hypervisors', 'aggregates',
10 'instances', 'volumes', 'flavors', 'images',
11 'networks', 'routers', 'defaults', 'metadata_defs', 'info')
12
13class MyPanels(horizon.PanelGroup):
14 slug = "mypanelgroup"
15 name = "Mypanelgroup"
16 panels = ('mypanel',)
17
18
19class Admin(horizon.Dashboard):
20 name = _("Admin")
21 slug = "admin"
22 panels = (SystemPanels, MyPanels,)
23 default_panel = 'overview'
24 permissions = ('openstack.roles.admin',)
25
26
27horizon.register(Admin)
将自己加的mypanel加到了这个Panelgroup中,然后重启一下httpd服务,查看页面如下: