地平线django工具。
horizon_contrib的Python项目详细描述
地平线django contrib
构建在django和horizon(openstack仪表板的一部分)之上的库,用于构建现代web应用程序。
使用此工具包可以快速轻松地构建应用程序!
这个库提供了大多数horizon组件的通用实现,添加了更多的工具来轻松构建应用程序,并保留了对复杂定制的支持。
Short story
horizon是一个很好的包,可以快速创建所有东西的ui。但它是为无模型应用程序(如openstack仪表板)设计的。 如果我们将horizon与典型的django应用程序连接起来,我们必须创建相同组件的相同片段,这真的很糟糕! 我们需要更多的声明性代码和更少的命令性代码。为此,我们创建了这个库,它在一个地方组成普通的东西。
Features
使用django和conent类型
- Views - PaginatedIndex, Create, Update, Delete in Angular modal’s
- Tables with inline-ajax update
- Modal Forms autohandled
- Generic - IndexView with pagination, CRUD actions and AJAX inline-edit.
不需要实现,所有django的东西都像管理员一样自动生成,但是以更可定制和扩展的形式生成。
rest api仪表板
- APIModel
- Manager
- ClientBase - simple implementation which uses ^{tt1}$
- Generic - Tables, Views, Actions
加上在django下定义的所有特性,因为如果我们有模型,大多数东西都可以在没有任何修改的情况下正常工作。
Manager负责从远程API获取数据。它是一个简单的对象,具有与django模型管理器类似的方法。它一定是抽象模型。
其他
- ReactJS integration - for large tables with thousands rows we have integrated https://github.com/glittershark/reactable as ^{tt2}$
- LinkedListColumn
- set of common filters, templatetags
Requires
- Django
- 地平线-OpenStack仪表板的一部分
Tested with
- 地平线2012+(冰屋+)
- Django 1.4+
- Python2.6+
Installation
pip install testrepository
pip install horizon-contrib
pip install git+https://github.com/michaelkuty/horizon-contrib.git#egg=horizon-contrib
现在按照您的意愿安装Horizon,如果您不知道,请使用以下命令:
pip install horizon-contrib[horizon]
Configuration
INSTALLED_APPS+=('horizon_contrib',)
下一个配置取决于您的方案
对于通常的django应用程序,我们必须包含horizon_contrib.urls或包含horizon.urls。如果我们包含horizon的url,contrib url将被映射为horizon仪表板。
fromdjango.conf.urlsimportpatterns,include,urlurlpatterns=patterns('',...url(r'^contrib/',include('horizon_contrib.urls'),),...# orurl(r'^horizon/',include('horizon.urls'),),)
Django example
有了django模型,没有任何代码,一切都可以正常工作。仅将浏览器导航到
- /contrib/models/project/index
- /contrib/models/project/create
- /contrib/models/project/1/update
有关覆盖行为,请参阅文档。
Horizon example REST-API !
仪表板结构:
my_dashboard |-- __init__.py |-- projects |-- __init__.py |-- models.py # define data structure |-- managers.py # load remote data |-- panel.py # register namespace |-- dashboard.py
您的models.py
fromhorizon_contrib.apiimportAPIModelfromhorizon_contrib.commonimportregister_modelclassProject(APIModel):name=models.CharField('id',primary_key=True)# default primary is iddescription=models.CharField.....objects=Manager()# see belowclassMeta:verbose_name='Project'abstract=Trueregister_model(Project)# supply Django Content Type framework
新的managers.py
fromhorizon_contrib.apiimportManagerclassManager(Manager):defall(self,*args,**kwargs):returnself.request('/projects')
最后panel.py
fromhorizon_contrib.panelimportModelPanelfromhorizon_redmine.dashboardimportRedmineDashboardclassProjectPanel(ModelPanel):name="Projects"slug='projects'model_class='project'RedmineDashboard.register(ProjectPanel)
将浏览器导航到
- /contrib/models/project/index
- /contrib/models/project/create
- /contrib/models/project/1/update
用于React Sorttable
pip install xstatic-react
添加到settings.py
importxstatic.pkg.reactSTATICFILES_DIRS=[('lib',xstatic.main.XStatic(xstatic.pkg.react).base_dir),]
- /contrib/models/project/react…
fromhorizon_contrib.tablesimportReactTable
有关更多代码,请参见[Documentation]。