Building my photos web site with CubicWeb (Part I)

Desired features

  • photo gallery;
  • photo stored onto the fs and displayed through a web interface dynamically;
  • navigation through folder (album), tags, geographical zone, people on the picture... using facets;
  • advanced security (eg not everyone can see everything). More on this later.

Let's go then

Step 1: creating a new cube for my web site

One note about my development environment: I wanted to use packaged version of CubicWeb and cubes while keeping my cube in my user directory, let's say ~src/cubes. It can be done by setting the following environment variables:

CW_CUBES_PATH=~/src/cubes CW_MODE=user

The new cube, holding custom code for this web site, can now be created using:

cubicweb-ctl newcube --directory=~/src/cubes sytweb

Step 2: pick building blocks into existing cubes

Almost everything I want to represent in my web-site is somewhat already modelized in existing cubes that I'll extend for my needs:

  • folder, containing Folder entity type, which will be used as both 'album' and a way to map file system folders. Entities are added to a given folder using the filed_under relation.
  • file, containing File and Image entity type, gallery view, and a file system import utility.
  • zone, containing the Zone entity type for hierarchical geographical zones. Entities (including sub-zones) are added to a given zone using the situated_in relation.
  • person, containing the Person entity type plus some basic views.
  • comment, providing a full commenting system allowing one to comment entity types supporting the comments relation by adding a Comment entity.
  • tag, providing a full tagging system as an easy and powerful way to classify entities supporting the tags relation by linking the to Tag entities. This will allow navigation into a large number of pictures.

Ok, now I'll tell my cube requires all this by editing cubes/sytweb/

depends_cubes = {'file': '>= 1.2.0',
'folder': '>= 1.1.0',
'person': '>= 1.2.0',
'comment': '>= 1.2.0',
'tag': '>= 1.2.0',
'zone': None,
depends = {'cubicweb': '>= 3.5.10',
for key,value in depends_cubes.items():
depends['cubicweb-'+key] = value
use = tuple(depends_cubes)

Notice that you can express minimal version of the cube that should be used, None meaning whatever version available.

Step 3: glue everything together in my cube's schema

from yams.buildobjs import RelationDefinitionclass comments(RelationDefinition):
subject = 'Comment'
object = ('File', 'Image')
cardinality = '1*'
composite = 'object'class tags(RelationDefinition):
subject = 'Tag'
object = ('File', 'Image')class filed_under(RelationDefinition):
subject = ('File', 'Image')
object = 'Folder'class situated_in(RelationDefinition):
subject = 'Image'
object = 'Zone'class displayed_on(RelationDefinition):
subject = 'Person'
object = 'Image'

This schema:

  • allows to comment and tag File and Image entity types by adding the comments and tags relations. This should be all we have to do for this feature since the related cubes provide 'pluggable section' which are automatically displayed in the primary view of entity types supporting the relation.
  • adds a situated_in relation definition so that image entities can be geolocalized.
  • add a new relation displayed_on relation telling who can be seen on a picture.

This schema will probably have to evolve as time goes (for security handling at least), but since the possibility to change and update the schema evolving is one of CubicWeb features (and goals), we won't worry and see that later when needed.

Step 4: creating the instance

Now that I have a schema, I want to create an instance of that new 'sytweb' cube, so I run:

cubicweb-ctl create sytweb sytweb_instance

hint: if you get an error while the database is initialized, you can avoid having to reanswer to questions by running

cubicweb-ctl db-create sytweb_instance

This will use your already configured instance and start directly from the database creation 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...

Next times

We will customize the index page, see security configuration, use the Bytes FileSystem Storage... Lots of cool stuff remaining :)

Next post : security, testing and migration