| | 133 | |
| | 134 | Get a sub-item of this item: |
| | 135 | {{{ |
| | 136 | sub_item = item[i] |
| | 137 | }}} |
| | 138 | |
| | 139 | Loop over sub-items: |
| | 140 | {{{ |
| | 141 | for sub_item in item: |
| | 142 | ... |
| | 143 | }}} |
| | 144 | |
| | 145 | Get the root item of the tree: |
| | 146 | {{{ |
| | 147 | root_item = item.get_root() |
| | 148 | }}} |
| | 149 | |
| | 150 | Get the path (list of items) from the root item down to this item: |
| | 151 | {{{ |
| | 152 | path = item.path() |
| | 153 | }}} |
| | 154 | |
| | 155 | Get all sub-items with certain flags (can also take multiple flags): |
| | 156 | {{{ |
| | 157 | enabled_sub_items = item.get_all(enabled=True) |
| | 158 | }}} |
| | 159 | |
| | 160 | Get the first sub-item with certain flags (can also take multiple flags): |
| | 161 | {{{ |
| | 162 | first_authorized_and_enabled_sub_item = item.get_first(enabled=True, authorized=True) |
| | 163 | }}} |
| | 164 | |
| | 165 | Get the last sub-item with certain flags (analogous to above): |
| | 166 | {{{ |
| | 167 | last_authorized_and_enabled_sub_item = item.get_last(enabled=True, authorized=True) |
| | 168 | }}} |
| | 169 | |
| | 170 | Number of sub-items: |
| | 171 | {{{ |
| | 172 | number_of_subitems = len(item) |
| | 173 | }}} |
| | 174 | |
| | 175 | Position of a sub-item within the sub-items list: |
| | 176 | {{{ |
| | 177 | sub_item_position = item.index(sub_item) |
| | 178 | }}} |
| | 179 | |
| | 180 | Check whether this is the first sub-item with certain flags: |
| | 181 | {{{ |
| | 182 | is_first_enabled = item.is_first(enabled=True) |
| | 183 | }}} |
| | 184 | |
| | 185 | Check whether this is the last sub-item with certain flags: |
| | 186 | {{{ |
| | 187 | is_last_authorized_and_visible = item.is_last(authorized=True, visible=True) |
| | 188 | }}} |
| | 189 | |
| | 190 | Get all preceding siblings of this item within the parent (as list): |
| | 191 | {{{ |
| | 192 | preceding_siblings = item.preceding() |
| | 193 | }}} |
| | 194 | |
| | 195 | Get all following siblings of this item within the parent (as list): |
| | 196 | {{{ |
| | 197 | following_siblings = item.following() |
| | 198 | }}} |
| | 199 | |
| | 200 | Get the last preceding item with certain flags: |
| | 201 | {{{ |
| | 202 | preceding_enabled = item.get_prev(enabled=True) |
| | 203 | }}} |
| | 204 | |
| | 205 | Get the first following item with certain flags: |
| | 206 | {{{ |
| | 207 | following_visible_and_enabled = item.get_next(visible=True, enabled=True) |
| | 208 | }}} |
| | 209 | |
| | 210 | Get the item URL: |
| | 211 | {{{ |
| | 212 | url = item.url() |
| | 213 | }}} |
| | 214 | |
| | 215 | Get an inherited attribute (i.e. controller, function or application; these attributes should never be accessed directly): |
| | 216 | {{{ |
| | 217 | controller = item.get("controller") |
| | 218 | }}} |
| | 219 | |
| | 220 | Check whether this item or any item underneath it contains a certain tag: |
| | 221 | {{{ |
| | 222 | tag = "special" |
| | 223 | if tag in item: |
| | 224 | # This item or at least one underneath it contains this tag |
| | 225 | }}} |
| | 226 | |
| | 227 | ==== Manipulation methods ==== |
| | 228 | |
| | 229 | These methods can be used by controllers to influence the rendering of items: |
| | 230 | |
| | 231 | Get all items underneath this item with a certain tag (as list): |
| | 232 | {{{ |
| | 233 | tag = "special" |
| | 234 | special_items = item.findall(tag) |
| | 235 | }}} |
| | 236 | |
| | 237 | Enable/disable items by tag: |
| | 238 | {{{ |
| | 239 | tag = "special" |
| | 240 | item.enable(tag) # enables all descendand items with the tag "special" |
| | 241 | |
| | 242 | tag = "nonspecial" |
| | 243 | item.disable(tag) # disables all descendand items with the tag "nonspecial" |
| | 244 | }}} |
| | 245 | |
| | 246 | If enable or disable are used without tag, then only the current item gets enabled/disabled |
| | 247 | |
| | 248 | Set layout: |
| | 249 | {{{ |
| | 250 | tag = "special" |
| | 251 | def f(item): |
| | 252 | # Layout goes here |
| | 253 | |
| | 254 | # Set this layout to all descendand items with the tag "special" |
| | 255 | item.set_layout(f, tag=tag, recursive=True) |
| | 256 | }}} |