doc/dev/refactoring-the-css-with-uiprops.rst
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 30 Nov 2017 11:55:35 +0100
changeset 12242 68ca7fe0ca29
parent 10492 68c13e0c0fc5
permissions -rw-r--r--
[ssplanner] Prevent execution of write queries involving computed relations Previously, setting a computed relation upon entity creation or modification (using the ORM or an RQL query) would usually fail with an operational error in the backend ("no such table"). However, under some mysterious circumstances (like passing a string as value in cw_set for a computed relation), the RQL to SQL transformation would simply drop the clause. To prevent this to happen, we add a check for computed relation before adding a relation to an execution plan. This check raises a QueryError. It happens in several places: * in querier.InsertPlan.add_relation_def() (called from several places in ssplanner steps) for INSERT queries, * in ssplanner.UpdateStep.execute() for SET queries and, * in ssplanner.SSplanner.build_delete_plan() for DELETE queries. Tests added to unittest_querier.py because unittest_sslplanner.py looked inappropriate (it has only unit tests) and the former already had a NonRegressionTC class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5482
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     1
=========================================
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     2
Refactoring the CSSs with UI properties
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     3
=========================================
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     4
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     5
Overview
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     6
=========
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     7
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     8
Managing styles progressively became difficult in CubicWeb. The
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     9
introduction of uiprops is an attempt to fix this problem.
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    10
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    11
The goal is to make it possible to use variables in our CSSs.
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    12
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    13
These variables are defined or computed in the uiprops.py python file
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    14
and inserted in the CSS using the Python string interpolation syntax.
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    15
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    16
A quick example, put in ``uiprops.py``::
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    17
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    18
  defaultBgColor = '#eee'
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    19
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    20
and in your css::
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    21
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    22
  body { background-color: %(defaultBgColor)s; }
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    23
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    24
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    25
The good practices are:
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    26
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    27
- define a variable in uiprops to avoid repetitions in the CSS
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    28
  (colors, borders, fonts, etc.)
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    29
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    30
- define a variable in uiprops when you need to compute values
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    31
  (compute a color palette, etc.)
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    32
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    33
The algorithm implemented in CubicWeb is the following:
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    34
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    35
- read uiprops file while walk up the chain of cube dependencies: if
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    36
  cube myblog depends on cube comment, the variables defined in myblog
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    37
  will have precedence over the ones in comment
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    38
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    39
- replace the %(varname)s in all the CSSs of all the cubes
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    40
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    41
Keep in mind that the browser will then interpret the CSSs and apply
8c8c6d3f3b3a [css] start using uiprops in cubicweb.css
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    42
the standard cascading mechanism.