doc/book/en/01-introduction.en.txt
author Sandrine Ribeau <sandrine.ribeau@logilab.fr>
Mon, 17 Nov 2008 23:54:24 -0800
changeset 95 a5c7609de579
parent 93 9c919a47e140
child 97 d507caa1b386
permissions -rw-r--r--
[doc] Initial translation of index and introduction for book/en.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     3
.. _Overview:
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     4
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     5
Quick overview of `CubicWeb`
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     6
============================
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     7
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     8
`CubicWeb` allows us to develop web applications instances based on
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     9
one or more `cubes`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    10
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    11
What we call a `cube` is a model defining the data types and views. 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    12
A `cube` is a reusable component grouped with others cubes in the file
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    13
system.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    14
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    15
An `instance` refers to a specific installation of one or more `cubes`
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    16
 where are grouped configuration files of the final web application.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    17
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    18
In this document, we will show you how to create a `cube` and how to use it
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    19
in an `instance` for your web application.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    20
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    21
Create your cube
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    22
----------------
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    23
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    24
After you installed your `CubicWeb` development environment, you can start
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    25
to build your first cube: ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    26
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    27
  cubicweb-ctl newcube blog
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    28
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    29
This will create in ``/path/to/forest/cubes`` a directory containing: ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    30
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    31
  blog/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    32
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    33
  |-- data/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    34
  |   |-- cubes.blog.css
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    35
  |   |-- cubes.blog.js  
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    36
  |   |-- external_resources
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    37
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    38
  |-- debian/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    39
  |   |-- changelog
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    40
  |   |-- compat
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    41
  |   |-- control
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    42
  |   |-- copyright
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    43
  |   |-- cubicweb-blog.prerm
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    44
  |   |-- rules
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    45
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
  |-- entities.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    47
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    48
  |-- i18n/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    49
  |   |-- en.po
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    50
  |   |-- fr.po
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    51
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    52
  |-- __init__.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    53
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    54
  |-- MANIFEST.in
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    55
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    56
  |-- migration/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    57
  |   |-- postcreate.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    58
  |   |-- precreate.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    59
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    60
  |-- __pkginfo__.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    61
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    62
  |-- schema.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    63
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    64
  |-- setup.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    65
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    66
  |-- site_cubicweb.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    67
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    68
  |-- sobjects.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    69
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    70
  |-- test/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    71
  |   |-- data/
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    72
  |       |-- bootstrap_cubes
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    73
  |   |-- pytestconf.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    74
  |   |-- realdb_test_blog.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    75
  |   |-- test_blog.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    76
  |
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    77
  |-- views.py
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    78
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    79
Any changes applied to your data model should be done in this
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    80
directory.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    81
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    82
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    83
Define your data schema
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    84
-----------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    85
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    86
The data model or schema is hte core of your `CubicWeb` application.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    87
This is where is defined the type of content you application will handle.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    88
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    89
The data model is defined in the file ``schema.py`` of your cube
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    90
``blog`` such as follows.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    91
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    92
::
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    94
  from cubicweb.schema import format_constraint
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    95
  class Blog(EntityType):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    96
    title = String(maxsize=50, required=True)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    97
    description = String()
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    98
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    99
  class BlogEntry(EntityType):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   100
    title = String(required=True, fulltextindexed=True, maxsize=256)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   101
    publish_date = Date(default='TODAY')
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   102
    content = String(required=True, fulltextindexed=True)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
    entry_of = SubjectRelation('Blog', cardinality='?*') 
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   104
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   105
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   106
A Blog has a title and a description. The title is a string that is
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   107
required by the class EntityType and must be less than 50 characters. 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   108
The description is a string that is not constrained.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   109
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   110
A BlogEntry has a title, a publish_date and a content. The title is a
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   111
string that is required and must be less than 100 characters. The
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   112
publish_date is a Date with a default value of TODAY, meaning that
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   113
when a BlogEntry is created, its publish_date will be the current day
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   114
unless it is modified. The content is a string that will be indexed in
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   115
the full-text index and has no constraint.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   116
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   117
A BlogEntry also has a relationship ``entry_of`` that links it to a
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   118
Blog. The cardinality ``?*`` means that a BlogEntry can be part of
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   119
zero or one Blog (``?`` means `zero or one`) and that a Blog can
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   120
have any number of BlogEntry (``*`` means `any number including
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   121
zero`). For completeness, remember that ``+`` means `one or more`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   122
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   123
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   124
Create your instance
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   125
--------------------
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   126
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   127
::
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   128
  
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   129
  cubicweb-ctl create blog blogdemo
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   130
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   131
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   132
This command will create a directory ``~/etc/cubicweb.d/blogdemo``
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   133
which will contain all the configuration files required to start
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   134
you web application.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   135
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   136
The instance ``blogdemo`` is based on the cube ``blog``.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   137
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   138
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   139
Welcome in your web application
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   140
-------------------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   142
Run your application with the following command: ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   143
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   144
  cubicweb-ctl start -D blogdemo
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   145
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   146
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   147
You can now access to your web application to create blogs and post messages
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   148
by visitin the URL http://localhost:8080/.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   149
A login form will first be prompted. By default, the application will not allow
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   150
anonymous user to get in the application. You should then use the admin
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   151
account you created at the time you initialized the database with
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   152
``cubicweb-ctl create``.
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   153
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   154
.. image:: images/login-form.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   155
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   157
Once authenticated, you can start playing with your application 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   158
and create entities. Bravo!
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   159
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   160
.. image:: images/blog-demo-first-page.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   162
Please notice that so far, `CubicWeb` franework managed all aspects of 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   163
the web application based in the schema provided at first.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   165
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   166
Create entities
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   167
---------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   169
We will now create a couple of entities in our web application.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   170
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   171
Create a Blog
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   172
~~~~~~~~~~~~~
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   173
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   174
Let us create a few of these entities. Click on the `[+]` at the right
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   175
of the link Blog.  Call this new Blog ``Tech-blog`` and type in
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   176
``everything about technology`` as the description, then validate the
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   177
form by clicking on ``Validate``.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   178
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   179
.. image:: images/cbw-create-blog.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   180
   :alt: from to create blog
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   181
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   182
Click on the logo at top left to get back to the home page, then
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   183
follow the Blog link that will list for you all the existing Blog.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   184
You should be seeing a list with a single item ``Tech-blog`` you
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   185
just created.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   186
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   187
.. image:: images/cbw-list-one-blog.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   188
   :alt: displaying a list of a single blog
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   189
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   190
Clicking on this item will get you to its detailed description except
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   191
that in this case, there is not much to display besides the name and
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   192
the phrase ``everything about technology``.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   193
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   194
Now get back to the home page by clicking on the top-left logo, then
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   195
create a new Blog called ``MyLife`` and get back to the home page
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   196
again to follow the Blog link for the second time. The list now
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   197
has two items.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   198
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   199
.. image:: images/cbw-list-two-blog.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   200
   :alt: displaying a list of two blogs
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   201
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   202
Create a BlogEntry
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   203
~~~~~~~~~~~~~~~~~~
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   204
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   205
Get back to the home page and click on [+] at the right of the link
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   206
BlogEntry. Call this new entry ``Hello World`` and type in some text
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   207
before clicking on ``Validate``. You added a new blog entry without
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   208
saying to what blog it belongs. There is a box on the left entitled
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   209
``actions``, click on the menu item ``modify``. You are back to the form
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   210
to edit the blog entry you just created, except that the form now has
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   211
another section with a combobox titled ``add relation``. Chose
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   212
``entry_of`` in this menu and a second combobox appears where you pick
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   213
``MyLife``. 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   214
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   215
You could also have, at the time you started to fill the form for a
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   216
new entity BlogEntry, hit ``Apply`` instead of ``Validate`` and the 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   217
combobox titled ``add relation`` would have showed up.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   218
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   219
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   220
.. image:: images/cbw-add-relation-entryof.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   221
   :alt: editing a blog entry to add a relation to a blog
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   222
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   223
Validate the changes by clicking ``Validate``. The entity BlogEntry
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   224
that is displayed now includes a link to the entity Blog named
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   225
``MyLife``.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   226
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   227
.. image:: images/cbw-detail-one-blogentry.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   228
   :alt: displaying the detailed view of a blogentry
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   229
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   230
Please notice that so far, `CubicWeb` franework managed all aspects of 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   231
the web application based in the schema provided at first.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   232
Also if you wish to get a graphical view of the schema, visit
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   233
the link `Application schema`` which will direct you to :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   234
http://localhost:8080/view?vid=schema
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   235
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   236
.. image:: images/cbw-schema.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   237
   :alt: graphical view of the schema (aka data-model)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   238
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   239
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   240
Define your entities views
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   241
--------------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   242
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   243
The views selection principle
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   244
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   245
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   246
A view is defined by a Python class which includes: 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   247
  
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   248
  - an identifier (all objects in `CubicWeb` are entered in a registry
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   249
    and this identifier will be used as a key)
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   250
  
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   251
  - a filter to select the resulsets it can be applied to
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   252
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   253
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   254
`CubicWeb` provides a lot of standard views for the type
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   255
`EntityView`, for a complete list, you
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   256
will have to read the code in directory ``cubicweb/web/views/``
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   257
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   258
A view is applied on a `result set` which contains a set of
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   259
entities we are trying to display. `CubicWeb` uses a selector
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   260
mecanism which computes a score used to identify which view
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   261
is the best to apply for the `result set` we are trying to 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   262
display. The standard library of selectors is in 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   263
``cubicweb.common.selector`` and a library of methods used to
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   264
compute scores is available in ``cubicweb.vregistry.vreq``.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   265
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   266
It is possible to define multiple views for the same identifier
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   267
and to associate selectors and filters to allow the application
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   268
to find the best way to render the data. We will see more details
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   269
on this in :ref:`DefinitionVues`.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   270
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   271
For example, the view named ``primary`` is the one used to display
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   272
a single entity. We will now show you hos to customize this view.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   273
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   274
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   275
View customization
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   276
~~~~~~~~~~~~~~~~~~
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   277
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   278
If you wish to modify the way a `BlogEntry` is rendered, you will have to 
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   279
overwrite the `primary` view defined in the module ``views`` of the cube
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   280
``cubes/blog/views.py``.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   281
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   282
We can by example add in front of the pulication date a prefix specifying
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   283
the date we see is the publication date.
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   284
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   285
To do so, please apply the following changes:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   286
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   287
:: 
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   288
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   289
  from cubicweb.web.views import baseviews
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   290
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   291
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   292
  class BlogEntryPrimaryView(baseviews.PrimaryView):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   293
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   294
    accepts = ('BlogEntry',)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   295
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   296
    def render_entity_title(self, entity):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   297
        self.w(u'<h1>%s</h1>' % html_escape(entity.dc_title()))
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   298
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   299
    def content_format(self, entity):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   300
        return entity.view('reledit', rtype='content_format')
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   301
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   302
    def cell_call(self, row, col):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   303
        entity = self.entity(row, col)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   304
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   305
        # display entity attributes with prefixes
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   306
        self.w(u'<h1>%s</h1>' % entity.title)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   307
        self.w(u'<p>published on %s</p>' % entity.publish_date.strftime('%Y-%m-%d'))
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   308
        self.w(u'<p>%s</p>' % entity.content)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   309
        
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   310
        # display relations
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   311
        siderelations = []
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   312
        if self.main_related_section:
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   313
            self.render_entity_relations(entity, siderelations)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   314
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   315
.. note::
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   316
  When a view is modified, it is not required to restart the application
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   317
  server. Save the Python file and reload the page in your web browser
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   318
  to view the changes.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   319
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   320
You can now see that the publication date has a prefix.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   321
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   322
.. image:: images/cbw-update-primary-view.en.png
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   323
   :alt: modified primary view
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   324
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   325
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   326
The above source code defines a new primary view for
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   327
``BlogEntry``. 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   328
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   329
Le code que nous avons modifié définit une vue primaire pour une entité de 
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   330
type `BlogEntry`. 
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   331
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   332
Since views are applied to resultsets and resulsets can be tables of
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   333
data, it is needed to recover the entity from its (row,col)
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   334
coordinates. We will get to this in more detail later.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   335
95
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   336
The view has a ``self.w()`` method that is used to output data. In our
a5c7609de579 [doc] Initial translation of index and introduction for book/en.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   337
example we use it to output HTML tags and values of the entity's attributes.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   338