doc/tutorials/advanced/part05_ui-advanced.rst
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 22 Mar 2019 17:29:15 +0100
changeset 12539 10159a3d1d72
parent 12417 d0206861996a
child 12556 d1c659d70368
permissions -rw-r--r--
Drop deprecated CWCache entity type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
     1
Building my photos web site with |cubicweb| part V: let's make it even more user friendly
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
=========================================================================================
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
7529
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6880
diff changeset
     4
.. _uiprops:
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6880
diff changeset
     5
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
     6
Step 1: tired of the default look?
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
     9
OK... Now our site has its most desired features. But... I would like to make it look
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
    10
somewhat like *my* website. It is not www.cubicweb.org after all. Let's tackle this
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
first!
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
The first thing we can to is to change the logo. There are various way to achieve
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    14
this. The easiest way is to put a :file:`logo.png` file into the cube's :file:`data`
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
    15
directory. As data files are looked at according to cubes order (CubicWeb
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
    16
resources coming last), that file will be selected instead of CubicWeb's one.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
.. Note::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
   As the location for static resources are cached, you'll have to restart
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
   your instance for this to be taken into account.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    22
Though there are some cases where you don't want to use a :file:`logo.png` file.
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    23
For instance if it's a JPEG file. You can still change the logo by defining in
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    24
the cube's :file:`uiprops.py` file:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
   LOGO = data('logo.jpg')
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
12414
34e89d5e5e51 [doc] add a note because uiprops.py is not generated anymore by default
Laurent Peuch <cortex@worlddomination.be>
parents: 12407
diff changeset
    30
.. Note::
34e89d5e5e51 [doc] add a note because uiprops.py is not generated anymore by default
Laurent Peuch <cortex@worlddomination.be>
parents: 12407
diff changeset
    31
   If the file :file:`uiprops.py` doesn't exist in your cube, simply create it.
34e89d5e5e51 [doc] add a note because uiprops.py is not generated anymore by default
Laurent Peuch <cortex@worlddomination.be>
parents: 12407
diff changeset
    32
9256
697a8181ba30 remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    33
The uiprops machinery is used to define some static file resources,
697a8181ba30 remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    34
such as the logo, default Javascript / CSS files, as well as CSS
697a8181ba30 remove 3.9 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    35
properties (we'll see that later).
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
.. Note::
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
   This file is imported specifically by |cubicweb|, with a predefined name space,
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
   containing for instance the `data` function, telling the file is somewhere
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
    40
   in a cube or CubicWeb's data directory.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
   One side effect of this is that it can't be imported as a regular python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
   module.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
The nice thing is that in debug mode, change to a :file:`uiprops.py` file are detected
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
and then automatically reloaded.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
Now, as it's a photos web-site, I would like to have a photo of mine as background...
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
After some trials I won't detail here, I've found a working recipe explained `here`_.
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
    50
All I've to do is to override some stuff of the default CubicWeb user interface to
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
apply it as explained.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    53
The first thing to to get the ``<img/>`` tag as first element after the
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    54
``<body>`` tag.  If you know a way to avoid this by simply specifying the image
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    55
in the CSS, tell me!  The easiest way to do so is to override the
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    56
:class:`HTMLPageHeader` view, since that's the one that is directly called once
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    57
the ``<body>`` has been written. How did I find this?  By looking in the
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    58
:mod:`cubiweb.web.views.basetemplates` module, since I know that global page
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    59
layouts sits there. I could also have grep the "body" tag in
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    60
:mod:`cubicweb.web.views`... Finding this was the hardest part. Now all I need is
12407
d4e0af0b5ad7 [doc] uses :file:`name` everywhere + indicate file when it's not present
Laurent Peuch <cortex@worlddomination.be>
parents: 12405
diff changeset
    61
to customize it to write that ``img`` tag, as below in :file:`views.py`:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
12415
6c23631b887e [doc] missing import in code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12414
diff changeset
    65
    from cubicweb.web.views import basetemplates
6c23631b887e [doc] missing import in code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12414
diff changeset
    66
6c23631b887e [doc] missing import in code example
Laurent Peuch <cortex@worlddomination.be>
parents: 12414
diff changeset
    67
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
    class HTMLPageHeader(basetemplates.HTMLPageHeader):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    69
        # override this since it's the easier way to have our bg image
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    70
        # as the first element following <body>
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    71
        def call(self, **kwargs):
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
            self.w(u'<img id="bg-image" src="%sbackground.jpg" alt="background image"/>'
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
                   % self._cw.datadir_url)
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    74
            super(HTMLPageHeader, self).call(**kwargs)
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
    def registration_callback(vreg):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    78
        vreg.register_all(globals().values(), __name__, (HTMLPageHeader))
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
    79
        vreg.register_and_replace(HTMLPageHeader, basetemplates.HTMLPageHeader)
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    82
As you may have guessed, my background image is in a :file:`background.jpg` file
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    83
in the cube's :file:`data` directory, but there are still some things to explain
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    84
to newcomers here:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    86
* The :meth:`call` method is there the main access point of the view. It's called by
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    87
  the view's :meth:`render` method. It is not the only access point for a view, but
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
    88
  this will be detailed later.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
    90
* Calling `self.w` writes something to the output stream. Except for binary views
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
    91
  (which do not generate text), it *must* be passed an Unicode string.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    93
* The proper way to get a file in :file:`data` directory is to use the `datadir_url`
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
  attribute of the incoming request (e.g. `self._cw`).
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    96
I won't explain again the :func:`registration_callback` stuff, you should understand it
12416
30b83cf45dd4 [doc] add actual link to previous post
Laurent Peuch <cortex@worlddomination.be>
parents: 12415
diff changeset
    97
now!  If not, go back to `previous post in the series`_ :)
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
    99
Fine. Now all I've to do is to add a bit of CSS to get it to behave nicely (which
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   100
is not the case at all for now). I'll put all this in a :file:`cubes.sytweb.css`
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   101
file, stored as usual in our :file:`data` directory:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
.. sourcecode:: css
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
    /* fixed full screen background image
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
     * as explained on http://webdesign.about.com/od/css3/f/blfaqbgsize.htm
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
     *
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
     * syt update: set z-index=0 on the img instead of z-index=1 on div#page & co to
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
     * avoid pb with the user actions menu
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
     */
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   112
    img#bg-image {
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   113
        position: fixed;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   114
        top: 0;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   115
        left: 0;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   116
        width: 100%;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   117
        height: 100%;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   118
        z-index: 0;
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
    }
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   120
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   121
    div#page, table#header, div#footer {
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   122
        background: transparent;
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   123
        position: relative;
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   124
    }
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
    /* add some space around the logo
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
     */
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   128
    img#logo {
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   129
        padding: 5px 15px 0px 15px;
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   130
    }
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   131
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
    /* more dark font for metadata to have a chance to see them with the background
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
     *  image
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
     */
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
    div.metadata {
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   136
        color: black;
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
    }
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
You can see here stuff explained in the cited page, with only a slight modification
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   140
explained in the comments, plus some additional rules to make things somewhat cleaner:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
* a bit of padding around the logo
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
* darker metadata which appears by default below the content (the white frame in the page)
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   146
To get this CSS file used everywhere in the site, I have to modify the :file:`uiprops.py` file
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   147
introduced above:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
   STYLESHEETS = sheet['STYLESHEETS'] + [data('cubes.sytweb.css')]
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   153
.. Note::
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
   `sheet` is another predefined variable containing values defined by
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   155
   already process `:file:`uiprops.py`` file, notably the CubicWeb's one.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   156
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   157
Here we simply want our CSS in addition to CubicWeb's base CSS files, so we
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   158
redefine the `STYLESHEETS` variable to existing CSS (accessed through the `sheet`
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   159
variable) with our one added. I could also have done:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   162
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
   sheet['STYLESHEETS'].append(data('cubes.sytweb.css'))
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   165
But this is less interesting since we don't see the overriding mechanism...
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
At this point, the site should start looking good, the background image being
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
resized to fit the screen.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   169
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   170
.. image:: ../../images/tutos-photowebsite_background-image.png
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   171
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   172
The final touch: let's customize CubicWeb's CSS to get less orange... By simply adding
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   173
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   174
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   175
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   176
  contextualBoxTitleBg = incontextBoxTitleBg = '#AAAAAA'
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   177
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   178
and reloading the page we've just seen, we know have a nice greyed box instead of
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   179
the orange one:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   180
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   181
.. image:: ../../images/tutos-photowebsite_grey-box.png
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   183
This is because CubicWeb's CSS include some variables which are
12407
d4e0af0b5ad7 [doc] uses :file:`name` everywhere + indicate file when it's not present
Laurent Peuch <cortex@worlddomination.be>
parents: 12405
diff changeset
   184
expanded by values defined in :file:`uiprops.py` file. In our case we controlled the
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   185
properties of the CSS `background` property of boxes with CSS class
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   186
`contextualBoxTitleBg` and `incontextBoxTitleBg`.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   187
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   189
Step 2: configuring boxes
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   190
~~~~~~~~~~~~~~~~~~~~~~~~~
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   191
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   192
Boxes present to the user some ways to use the application. Let's first do a few
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   193
user interface tweaks in our :file:`views.py` file:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   196
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   197
  from cubicweb.predicates import none_rset
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   198
  from cubicweb.web.views import bookmark
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   199
  from cubes.zone import views as zone
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
  from cubes.tag import views as tag
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   201
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   202
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   203
  # change bookmarks box selector so it's only displayed on startup views
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   204
  bookmark.BookmarksBox.__select__ = bookmark.BookmarksBox.__select__ & none_rset()
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
  # move zone box to the left instead of in the context frame and tweak its order
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
  zone.ZoneBox.context = 'left'
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
  zone.ZoneBox.order = 100
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
  # move tags box to the left instead of in the context frame and tweak its order
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
  tag.TagsBox.context = 'left'
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
  tag.TagsBox.order = 102
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
  # hide similarity box, not interested
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
  tag.SimilarityBox.visible = False
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   214
The idea is to move all boxes in the left column, so we get more space for the
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   215
photos.  Now, serious things: I want a box similar to the tags box but to handle
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   216
the `Person displayed_on File` relation. We can do this simply by adding a
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   217
:class:`AjaxEditRelationCtxComponent` subclass to our views, as below:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
12417
d0206861996a [doc] missing import, cw now require this explicitely
Laurent Peuch <cortex@worlddomination.be>
parents: 12416
diff changeset
   221
    from cubicweb import _
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   222
    from logilab.common.decorators import monkeypatch
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
    from cubicweb import ValidationError
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8190
diff changeset
   224
    from cubicweb.web.views import uicfg, component
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
    from cubicweb.web.views import basecontrollers
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   226
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   227
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   228
    # hide displayed_on relation using uicfg since it will be displayed by the box below
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   229
    uicfg.primaryview_section.tag_object_of(('*', 'displayed_on', '*'), 'hidden')
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   230
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   231
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   232
    class PersonBox(component.AjaxEditRelationCtxComponent):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   233
        __regid__ = 'sytweb.displayed-on-box'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   234
        # box position
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   235
        order = 101
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   236
        context = 'left'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   237
        # define relation to be handled
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   238
        rtype = 'displayed_on'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   239
        role = 'object'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   240
        target_etype = 'Person'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   241
        # messages
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   242
        added_msg = _('person has been added')
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   243
        removed_msg = _('person has been removed')
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   244
        # bind to js_* methods of the json controller
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   245
        fname_vocabulary = 'unrelated_persons'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   246
        fname_validate = 'link_to_person'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   247
        fname_remove = 'unlink_person'
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   248
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   249
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   250
    @monkeypatch(basecontrollers.JSonController)
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   251
    @basecontrollers.jsonize
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   252
    def js_unrelated_persons(self, eid):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   253
        """return tag unrelated to an entity"""
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   254
        rql = "Any F + ' ' + S WHERE P surname S, P firstname F, X eid %(x)s, NOT P displayed_on X"
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   255
        return [name for (name,) in self._cw.execute(rql, {'x' : eid})]
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   256
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   257
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   258
    @monkeypatch(basecontrollers.JSonController)
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   259
    def js_link_to_person(self, eid, people):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   260
        req = self._cw
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   261
        for name in people:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   262
            name = name.strip().title()
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   263
            if not name:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   264
                continue
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   265
            try:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   266
                firstname, surname = name.split(None, 1)
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   267
            except:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   268
                raise ValidationError(eid, {('displayed_on', 'object'): 'provide <first name> <surname>'})
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   269
            rset = req.execute('Person P WHERE '
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   270
                               'P firstname %(firstname)s, P surname %(surname)s',
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   271
                               locals())
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   272
            if rset:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   273
                person = rset.get_entity(0, 0)
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   274
            else:
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   275
                person = req.create_entity('Person', firstname=firstname,
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   276
                                                surname=surname)
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   277
            req.execute('SET P displayed_on X WHERE '
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   278
                        'P eid %(p)s, X eid %(x)s, NOT P displayed_on X',
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   279
                        {'p': person.eid, 'x' : eid})
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   280
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   281
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   282
    @monkeypatch(basecontrollers.JSonController)
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   283
    def js_unlink_person(self, eid, personeid):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   284
        self._cw.execute('DELETE P displayed_on X WHERE P eid %(p)s, X eid %(x)s',
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   285
                         {'p': personeid, 'x': eid})
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   286
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   287
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   288
You basically subclass to configure with some class attributes. The `fname_*`
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   289
attributes give the name of methods that should be defined on the json control to
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   290
make the AJAX part of the widget work: one to get the vocabulary, one to add a
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   291
relation and another to delete a relation. These methods must start by a `js_`
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   292
prefix and are added to the controller using the `@monkeypatch` decorator. In my
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   293
case, the most complicated method is the one which adds a relation, since it
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   294
tries to see if the person already exists, and else automatically create it,
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   295
assuming the user entered "firstname surname".
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   296
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   297
Let's see how it looks like on a file primary view:
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   298
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   299
.. image:: ../../images/tutos-photowebsite_boxes.png
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   300
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   301
Great, it's now as easy for me to link my pictures to people than to tag them.
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   302
Also, visitors get a consistent display of these two pieces of information.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   303
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   304
.. Note::
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   305
  The ui component system has been refactored in `CubicWeb 3.10`_, which also
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   306
  introduced the :class:`AjaxEditRelationCtxComponent` class.
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   307
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   308
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   309
Step 3: configuring facets
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   310
~~~~~~~~~~~~~~~~~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   311
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   312
The last feature we'll add today is facet configuration. If you access to the
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   313
'/file' url, you'll see a set of 'facets' appearing in the left column. Facets
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   314
provide an intuitive way to build a query incrementally, by proposing to the user
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   315
various way to restrict the result set. For instance CubicWeb proposes a facet to
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   316
restrict based on who created an entity; the tag cube proposes a facet to
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   317
restrict based on tags; the zoe cube a facet to restrict based on geographical
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   318
location, and so on. In that gist, I want to propose a facet to restrict based on
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   319
the people displayed on the picture. To do so, there are various classes in the
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   320
:mod:`cubicweb.web.facet` module which simply have to be configured using class
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   321
attributes as we've done for the box. In our case, we'll define a subclass of
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   322
:class:`RelationFacet`.
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   323
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   324
.. Note::
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   325
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   326
   Since that's ui stuff, we'll continue to add code below to our
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   327
   :file:`views.py` file. Though we begin to have a lot of various code their, so
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   328
   it's may be a good time to split our views module into submodules of a `view`
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   329
   package. In our case of a simple application (glue) cube, we could start using
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   330
   for instance the layout below: ::
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   331
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   332
     views/__init__.py   # uicfg configuration, facets
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   333
     views/layout.py     # header/footer/background stuff
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   334
     views/components.py # boxes, adapters
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   335
     views/pages.py      # index view, 404 view
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   336
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   337
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   338
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   339
    from cubicweb.web import facet
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   340
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   341
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   342
    class DisplayedOnFacet(facet.RelationFacet):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   343
        __regid__ = 'displayed_on-facet'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   344
        # relation to be displayed
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   345
        rtype = 'displayed_on'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   346
        role = 'object'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   347
        # view to use to display persons
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   348
        label_vid = 'combobox'
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   349
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   350
Let's say we also want to filter according to the `visibility` attribute. This is
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   351
even simpler as we just have to derive from the :class:`AttributeFacet` class:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   352
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   353
.. sourcecode:: python
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   354
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   355
    class VisibilityFacet(facet.AttributeFacet):
12405
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   356
        __regid__ = 'visibility-facet'
99e150b6a876 [doc] pep8/retab in code examples
Laurent Peuch <cortex@worlddomination.be>
parents: 10491
diff changeset
   357
        rtype = 'visibility'
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   358
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   359
Now if I search for some pictures on my site, I get the following facets available:
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   360
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   361
.. image:: ../../images/tutos-photowebsite_facets.png
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   362
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   363
.. Note::
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   364
6879
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   365
  By default a facet must be applyable to every entity in the result set and
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   366
  provide at leat two elements of vocabulary to be displayed (for instance you
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   367
  won't see the `created_by` facet if the same user has created all
54944faf9b61 [book] advanced tutorial part 5 improvments: add some roles, talk about cube's layout, strip image
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6877
diff changeset
   368
  entities). This may explain why you don't see yours...
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   369
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   370
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   371
Conclusion
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   372
~~~~~~~~~~
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   373
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   374
We started to see the power behind the infrastructure provided by the
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   375
framework, both on the pure ui (CSS, Javascript) side and on the Python side
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   376
(high level generic classes for components, including boxes and facets). We now
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   377
have, with a few lines of code, a full-featured web site with a personalized look.
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   378
6877
0e8fc441b38b blog proofreading
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6876
diff changeset
   379
Of course we'll probably want more as time goes, but we can now
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   380
concentrate on making good pictures, publishing albums and sharing them with
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   381
friends...
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   382
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   383
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   384
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6879
diff changeset
   385
.. _`CubicWeb 3.10`: http://www.cubicweb.org/blogentry/1330518
6876
4b0b9d8207c5 [doc] backport part 3 & 4 of the sytweb's tutorial + to be published part 5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   386
.. _`here`: http://webdesign.about.com/od/css3/f/blfaqbgsize.htm
12416
30b83cf45dd4 [doc] add actual link to previous post
Laurent Peuch <cortex@worlddomination.be>
parents: 12415
diff changeset
   387
.. _`previous post in the series`: part04_ui-base.rst