Changes between Version 55 and Version 56 of S3/S3Navigation
- Timestamp:
- 06/13/14 12:12:20 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/S3Navigation
v55 v56 16 16 To implement a Layout, create a new subclass of S3NavigationItem and implement a (static) method layout: 17 17 18 {{{ 18 {{{#!python 19 19 class MyMenuLayout(S3NavigationItem): 20 20 … … 32 32 Once 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: 33 33 34 {{{ 34 {{{#!python 35 35 my_menu = MyMenuLayout("Home")( 36 36 MyMenuLayout("First Item"), … … 97 97 Subclasses of S3NavigationItem must implement the layout method: 98 98 99 {{{ 99 {{{#!python 100 100 class MyMenuLayout(S3NavigationItem): 101 101 … … 134 134 135 135 Get a sub-item of this item at position i: 136 {{{ 136 {{{#!python 137 137 sub_item = item[i] 138 138 }}} 139 139 140 140 Loop over sub-items: 141 {{{ 141 {{{#!python 142 142 for sub_item in item: 143 143 ... … … 145 145 146 146 Get the root item of the tree: 147 {{{ 147 {{{#!python 148 148 root_item = item.get_root() 149 149 }}} 150 150 151 151 Get the ancestor path (list of items) from the root item down to this item: 152 {{{ 152 {{{#!python 153 153 path = item.path() 154 154 }}} 155 155 156 156 Get all sub-items with certain flags (can also take multiple flags): 157 {{{ 157 {{{#!python 158 158 enabled_sub_items = item.get_all(enabled=True) 159 159 }}} 160 160 161 161 Get the first sub-item with certain flags (can also take multiple flags): 162 {{{ 162 {{{#!python 163 163 first_authorized_and_enabled_sub_item = item.get_first(enabled=True, authorized=True) 164 164 }}} 165 165 166 166 Get the last sub-item with certain flags (analogous to above): 167 {{{ 167 {{{#!python 168 168 last_authorized_and_enabled_sub_item = item.get_last(enabled=True, authorized=True) 169 169 }}} 170 170 171 171 Number of sub-items: 172 {{{ 172 {{{#!python 173 173 number_of_subitems = len(item) 174 174 }}} 175 175 176 176 Position of a sub-item within the sub-items list: 177 {{{ 177 {{{#!python 178 178 sub_item_position = item.index(sub_item) 179 179 }}} 180 180 181 181 Position of this item within the parent's sub-items list: 182 {{{ 182 {{{#!python 183 183 my_position = item.pos() 184 184 }}} 185 185 186 186 Check whether this is the first sub-item with certain flags: 187 {{{ 187 {{{#!python 188 188 is_first_enabled = item.is_first(enabled=True) 189 189 }}} 190 190 191 191 Check whether this is the last sub-item with certain flags: 192 {{{ 192 {{{#!python 193 193 is_last_authorized_and_visible = item.is_last(authorized=True, visible=True) 194 194 }}} 195 195 196 196 Get all preceding siblings of this item within the parent (as list): 197 {{{ 197 {{{#!python 198 198 preceding_siblings = item.preceding() 199 199 }}} 200 200 201 201 Get all following siblings of this item within the parent (as list): 202 {{{ 202 {{{#!python 203 203 following_siblings = item.following() 204 204 }}} 205 205 206 206 Get the last preceding item with certain flags: 207 {{{ 207 {{{#!python 208 208 preceding_enabled = item.get_prev(enabled=True) 209 209 }}} 210 210 211 211 Get the first following item with certain flags: 212 {{{ 212 {{{#!python 213 213 following_visible_and_enabled = item.get_next(visible=True, enabled=True) 214 214 }}} 215 215 216 216 Get the item URL: 217 {{{ 217 {{{#!python 218 218 url = item.url() 219 219 }}} 220 220 221 221 Get an inherited attribute (i.e. controller, function or application; these attributes should never be accessed directly): 222 {{{ 222 {{{#!python 223 223 controller = item.get("controller") 224 224 }}} 225 225 226 226 Check whether this item or any item underneath it contains a certain tag: 227 {{{ 227 {{{#!python 228 228 tag = "special" 229 229 if tag in item: … … 236 236 237 237 Get all items underneath this item with a certain tag (as list): 238 {{{ 238 {{{#!python 239 239 tag = "special" 240 240 special_items = item.findall(tag) … … 242 242 243 243 Enable/disable items by tag: 244 {{{ 244 {{{#!python 245 245 tag = "special" 246 246 item.enable(tag) # enables all descendand items with the tag "special" … … 253 253 254 254 Set layout: 255 {{{ 255 {{{#!python 256 256 tag = "special" 257 257 def f(item): … … 265 265 Instead of stepping through the sub-items and recursively rendering the descendant tree, the layout method (=renderer) can use: 266 266 267 {{{ 267 {{{#!python 268 268 sub_items = item.render_components() 269 269 }}} … … 276 276 To render a navigation element (i.e. to run the layout method), just put it into the view like: 277 277 278 {{{ 278 {{{#!python 279 279 {{=my_menu}} 280 280 }}} … … 310 310 Old: you can simply comment the respective standard option and replace it by a custom menu definition, e.g.: 311 311 312 {{{ 312 {{{#!python 313 313 # ========================================================================= 314 314 # Main menu … … 348 348 To 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.: 349 349 350 {{{ 350 {{{#!python 351 351 # ========================================================================= 352 352 # Controller menus … … 376 376 Items 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.: 377 377 378 {{{ 378 {{{#!python 379 379 M("Persons", c="pr", f=["person", "index"]) 380 380 }}} … … 386 386 After a menu has been defined, you can modify its attributes in the controller. To access the current menus, use: 387 387 388 {{{ 388 {{{#!python 389 389 current.menu.main 390 390 }}} 391 391 ...for the main menu, and 392 392 393 {{{ 393 {{{#!python 394 394 current.menu.options 395 395 }}} … … 401 401 402 402 You can use the call-method later to append more items: 403 {{{ 403 {{{#!python 404 404 # Append another item to the menu 405 405 my_menu(MyMenuLayout("Third Item")) … … 408 408 If you want to insert an item at a particular position, use the insert method: 409 409 410 {{{ 410 {{{#!python 411 411 my_menu.insert(0, MyMenuLayout("New First Item")) 412 412 }}} … … 414 414 You can also remove items from a certain position: 415 415 416 {{{ 416 {{{#!python 417 417 my_menu.pop(0) # Remove "New First Item" again 418 418 }}}