Changes between Version 55 and Version 56 of S3/S3Navigation


Ignore:
Timestamp:
06/13/14 12:12:20 (7 years ago)
Author:
MattS
Comment:

syntax highlighting

Legend:

Unmodified
Added
Removed
Modified
  • S3/S3Navigation

    v55 v56  
    1616To implement a Layout, create a new subclass of S3NavigationItem and implement a (static) method layout:
    1717
    18 {{{
     18{{{#!python
    1919class MyMenuLayout(S3NavigationItem):
    2020
     
    3232Once you have implemented the Layout, you can create instances of it to define the particular navigation elements. The elements can be nested using the call-method:
    3333
    34 {{{
     34{{{#!python
    3535my_menu = MyMenuLayout("Home")(
    3636             MyMenuLayout("First Item"),
     
    9797Subclasses of S3NavigationItem must implement the layout method:
    9898
    99 {{{
     99{{{#!python
    100100class MyMenuLayout(S3NavigationItem):
    101101
     
    134134
    135135Get a sub-item of this item at position i:
    136 {{{
     136{{{#!python
    137137    sub_item = item[i]
    138138}}}
    139139
    140140Loop over sub-items:
    141 {{{
     141{{{#!python
    142142    for sub_item in item:
    143143        ...
     
    145145
    146146Get the root item of the tree:
    147 {{{
     147{{{#!python
    148148    root_item = item.get_root()
    149149}}}
    150150
    151151Get the ancestor path (list of items) from the root item down to this item:
    152 {{{
     152{{{#!python
    153153    path = item.path()
    154154}}}
    155155
    156156Get all sub-items with certain flags (can also take multiple flags):
    157 {{{
     157{{{#!python
    158158    enabled_sub_items = item.get_all(enabled=True)
    159159}}}
    160160
    161161Get the first sub-item with certain flags (can also take multiple flags):
    162 {{{
     162{{{#!python
    163163    first_authorized_and_enabled_sub_item = item.get_first(enabled=True, authorized=True)
    164164}}}
    165165
    166166Get the last sub-item with certain flags (analogous to above):
    167 {{{
     167{{{#!python
    168168    last_authorized_and_enabled_sub_item = item.get_last(enabled=True, authorized=True)
    169169}}}
    170170
    171171Number of sub-items:
    172 {{{
     172{{{#!python
    173173    number_of_subitems = len(item)
    174174}}}
    175175
    176176Position of a sub-item within the sub-items list:
    177 {{{
     177{{{#!python
    178178    sub_item_position = item.index(sub_item)
    179179}}}
    180180
    181181Position of this item within the parent's sub-items list:
    182 {{{
     182{{{#!python
    183183    my_position = item.pos()
    184184}}}
    185185
    186186Check whether this is the first sub-item with certain flags:
    187 {{{
     187{{{#!python
    188188    is_first_enabled = item.is_first(enabled=True)
    189189}}}
    190190
    191191Check whether this is the last sub-item with certain flags:
    192 {{{
     192{{{#!python
    193193    is_last_authorized_and_visible = item.is_last(authorized=True, visible=True)
    194194}}}
    195195
    196196Get all preceding siblings of this item within the parent (as list):
    197 {{{
     197{{{#!python
    198198    preceding_siblings = item.preceding()
    199199}}}
    200200
    201201Get all following siblings of this item within the parent (as list):
    202 {{{
     202{{{#!python
    203203    following_siblings = item.following()
    204204}}}
    205205
    206206Get the last preceding item with certain flags:
    207 {{{
     207{{{#!python
    208208    preceding_enabled = item.get_prev(enabled=True)
    209209}}}
    210210
    211211Get the first following item with certain flags:
    212 {{{
     212{{{#!python
    213213    following_visible_and_enabled = item.get_next(visible=True, enabled=True)
    214214}}}
    215215
    216216Get the item URL:
    217 {{{
     217{{{#!python
    218218    url = item.url()
    219219}}}
    220220
    221221Get an inherited attribute (i.e. controller, function or application; these attributes should never be accessed directly):
    222 {{{
     222{{{#!python
    223223    controller = item.get("controller")
    224224}}}
    225225
    226226Check whether this item or any item underneath it contains a certain tag:
    227 {{{
     227{{{#!python
    228228    tag = "special"
    229229    if tag in item:
     
    236236
    237237Get all items underneath this item with a certain tag (as list):
    238 {{{
     238{{{#!python
    239239    tag = "special"
    240240    special_items = item.findall(tag)
     
    242242
    243243Enable/disable items by tag:
    244 {{{
     244{{{#!python
    245245    tag = "special"
    246246    item.enable(tag) # enables all descendand items with the tag "special"
     
    253253
    254254Set layout:
    255 {{{
     255{{{#!python
    256256    tag = "special"
    257257    def f(item):
     
    265265Instead of stepping through the sub-items and recursively rendering the descendant tree, the layout method (=renderer) can use:
    266266
    267 {{{
     267{{{#!python
    268268    sub_items = item.render_components()
    269269}}}
     
    276276To render a navigation element (i.e. to run the layout method), just put it into the view like:
    277277
    278 {{{
     278{{{#!python
    279279{{=my_menu}}
    280280}}}
     
    310310Old: you can simply comment the respective standard option and replace it by a custom menu definition, e.g.:
    311311
    312 {{{
     312{{{#!python
    313313    # =========================================================================
    314314    # Main menu
     
    348348To customize a controller menu, you can override the standard menu in the {{{s3_menu_dict}}} in the second section of {{{models/01_menu.py}}} with a custom menu definition, e.g.:
    349349
    350 {{{
     350{{{#!python
    351351    # =========================================================================
    352352    # Controller menus
     
    376376Items which shall match multiple functions can take a list of function names for the parameter {{{f}}}, where the first function name is used to render the URL, i.e.:
    377377
    378 {{{
     378{{{#!python
    379379   M("Persons", c="pr", f=["person", "index"])
    380380}}}
     
    386386After a menu has been defined, you can modify its attributes in the controller. To access the current menus, use:
    387387
    388 {{{
     388{{{#!python
    389389current.menu.main
    390390}}}
    391391...for the main menu, and
    392392
    393 {{{
     393{{{#!python
    394394current.menu.options
    395395}}}
     
    401401
    402402You can use the call-method later to append more items:
    403 {{{
     403{{{#!python
    404404# Append another item to the menu
    405405my_menu(MyMenuLayout("Third Item"))
     
    408408If you want to insert an item at a particular position, use the insert method:
    409409
    410 {{{
     410{{{#!python
    411411my_menu.insert(0, MyMenuLayout("New First Item"))
    412412}}}
     
    414414You can also remove items from a certain position:
    415415
    416 {{{
     416{{{#!python
    417417my_menu.pop(0) # Remove "New First Item" again
    418418}}}