doc/book/en/tutorials/advanced/part04_ui-base.rst
branchstable
changeset 6923 327443ec7120
parent 6880 4be32427b2b9
child 7827 9bbf83f68bcc
equal deleted inserted replaced
6922:cb1dd14a768f 6923:327443ec7120
     1 Let's make it more user friendly
     1 Let's make it more user friendly
     2 ================================
     2 ================================
     3 
       
     4 
       
     5 Step 0: updating code to CubicWeb 3.9 / cubicweb-file 1.9
       
     6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
     7 
       
     8 CubicWeb 3.9 brings `several improvments`_ that we'll want to use, and the 1.9
       
     9 version of the file cube has a major change: the `Image` type has been dropped in
       
    10 favor of an `IImage` adapter that makes code globally much cleaner (though we wont
       
    11 see that much this here). So the first thing to do is to upgrade our cube to the
       
    12 3.9 API. As CubicWeb releases are mostly backward compatible, this is not
       
    13 mandatory but it's easier to follow change as they come than having a huge
       
    14 upgrade to do at some point. Also, this remove deprecation warnings which are a
       
    15 bit tedious...
       
    16 
       
    17 Also, since we've only a few lines of code yet, this is quite easy to upgrade.
       
    18 Actually the main thing we've to do is to upgrade our schema, to remove occurences
       
    19 of the `Image` type or replace them by the `File` type. Here is the (striped) diff:
       
    20 
       
    21 .. sourcecode:: diff
       
    22 
       
    23      class comments(RelationDefinition):
       
    24 	 subject = 'Comment'
       
    25     -    object = ('File', 'Image')
       
    26     +    object = 'File'
       
    27 	 cardinality = '1*'
       
    28 	 composite = 'object'
       
    29 
       
    30      class tags(RelationDefinition):
       
    31 	 subject = 'Tag'
       
    32     -    object = ('File', 'Image')
       
    33     +    object = 'File'
       
    34 
       
    35      class displayed_on(RelationDefinition):
       
    36 	 subject = 'Person'
       
    37     -    object = 'Image'
       
    38     +    object = 'File'
       
    39 
       
    40      class situated_in(RelationDefinition):
       
    41     -    subject = 'Image'
       
    42     +    subject = 'File'
       
    43 	 object = 'Zone'
       
    44 
       
    45      class filed_under(RelationDefinition):
       
    46     -    subject = ('File', 'Image')
       
    47     +    subject = 'File'
       
    48 	 object = 'Folder'
       
    49 
       
    50      class visibility(RelationDefinition):
       
    51     -    subject = ('Folder', 'File', 'Image', 'Comment')
       
    52     +    subject = ('Folder', 'File', 'Comment')
       
    53 	 object = 'String'
       
    54 	 constraints = [StaticVocabularyConstraint(('public', 'authenticated',
       
    55 						    'restricted', 'parent'))]
       
    56 
       
    57      class may_be_readen_by(RelationDefinition):
       
    58     -    subject = ('Folder', 'File', 'Image', 'Comment',)
       
    59     +    subject = ('Folder', 'File', 'Comment',)
       
    60 	 object = 'CWUser'
       
    61 
       
    62 
       
    63     -from cubes.file.schema import File, Image
       
    64     +from cubes.file.schema import File
       
    65 
       
    66      File.__permissions__ = VISIBILITY_PERMISSIONS
       
    67     -Image.__permissions__ = VISIBILITY_PERMISSIONS
       
    68 
       
    69 Now, let's record that we depends on the versions in the __pkginfo__ file.  As
       
    70 `3.8`_ simplify this file, we can merge `__depends_cubes__` (as introduced if the
       
    71 `first blog of this series`_) with `__depends__` to get the following result:
       
    72 
       
    73 .. sourcecode:: python
       
    74 
       
    75     __depends__ = {'cubicweb': '>= 3.9.0',
       
    76 		   'cubicweb-file': '>= 1.9.0',
       
    77 		   'cubicweb-folder': None,
       
    78 		   'cubicweb-person': None,
       
    79 		   'cubicweb-zone': None,
       
    80 		   'cubicweb-comment': None,
       
    81 		   'cubicweb-tag': None,
       
    82 		   }
       
    83 
       
    84 If your cube is packaged for debian, it's a good idea to update the
       
    85 `debian/control` file at the same time, so you won't forget it.
       
    86 
       
    87 That's it for the API update, CubicWeb, cubicweb-file will handle other stuff for
       
    88 us. Easy, no?
       
    89 
       
    90 We can now start some more funny stuff...
       
    91 
     3 
    92 
     4 
    93 Step 1: let's improve site's usability for our visitors
     5 Step 1: let's improve site's usability for our visitors
    94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    95 
     7