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