One note about my development environment: I wanted to use the packaged version of CubicWeb and cubes while keeping my cube in my user directory, let’s say ~src/cubes. I achieve this by setting the following environment variables:
CW_CUBES_PATH=~/src/cubes
CW_MODE=user
I can now create the cube which will hold custom code for this web site using:
cubicweb-ctl newcube --directory=~/src/cubes sytweb
Almost everything I want to handle in my web-site is somehow already modelized in existing cubes that I’ll extend for my need. So I’ll pick the following cubes:
Ok, now I’ll tell my cube requires all this by editing cubes/sytweb/__pkginfo__.py:
__depends__ = {'cubicweb': '>= 3.10.0', 'cubicweb-file': '>= 1.9.0', 'cubicweb-folder': '>= 1.1.0', 'cubicweb-person': '>= 1.2.0', 'cubicweb-comment': '>= 1.2.0', 'cubicweb-tag': '>= 1.2.0', 'cubicweb-zone': None}
Notice that you can express minimal version of the cube that should be used, None meaning whatever version available. All packages starting with ‘cubicweb-‘ will be recognized as being cube, not bare python packages. You can still specify this explicitly using instead the __depends_cubes__ dictionary which should contains cube’s name without the prefix. So the example below would be written as:
__depends__ = {'cubicweb': '>= 3.10.0'} __depends_cubes__ = {'file': '>= 1.9.0', 'folder': '>= 1.1.0', 'person': '>= 1.2.0', 'comment': '>= 1.2.0', 'tag': '>= 1.2.0', 'zone': None}
If your cube is packaged for debian, it’s a good idea to update the debian/control file at the same time, so you won’t forget it.
from yams.buildobjs import RelationDefinition
class comments(RelationDefinition):
subject = 'Comment'
object = 'File'
cardinality = '1*'
composite = 'object'
class tags(RelationDefinition):
subject = 'Tag'
object = 'File'
class filed_under(RelationDefinition):
subject = 'File'
object = 'Folder'
class situated_in(RelationDefinition):
subject = 'File'
object = 'Zone'
class displayed_on(RelationDefinition):
subject = 'Person'
object = 'File'
This schema:
This schema will probably have to evolve as time goes (for security handling at least), but since the possibility to let a schema evolve is one of CubicWeb’s features (and goals), we won’t worry about it for now and see that later when needed.
Now that I have a schema, I want to create an instance. To do so using this new ‘sytweb’ cube, I run:
cubicweb-ctl create sytweb sytweb_instance
Hint: if you get an error while the database is initialized, you can avoid having to answer the questions again by running:
cubicweb-ctl db-create sytweb_instance
This will use your already configured instance and start directly from the create database step, thus skipping questions asked by the ‘create’ command.
Once the instance and database are fully initialized, run
cubicweb-ctl start sytweb_instance
to start the instance, check you can connect on it, etc...