Cubicweb Documentation Release 3.20.7
Total Page:16
File Type:pdf, Size:1020Kb
Cubicweb Documentation Release 3.20.7 Logilab April 24, 2015 Contents 1 Introduction to CubicWeb 3 1.1 A little history................................................3 1.2 The Core Concepts of CubicWeb .....................................3 2 Tutorials 9 2.1 Building a simple blog with CubicWeb .................................9 2.2 Building a photo gallery with CubicWeb ................................. 30 2.3 Use Windmill with CubicWeb...................................... 57 2.4 Writing text reports with RestructuredText............................... 61 3 Repository development 63 3.1 Cubes................................................... 63 3.2 The Registry, selectors and application objects............................. 66 3.3 Data model................................................ 68 3.4 Data as objects.............................................. 83 3.5 Core APIs................................................ 90 3.6 Repository customization........................................ 95 3.7 Tests................................................... 102 3.8 Migration................................................. 111 3.9 Profiling and performance........................................ 115 3.10 Full Text Indexing in CubicWeb..................................... 116 3.11 Dataimport................................................ 118 4 Web side development 119 4.1 Publisher................................................. 119 4.2 Controllers................................................ 120 4.3 The Request class (cubicweb.web.request)................................ 121 4.4 RQL search bar.............................................. 126 4.5 The View system............................................. 126 4.6 Configuring the user interface...................................... 145 4.7 Ajax................................................... 146 4.8 Javascript................................................. 146 4.9 CSS Stylesheet.............................................. 151 4.10 Edition control.............................................. 151 4.11 The facets system............................................ 169 4.12 Internationalization............................................ 171 4.13 The property mecanism......................................... 174 4.14 HTTP cache management........................................ 174 i 4.15 Locate resources............................................. 174 4.16 Static files handling........................................... 174 5 Administration 177 5.1 Installation of a CubicWeb environment................................. 177 5.2 Installing a development environement on Windows.......................... 180 5.3 Set-up of a CubicWeb environment................................... 182 5.4 cubicweb-ctl tool.......................................... 188 5.5 Creation of your first instance...................................... 190 5.6 Configure an instance.......................................... 191 5.7 User interface for web site configuration................................ 195 5.8 Multiple sources of data......................................... 197 5.9 LDAP integration............................................. 197 5.10 Working with a distributed client (using Pyro).............................. 198 5.11 Migrating cubicweb instances - benefits from a distributed architecture................ 199 5.12 Backups (mostly with postgresql).................................... 200 5.13 RQL logs................................................. 201 6 Additional services 203 6.1 Undoing changes in CubicWeb..................................... 203 7 Appendixes 209 7.1 Frequently Asked Questions (FAQ)................................... 209 7.2 Relation Query Language (RQL).................................... 216 7.3 Introducing Mercurial.......................................... 232 7.4 Installation dependencies......................................... 234 7.5 Javascript docstrings........................................... 235 Python Module Index 237 ii Cubicweb Documentation, Release 3.20.7 CubicWeb is a semantic web application framework, licensed under the LGPL, that empowers developers to efficiently build web applications by reusing components (called cubes) and following the well known object-oriented design principles. Its main features are: • an engine driven by the explicit data model of the application, • a query language named RQL similar to W3C’s SPARQL, •a selection+view mechanism for semi-automatic XHTML/XML/JSON/text generation, • a library of reusable components (data model and views) that fulfill common needs, • the power and flexibility of the Python programming language, • the reliability of SQL databases, LDAP directories, Subversion and Mercurial for storage backends. Built since 2000 from an R&D effort still continued, supporting 100,000s of daily visits at some production sites, CubicWeb is a proven end to end solution for semantic web application development that promotes quality, reusability and efficiency. The unbeliever will read the Tutorials. The hacker will join development at the forge. The impatient developer will move right away to Installation of a CubicWeb environment then to Set-up of a CubicWeb environment. The chatter lover will join the jabber forum, the mailing-list and the blog. Contents 1 Cubicweb Documentation, Release 3.20.7 2 Contents CHAPTER 1 Introduction to CubicWeb This first part of the book offers different reading path to discover the CubicWeb framework, provides a tutorial to get a quick overview of its features and lists its key concepts. 1.1 A little history... CubicWeb is a semantic web application framework that Logilab started developing in 2001 as an offspring of its Narval research project. CubicWeb is written in Python and includes a data server and a web engine. Its data server publishes data federated from different sources like SQL databases, LDAP directories, VCS repositories or even from other CubicWeb data servers. Its web engine was designed to let the final user control what content to select and how to display it. It allows one to browse the federated data sources and display the results with the rendering that best fits the context. This flexibility of the user interface gives back to the user some capabilities usually only accessible to application developers. CubicWeb has been developed by Logilab and used in-house for many years before it was first installed for its clients in 2006 as version 2. In 2008, CubicWeb version 3 became downloadable for free under the terms of the LGPL license. Its community is now steadily growing without hampering the fast-paced stream of changes thanks to the time and energy originally put in the design of the framework. 1.2 The Core Concepts of CubicWeb This section defines some terms and core concepts of the CubicWeb framework. To avoid confusion while reading this book, take time to go through the following definitions and use this section as a reference during your reading. 1.2.1 Cubes A cube is a software component made of three parts: its data model (schema), its logic (entities) and its user interface (views). A cube can use other cubes as building blocks and assemble them to provide a whole with richer functionnalities than its parts. The cubes cubicweb-blog and cubicweb-comment could be used to make a cube named myblog with commentable blog entries. The CubicWeb.org Forge offers a large number of cubes developed by the community and available under a free software license. 3 Cubicweb Documentation, Release 3.20.7 Note: The command cubicweb-ctl list displays the list of available cubes. 1.2.2 Instances An instance is a runnable application installed on a computer and based on a cube. The instance directory contains the configuration files. Several instances can be created and based on the same cube. For exemple, several software forges can be set up on one computer system based on the cubicweb-forge cube. Instances can be of three different types: all-in-one, web engine or data repository. For applications that support high traffic, several web (front-end) and data (back-end) instances can be set-up to share the load. The command cubicweb-ctl list also displays the list of instances installed on your system. Note: The term application is used to refer to “something that should do something as a whole”, eg more like a project and so can refer to an instance or to a cube, depending on the context. This book will try to use application, cube and instance as appropriate. 4 Chapter 1. Introduction to CubicWeb Cubicweb Documentation, Release 3.20.7 1.2.3 Data Repository The data repository 1 encapsulates and groups an access to one or more data sources (including SQL databases, LDAP repositories, other CubicWeb instance repositories, filesystems, Google AppEngine’s DataStore, etc). All interactions with the repository are done using the Relation Query Language (RQL syntax). The repository feder- ates the data sources and hides them from the querier, which does not realize when a query spans several data sources and requires running sub-queries and merges to complete. Application logic can be mapped to data events happenning within the repository, like creation of entities, deletion of relations, etc. This is used for example to send email notifications when the state of an object changes. See Hooks and operations below. 1.2.4 Web Engine The web engine replies to http requests and runs the user interface. By default the web engine provides a CRUD user interface based on the data model of the