| 1 | import warningsscip-python python python-stdlib 3.11 warnings/__init__: |
| 2 | from collectionsscip-python python python-stdlib 3.11 collections/__init__: import defaultdictscip-python python python-stdlib 3.11 collections/defaultdict# |
| 3 | from copyscip-python python python-stdlib 3.11 copy/__init__: import deepcopyscip-python python python-stdlib 3.11 copy/deepcopy(). |
| 4 | from inspectscip-python python python-stdlib 3.11 inspect/__init__: import getfullargspecscip-python python python-stdlib 3.11 inspect/getfullargspec(). |
| 5 | from sysscip-python python python-stdlib 3.11 sys/__init__: import exc_infoscip-python python python-stdlib 3.11 sys/exc_info(). |
| 6 | from threadingscip-python python python-stdlib 3.11 threading/__init__: import localscip-python python python-stdlib 3.11 threading/local# |
| 7 | from typingscip-python python python-stdlib 3.11 typing/__init__: import Callablescip-python python python-stdlib 3.11 typing/Callable., Listscip-python python python-stdlib 3.11 typing/List., Optionalscip-python python python-stdlib 3.11 typing/Optional., Dictscip-python python python-stdlib 3.11 typing/Dict., Unionscip-python python python-stdlib 3.11 typing/Union., Sequencescip-python python python-stdlib 3.11 typing/Sequence#, Anyscip-python python python-stdlib 3.11 typing/Any., Tuplescip-python python python-stdlib 3.11 typing/Tuple. |
| 8 | |
| 9 | from django.confscip-python python Django 5.2.15 `django.conf`/__init__: import settings |
| 10 | from django.core.cachescip-python python Django 5.2.15 `django.core.cache`/__init__: import caches |
| 11 | from django.db.modelsscip-python python Django 5.2.15 `django.db.models`/__init__: import signals, QuerySet |
| 12 | from django.template.basescip-python python Django 5.2.15 `django.template.base`/__init__: import ( |
| 13 | FilterExpression, Lexer, Parser, Variable, VariableDoesNotExist, VARIABLE_TAG_START) |
| 14 | from django.template.contextscip-python python Django 5.2.15 `django.template.context`/__init__: import Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context# |
| 15 | from django.template.loaderscip-python python Django 5.2.15 `django.template.loader`/__init__: import get_template |
| 16 | from django.urlsscip-python python Django 5.2.15 `django.urls`/__init__: import reverse, NoReverseMatch |
| 17 | from django.utilsscip-python python Django 5.2.15 `django.utils`/__init__: import module_loadingscip-python python Django 5.2.15 `django.utils.module_loading`/__init__: |
| 18 | from django.utils.encodingscip-python python Django 5.2.15 `django.utils.encoding`/__init__: import iri_to_uri |
| 19 | from django.utils.translationscip-python python Django 5.2.15 `django.utils.translation`/__init__: import get_language |
| 20 | |
| 21 | from .compatscip-python python django-sitetree 1.18.0 compat/__init__: import TOKEN_TEXTscip-python python django-sitetree 1.18.0 `sitetree.compat`/TOKEN_TEXT., TOKEN_VARscip-python python django-sitetree 1.18.0 `sitetree.compat`/TOKEN_VAR. |
| 22 | from .exceptionsscip-python python django-sitetree 1.18.0 exceptions/__init__: import SiteTreeErrorscip-python python django-sitetree 1.18.0 `sitetree.exceptions`/SiteTreeError# |
| 23 | from .settingsscip-python python django-sitetree 1.18.0 settings/__init__: import ( |
| 24 | ALIAS_TRUNKscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_TRUNK., ALIAS_THIS_CHILDRENscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_CHILDREN., ALIAS_THIS_SIBLINGSscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_SIBLINGS., ALIAS_THIS_PARENT_SIBLINGSscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_PARENT_SIBLINGS., ALIAS_THIS_ANCESTOR_CHILDRENscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_ANCESTOR_CHILDREN., |
| 25 | UNRESOLVED_ITEM_MARKERscip-python python django-sitetree 1.18.0 `sitetree.settings`/UNRESOLVED_ITEM_MARKER.UNRESOLVED_ITEM_MARKER., RAISE_ITEMS_ERRORS_ON_DEBUGscip-python python django-sitetree 1.18.0 `sitetree.settings`/RAISE_ITEMS_ERRORS_ON_DEBUG.RAISE_ITEMS_ERRORS_ON_DEBUG., CACHE_TIMEOUTscip-python python django-sitetree 1.18.0 `sitetree.settings`/CACHE_TIMEOUT.CACHE_TIMEOUT., CACHE_NAMEscip-python python django-sitetree 1.18.0 `sitetree.settings`/CACHE_NAME.CACHE_NAME., DYNAMIC_ONLYscip-python python django-sitetree 1.18.0 `sitetree.settings`/DYNAMIC_ONLY.DYNAMIC_ONLY., ADMIN_APP_NAMEscip-python python django-sitetree 1.18.0 `sitetree.settings`/ADMIN_APP_NAME.ADMIN_APP_NAME., |
| 26 | SITETREE_CLSscip-python python django-sitetree 1.18.0 `sitetree.settings`/SITETREE_CLS.SITETREE_CLS., |
| 27 | ) |
| 28 | from .utilsscip-python python django-sitetree 1.18.0 utils/__init__: import get_tree_modelscip-python python django-sitetree 1.18.0 `sitetree.utils`/get_tree_model()., get_tree_item_modelscip-python python django-sitetree 1.18.0 `sitetree.utils`/get_tree_item_model()., import_app_sitetree_modulescip-python python django-sitetree 1.18.0 `sitetree.utils`/import_app_sitetree_module()., generate_id_forscip-python python django-sitetree 1.18.0 `sitetree.utils`/generate_id_for(). |
| 29 | |
| 30 | if False: # pragma: nocover |
| 31 | from django.contrib.auth.modelsscip-python python Django 5.2.15 `django.contrib.auth.models`/__init__: import User # noqa |
| 32 | from .modelsscip-python python django-sitetree 1.18.0 models/__init__: import TreeItemBase, TreeBase |
| 33 | |
| 34 | TypeDynamicTreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeDynamicTrees. = Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Unionscip-python python python-stdlib 3.11 typing/Union.[Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Listscip-python python python-stdlib 3.11 typing/List.['TreeBase']], Listscip-python python python-stdlib 3.11 typing/List.['TreeBase']]] |
| 35 | TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr. = Unionscip-python python python-stdlib 3.11 typing/Union.[strscip-python python python-stdlib 3.11 builtins/str#, FilterExpression] |
| 36 | |
| 37 | MODEL_TREE_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_CLASS. = get_tree_modelscip-python python django-sitetree 1.18.0 `sitetree.utils`/get_tree_model().() |
| 38 | MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS. = get_tree_item_modelscip-python python django-sitetree 1.18.0 `sitetree.utils`/get_tree_item_model().() |
| 39 | |
| 40 | |
| 41 | _ITEMS_PROCESSORscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR._ITEMS_PROCESSOR.: Optionalscip-python python python-stdlib 3.11 typing/Optional.[Callablescip-python python python-stdlib 3.11 typing/Callable.] = None |
| 42 | """Stores tree items processor callable or None.""" |
| 43 | |
| 44 | _ITEMS_PROCESSOR_ARGS_LENscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR_ARGS_LEN._ITEMS_PROCESSOR_ARGS_LEN.: intscip-python python python-stdlib 3.11 builtins/int# = 0 |
| 45 | """Number of arguments accepted by items processor.""" |
| 46 | |
| 47 | _I18N_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_I18N_TREES._I18N_TREES.: Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#] = [] |
| 48 | """Stores aliases of trees supporting internationalization.""" |
| 49 | |
| 50 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.: TypeDynamicTreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeDynamicTrees. = {} |
| 51 | """Holds trees dynamically loaded from project apps.""" |
| 52 | |
| 53 | _IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.: strscip-python python python-stdlib 3.11 builtins/str# = 'orphans' |
| 54 | """Dictionary index in `_DYNAMIC_TREES` for orphaned trees list.""" |
| 55 | |
| 56 | _IDX_TPLscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_TPL._IDX_TPL.: strscip-python python python-stdlib 3.11 builtins/str# = '%s|:|%s' |
| 57 | """Name template used as dictionary index in `_DYNAMIC_TREES`.""" |
| 58 | |
| 59 | _THREAD_LOCALscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_LOCAL. = localscip-python python python-stdlib 3.11 threading/local#() |
| 60 | _THREAD_SITETREEscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_SITETREE._THREAD_SITETREE.: strscip-python python python-stdlib 3.11 builtins/str# = 'sitetree' |
| 61 | _UNSETscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_UNSET. = setscip-python python python-stdlib 3.11 builtins/set#() # Sentinel |
| 62 | |
| 63 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache. = caches[CACHE_NAMEscip-python python django-sitetree 1.18.0 `sitetree.settings`/CACHE_NAME.CACHE_NAME.] |
| 64 | |
| 65 | |
| 66 | def get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/get_sitetree().() -> 'SiteTreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#': |
| 67 | """Returns SiteTree (thread-singleton) object, implementing utility methods. |
| 68 | This can return the built-in or a customized (see SITETREE_CLS setting) sitetree handler. |
| 69 | |
| 70 | """ |
| 71 | sitetree = getattrscip-python python python-stdlib 3.11 builtins/getattr().(_THREAD_LOCALscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_LOCAL., _THREAD_SITETREEscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_SITETREE._THREAD_SITETREE., None) |
| 72 | |
| 73 | if sitetree is None: |
| 74 | sitetree = _SITETREE_CLSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_SITETREE_CLS.() |
| 75 | setattr(_THREAD_LOCALscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_LOCAL., _THREAD_SITETREEscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_THREAD_SITETREE._THREAD_SITETREE., sitetree) |
| 76 | |
| 77 | return sitetree |
| 78 | |
| 79 | |
| 80 | def register_items_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_items_hook().(funcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_items_hook().(func): Callablescip-python python python-stdlib 3.11 typing/Callable.): |
| 81 | """Registers a hook callable to process tree items right before they are passed to templates. |
| 82 | |
| 83 | .. deprecated:: 1.13.0 |
| 84 | Items hooking with `register_items_hook` is deprecated, please use `SITETREE_CLS` |
| 85 | setting customization instead and override .apply_hook() method. |
| 86 | |
| 87 | Callable should be able to: |
| 88 | |
| 89 | a) handle ``tree_items`` and ``tree_sender`` key params. |
| 90 | ``tree_items`` will contain a list of extended TreeItem objects ready to pass to template. |
| 91 | ``tree_sender`` will contain navigation type identifier |
| 92 | (e.g.: `menu`, `sitetree`, `breadcrumbs`, `menu.children`, `sitetree.children`) |
| 93 | |
| 94 | b) return a list of extended TreeItems objects to pass to template. |
| 95 | |
| 96 | |
| 97 | Example:: |
| 98 | |
| 99 | # Put the following code somewhere where it'd be triggered as expected. E.g. in app view.py. |
| 100 | |
| 101 | # First import the register function. |
| 102 | from sitetree.sitetreeapp import register_items_hook |
| 103 | |
| 104 | # The following function will be used as items processor. |
| 105 | def my_items_processor(tree_items, tree_sender): |
| 106 | # Suppose we want to process only menu child items. |
| 107 | if tree_sender == 'menu.children': |
| 108 | # Lets add 'Hooked: ' to resolved titles of every item. |
| 109 | for item in tree_items: |
| 110 | item.title_resolved = f'Hooked: {item.title_resolved}' |
| 111 | # Return items list mutated or not. |
| 112 | return tree_items |
| 113 | |
| 114 | # And we register items processor. |
| 115 | register_items_hook(my_items_processor) |
| 116 | |
| 117 | :param func: |
| 118 | """ |
| 119 | warningsscip-python python python-stdlib 3.11 warnings/__init__:.warnscip-python python python-stdlib 3.11 _warnings/warn().( |
| 120 | 'Items hooking with `register_items_hook` is deprecated, ' |
| 121 | 'please use `SITETREE_CLS` settings customization instead.', |
| 122 | DeprecationWarningscip-python python python-stdlib 3.11 builtins/DeprecationWarning#, 2) |
| 123 | |
| 124 | global _ITEMS_PROCESSORscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR._ITEMS_PROCESSOR. |
| 125 | global _ITEMS_PROCESSOR_ARGS_LENscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR_ARGS_LEN._ITEMS_PROCESSOR_ARGS_LEN. |
| 126 | |
| 127 | _ITEMS_PROCESSORscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR._ITEMS_PROCESSOR. = funcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_items_hook().(func) |
| 128 | |
| 129 | if funcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_items_hook().(func): |
| 130 | args_len = len(getfullargspecscip-python python python-stdlib 3.11 inspect/getfullargspec().(funcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_items_hook().(func)).argsscip-python python python-stdlib 3.11 inspect/FullArgSpec#args.) |
| 131 | if args_len not in {2, 3}: |
| 132 | raise SiteTreeErrorscip-python python django-sitetree 1.18.0 `sitetree.exceptions`/SiteTreeError#('`register_items_hook()` expects a function with two or three arguments.') |
| 133 | _ITEMS_PROCESSOR_ARGS_LENscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR_ARGS_LEN._ITEMS_PROCESSOR_ARGS_LEN. = args_len |
| 134 | |
| 135 | |
| 136 | def register_i18n_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_i18n_trees().(aliasesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_i18n_trees().(aliases): Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#]): |
| 137 | """Registers aliases of internationalized sitetrees. |
| 138 | Internationalized sitetrees are those, which are dubbed by other trees having |
| 139 | locale identifying suffixes in their aliases. |
| 140 | |
| 141 | Lets suppose ``my_tree`` is the alias of a generic tree. This tree is the one |
| 142 | that we call by its alias in templates, and it is the one which is used |
| 143 | if no i18n version of that tree is found. |
| 144 | |
| 145 | Given that ``my_tree_en``, ``my_tree_ru`` and other ``my_tree_{locale-id}``-like |
| 146 | trees are considered internationalization sitetrees. These are used (if available) |
| 147 | in accordance with current locale used by project. |
| 148 | |
| 149 | Example:: |
| 150 | |
| 151 | # Put the following code somewhere where it'd be triggered as expected. E.g. in main urls.py. |
| 152 | |
| 153 | # First import the register function. |
| 154 | from sitetree.sitetreeapp import register_i18n_trees |
| 155 | |
| 156 | # At last we register i18n trees. |
| 157 | register_i18n_trees(['my_tree', 'my_another_tree']) |
| 158 | |
| 159 | :param aliases: |
| 160 | |
| 161 | """ |
| 162 | global _I18N_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_I18N_TREES._I18N_TREES. |
| 163 | _I18N_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_I18N_TREES._I18N_TREES. = aliasesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_i18n_trees().(aliases) |
| 164 | |
| 165 | |
| 166 | def register_dynamic_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().( |
| 167 | treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees): Unionscip-python python python-stdlib 3.11 typing/Union.[Listscip-python python python-stdlib 3.11 typing/List.['TreeBase'], Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Listscip-python python python-stdlib 3.11 typing/List.['TreeBase']]], |
| 168 | *argsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(args), |
| 169 | **kwargsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(kwargs) |
| 170 | ): |
| 171 | """Registers dynamic trees to be available for `sitetree` runtime. |
| 172 | Expects `trees` to be an iterable with structures created with `compose_dynamic_tree()`. |
| 173 | |
| 174 | Example:: |
| 175 | |
| 176 | register_dynamic_trees( |
| 177 | |
| 178 | # Get all the trees from `my_app`. |
| 179 | compose_dynamic_tree('my_app'), |
| 180 | |
| 181 | # Get all the trees from `my_app` and attach them to `main` tree root. |
| 182 | compose_dynamic_tree('my_app', target_tree_alias='main'), |
| 183 | |
| 184 | # Get all the trees from `my_app` and attach them to `has_dynamic` aliased item in `main` tree. |
| 185 | compose_dynamic_tree('articles', target_tree_alias='main', parent_tree_item_alias='has_dynamic'), |
| 186 | |
| 187 | # Define a tree right on the registration. |
| 188 | compose_dynamic_tree(( |
| 189 | tree('dynamic', items=( |
| 190 | item('dynamic_1', 'dynamic_1_url', children=( |
| 191 | item('dynamic_1_sub_1', 'dynamic_1_sub_1_url'), |
| 192 | )), |
| 193 | item('dynamic_2', 'dynamic_2_url'), |
| 194 | )), |
| 195 | )), |
| 196 | ) |
| 197 | |
| 198 | Accepted kwargs: |
| 199 | bool reset_cache: Resets tree cache, to introduce all changes made to a tree immediately. |
| 200 | |
| 201 | """ |
| 202 | global _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES. |
| 203 | |
| 204 | if _IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES. not in _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.: |
| 205 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.] = {} |
| 206 | |
| 207 | if isinstance(treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees), dictscip-python python python-stdlib 3.11 builtins/dict#): # New `less-brackets` style registration. |
| 208 | treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees) = [treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees)] |
| 209 | treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees).extendscip-python python python-stdlib 3.11 builtins/list#extend().(argsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(args)) |
| 210 | |
| 211 | for tree in treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(trees) or []: |
| 212 | if tree is not None and tree['sitetrees'] is not None: |
| 213 | if tree['tree'] is None: |
| 214 | # Register trees as they are defined in app. |
| 215 | for st in tree['sitetrees']: |
| 216 | if st.alias not in _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.]: |
| 217 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.][st.alias] = [] |
| 218 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.][st.alias].appendscip-python python python-stdlib 3.11 builtins/list#append().(st) |
| 219 | else: |
| 220 | # Register tree items as parts of existing trees. |
| 221 | index = _IDX_TPLscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_TPL._IDX_TPL. % (tree['tree'], tree['parent_item']) |
| 222 | if index not in _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.: |
| 223 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[index] = [] |
| 224 | _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.[index].extendscip-python python python-stdlib 3.11 builtins/list#extend().(tree['sitetrees']) |
| 225 | |
| 226 | reset_cache = kwargsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/register_dynamic_trees().(kwargs).getscip-python python python-stdlib 3.11 builtins/dict#get().('reset_cache', False) |
| 227 | if reset_cache: |
| 228 | cache_ = get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/get_sitetree().().cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache. |
| 229 | cache_.emptyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().() |
| 230 | cache_.resetscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#reset().() |
| 231 | |
| 232 | |
| 233 | def get_dynamic_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/get_dynamic_trees().() -> TypeDynamicTreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeDynamicTrees.: |
| 234 | """Returns a dictionary with currently registered dynamic trees.""" |
| 235 | return _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES. |
| 236 | |
| 237 | |
| 238 | def compose_dynamic_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().( |
| 239 | srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src): Unionscip-python python python-stdlib 3.11 typing/Union.[strscip-python python python-stdlib 3.11 builtins/str#, Sequencescip-python python python-stdlib 3.11 typing/Sequence#['TreeBase'], Sequencescip-python python python-stdlib 3.11 typing/Sequence#['TreeItemBase']], |
| 240 | target_tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(target_tree_alias): strscip-python python python-stdlib 3.11 builtins/str# = None, |
| 241 | parent_tree_item_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(parent_tree_item_alias): strscip-python python python-stdlib 3.11 builtins/str# = None, |
| 242 | include_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(include_trees): Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#] = None |
| 243 | ) -> dictscip-python python python-stdlib 3.11 builtins/dict#: |
| 244 | """Returns a structure describing a dynamic sitetree.utils |
| 245 | The structure can be built from various sources, |
| 246 | |
| 247 | :param src: If a string is passed to `src`, it'll be treated as the name of an app, |
| 248 | from where one want to import sitetrees definitions. `src` can be an iterable |
| 249 | of tree definitions (see `sitetree.toolbox.tree()` and `item()` functions). |
| 250 | |
| 251 | :param target_tree_alias: Static tree alias to attach items from dynamic trees to. |
| 252 | |
| 253 | :param parent_tree_item_alias: Tree item alias from a static tree to attach items from dynamic trees to. |
| 254 | |
| 255 | :param include_trees: Sitetree aliases to filter `src`. |
| 256 | |
| 257 | """ |
| 258 | def resultscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(sitetreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(sitetrees)): |
| 259 | if include_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(include_trees) is not None: |
| 260 | sitetreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(sitetrees) = [tree for tree in sitetreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(sitetrees) if tree.alias in include_treesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(include_trees)] |
| 261 | |
| 262 | return { |
| 263 | 'app': srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src), |
| 264 | 'sitetrees': sitetreesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(sitetrees), |
| 265 | 'tree': target_tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(target_tree_alias), |
| 266 | 'parent_item': parent_tree_item_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(parent_tree_item_alias)} |
| 267 | |
| 268 | if isinstance(srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src), strscip-python python python-stdlib 3.11 builtins/str#): |
| 269 | # Considered to be an application name. |
| 270 | try: |
| 271 | module = import_app_sitetree_modulescip-python python django-sitetree 1.18.0 `sitetree.utils`/import_app_sitetree_module().(srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src)) |
| 272 | return None if module is None else resultscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(getattrscip-python python python-stdlib 3.11 builtins/getattr().(module, 'sitetrees', None)) |
| 273 | |
| 274 | except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError# as e: |
| 275 | if settings.DEBUG: |
| 276 | warningsscip-python python python-stdlib 3.11 warnings/__init__:.warnscip-python python python-stdlib 3.11 _warnings/warn().(f'Unable to register dynamic sitetree(s) for `{srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src)}` application: {e}. ') |
| 277 | return {} |
| 278 | |
| 279 | return resultscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().result().(srcscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/compose_dynamic_tree().(src)) |
| 280 | |
| 281 | |
| 282 | class LazyTitlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#: |
| 283 | """Lazily resolves any variable found in a title of an item. |
| 284 | Produces resolved title as unicode representation. |
| 285 | |
| 286 | """ |
| 287 | def __init__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__init__().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__init__().(self), titlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__init__().(title): strscip-python python python-stdlib 3.11 builtins/str#): |
| 288 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__init__().(self).titlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#title. = titlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__init__().(title) |
| 289 | |
| 290 | def __str__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__str__().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__str__().(self)): |
| 291 | my_lexer = Lexer(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__str__().(self).titlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#title.) |
| 292 | my_tokens = my_lexer.tokenize() |
| 293 | |
| 294 | # Deliberately strip off template tokens that are not text or variable. |
| 295 | for my_token in my_tokens: |
| 296 | if my_token.token_type not in (TOKEN_TEXTscip-python python django-sitetree 1.18.0 `sitetree.compat`/TOKEN_TEXT., TOKEN_VARscip-python python django-sitetree 1.18.0 `sitetree.compat`/TOKEN_VAR.): |
| 297 | my_tokens.removescip-python python python-stdlib 3.11 builtins/list#remove().(my_token) |
| 298 | |
| 299 | my_parser = Parser(my_tokens) |
| 300 | return my_parser.parse().render(get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/get_sitetree().().current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context.) |
| 301 | |
| 302 | def __eq__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__eq__().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__eq__().(self), otherscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__eq__().(other)): |
| 303 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__eq__().(self).__str__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__str__().() == otherscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#__eq__().(other) |
| 304 | |
| 305 | |
| 306 | class Cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#: |
| 307 | """Contains cache-related stuff.""" |
| 308 | |
| 309 | def __init__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#__init__().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#__init__().(self)): |
| 310 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#__init__().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.: dictscip-python python python-stdlib 3.11 builtins/dict# = {} |
| 311 | |
| 312 | cache_empty = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#__init__().(self).emptyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty(). |
| 313 | # Listen for signals from the models. |
| 314 | signals.post_save.connect(cache_empty, sender=MODEL_TREE_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_CLASS.) |
| 315 | signals.post_save.connect(cache_empty, sender=MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS.) |
| 316 | signals.post_delete.connect(cache_empty, sender=MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS.) |
| 317 | # Listen to the changes in item permissions table. |
| 318 | signals.m2m_changed.connect(cache_empty, sender=MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS..access_permissions) |
| 319 | |
| 320 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#__init__().(self).initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().() |
| 321 | |
| 322 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 323 | def resetscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#reset().(clsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#reset().(cls)): |
| 324 | """Instructs sitetree to drop and recreate cache. |
| 325 | |
| 326 | Could be used to show up tree changes made in a different process. |
| 327 | |
| 328 | """ |
| 329 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..set('sitetrees_reset', True) |
| 330 | |
| 331 | def initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().(self)): |
| 332 | """Initializes local cache from Django cache.""" |
| 333 | |
| 334 | # Drop cache flag set by .reset() method. |
| 335 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..get('sitetrees_reset') and selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().(self).emptyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(init=False) |
| 336 | |
| 337 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache. = cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..get( |
| 338 | 'sitetrees', {'sitetrees': {}, 'parents': {}, 'items_by_ids': {}, 'tree_aliases': {}}) |
| 339 | |
| 340 | def savescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#save().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#save().(self)): |
| 341 | """Saves sitetree data to Django cache.""" |
| 342 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..set('sitetrees', selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#save().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache., CACHE_TIMEOUTscip-python python django-sitetree 1.18.0 `sitetree.settings`/CACHE_TIMEOUT.CACHE_TIMEOUT.) |
| 343 | |
| 344 | def emptyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(self), **kwargsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(kwargs)): |
| 345 | """Empties cached sitetree data.""" |
| 346 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..delete('sitetrees') |
| 347 | cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/cache..delete('sitetrees_reset') |
| 348 | |
| 349 | kwargsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(kwargs).getscip-python python python-stdlib 3.11 builtins/dict#get().('init', True) and selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#empty().(self).initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#init().() |
| 350 | |
| 351 | def get_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(self), entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(entry_name): strscip-python python python-stdlib 3.11 builtins/str#, keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(key)) -> Anyscip-python python python-stdlib 3.11 typing/Any.: |
| 352 | """Returns cache entry parameter value by its name. |
| 353 | |
| 354 | :param entry_name: |
| 355 | :param key: |
| 356 | |
| 357 | """ |
| 358 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.[entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(entry_name)].get(keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().(key), False) |
| 359 | |
| 360 | def update_entry_valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(self), entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(entry_name): strscip-python python python-stdlib 3.11 builtins/str#, keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(key): strscip-python python python-stdlib 3.11 builtins/str#, valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(value): Anyscip-python python python-stdlib 3.11 typing/Any.): |
| 361 | """Updates cache entry parameter with new data. |
| 362 | |
| 363 | :param entry_name: |
| 364 | :param key: |
| 365 | :param value: |
| 366 | |
| 367 | """ |
| 368 | if keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(key) not in selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.[entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(entry_name)]: |
| 369 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.[entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(entry_name)][keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(key)] = {} |
| 370 | |
| 371 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.[entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(entry_name)][keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(key)].update(valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value().(value)) |
| 372 | |
| 373 | def set_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(self), entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(entry_name): strscip-python python python-stdlib 3.11 builtins/str#, keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(key): strscip-python python python-stdlib 3.11 builtins/str#, valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(value): Anyscip-python python python-stdlib 3.11 typing/Any.): |
| 374 | """Replaces entire cache entry parameter data by its name with new data. |
| 375 | |
| 376 | :param entry_name: |
| 377 | :param key: |
| 378 | :param value: |
| 379 | |
| 380 | """ |
| 381 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#cache.[entry_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(entry_name)][keyscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(key)] = valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().(value) |
| 382 | |
| 383 | |
| 384 | class SiteTreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#: |
| 385 | """Main logic handler.""" |
| 386 | |
| 387 | cache_clsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache_cls. = Cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache# # Allow customizations. |
| 388 | |
| 389 | def __init__scip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#__init__().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#__init__().(self)): |
| 390 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#__init__().(self).initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context)=None) |
| 391 | |
| 392 | def initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context): Optionalscip-python python python-stdlib 3.11 typing/Optional.[Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#]): |
| 393 | """Initializes sitetree to handle new request. |
| 394 | |
| 395 | :param context: |
| 396 | |
| 397 | """ |
| 398 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache. = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self).cache_clsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache_cls.() |
| 399 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context. = contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context) |
| 400 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self).current_langscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_lang. = get_language() |
| 401 | |
| 402 | request = contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context).get('request', None) if contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context) else None |
| 403 | |
| 404 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self).current_requestscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_request. = request |
| 405 | |
| 406 | current_app = ( |
| 407 | getattrscip-python python python-stdlib 3.11 builtins/getattr().(request, 'current_app', None) or |
| 408 | getattrscip-python python python-stdlib 3.11 builtins/getattr().(getattrscip-python python python-stdlib 3.11 builtins/getattr().(request, 'resolver_match', None), 'namespace', None) or |
| 409 | (contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(context) or {}).get('current_app', '') # May be set by TreeItemChoiceField. |
| 410 | ) |
| 411 | |
| 412 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin. = current_app == ADMIN_APP_NAMEscip-python python django-sitetree 1.18.0 `sitetree.settings`/ADMIN_APP_NAME.ADMIN_APP_NAME. |
| 413 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self)._current_appscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app. = current_app |
| 414 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self)._current_user_permissionsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_user_permissions. = _UNSETscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_UNSET. |
| 415 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self)._items_urlsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_items_urls. = {} # Resolved urls are cache for a request. |
| 416 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(self)._current_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_items. = {} |
| 417 | |
| 418 | def resolve_tree_i18n_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(self), aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias): strscip-python python python-stdlib 3.11 builtins/str#) -> strscip-python python python-stdlib 3.11 builtins/str#: |
| 419 | """Resolves internationalized tree alias. |
| 420 | Verifies whether a separate sitetree is available for currently active language. |
| 421 | If so, returns i18n alias. If not, returns the initial alias. |
| 422 | |
| 423 | :param alias: |
| 424 | |
| 425 | """ |
| 426 | if aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias) not in _I18N_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_I18N_TREES._I18N_TREES.: |
| 427 | return aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias) |
| 428 | |
| 429 | current_language_code = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(self).current_langscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_lang. |
| 430 | i18n_tree_alias = f'{aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias)}_{current_language_code}' |
| 431 | trees_count = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache..get_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().('tree_aliases', i18n_tree_alias) |
| 432 | |
| 433 | if trees_count is False: |
| 434 | trees_count = MODEL_TREE_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_CLASS..objects.filter(alias=i18n_tree_alias).count() |
| 435 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache..set_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry().('tree_aliases', i18n_tree_alias, trees_count) |
| 436 | |
| 437 | if trees_count: |
| 438 | aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias) = i18n_tree_alias |
| 439 | |
| 440 | return aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(alias) |
| 441 | |
| 442 | @staticmethodscip-python python python-stdlib 3.11 builtins/staticmethod# |
| 443 | def attach_dynamic_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().( |
| 444 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, |
| 445 | src_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(src_tree_items): Unionscip-python python python-stdlib 3.11 typing/Union.[Sequencescip-python python python-stdlib 3.11 typing/Sequence#['TreeItemBase'], QuerySet] |
| 446 | ) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 447 | """Attaches dynamic sitetrees items registered with `register_dynamic_trees()` |
| 448 | to an initial (source) items list. |
| 449 | |
| 450 | :param tree_alias: |
| 451 | :param src_tree_items: |
| 452 | |
| 453 | """ |
| 454 | if not _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.: |
| 455 | return listscip-python python python-stdlib 3.11 builtins/list#(src_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(src_tree_items)) |
| 456 | |
| 457 | # This guarantees that a dynamic source stays intact, |
| 458 | # no matter how dynamic sitetrees are attached. |
| 459 | trees = deepcopyscip-python python python-stdlib 3.11 copy/deepcopy().(_DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.) |
| 460 | |
| 461 | items = [] |
| 462 | if not src_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(src_tree_items): |
| 463 | if _IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES. in trees and tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias) in trees[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.]: |
| 464 | for tree in trees[_IDX_ORPHAN_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_ORPHAN_TREES._IDX_ORPHAN_TREES.][tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias)]: |
| 465 | items.extendscip-python python python-stdlib 3.11 builtins/list#extend().(tree.dynamic_items) |
| 466 | else: |
| 467 | |
| 468 | # TODO Seems to be underoptimized %) |
| 469 | |
| 470 | # Tree item attachment by alias. |
| 471 | for static_item in listscip-python python python-stdlib 3.11 builtins/list#(src_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(src_tree_items)): |
| 472 | items.appendscip-python python python-stdlib 3.11 builtins/list#append().(static_item) |
| 473 | if not static_item.alias: |
| 474 | continue |
| 475 | |
| 476 | idx = _IDX_TPLscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_TPL._IDX_TPL. % (tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias), static_item.alias) |
| 477 | if idx not in trees: |
| 478 | continue |
| 479 | |
| 480 | for tree in trees[idx]: |
| 481 | tree.alias = tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias) |
| 482 | |
| 483 | for dyn_item in tree.dynamic_items: # noqa dynamic attr |
| 484 | if dyn_item.parent is None: |
| 485 | dyn_item.parent = static_item |
| 486 | # Unique IDs are required for the same trees attached |
| 487 | # to different parents. |
| 488 | dyn_item.id = generate_id_forscip-python python django-sitetree 1.18.0 `sitetree.utils`/generate_id_for().(dyn_item) |
| 489 | items.appendscip-python python python-stdlib 3.11 builtins/list#append().(dyn_item) |
| 490 | |
| 491 | # Tree root attachment. |
| 492 | idx = _IDX_TPLscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_IDX_TPL._IDX_TPL. % (tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias), None) |
| 493 | if idx in _DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.: |
| 494 | trees = deepcopyscip-python python python-stdlib 3.11 copy/deepcopy().(_DYNAMIC_TREESscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_DYNAMIC_TREES._DYNAMIC_TREES.) |
| 495 | for tree in trees[idx]: |
| 496 | tree.alias = tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(tree_alias) |
| 497 | items.extendscip-python python python-stdlib 3.11 builtins/list#extend().(tree.dynamic_items) # noqa dynamic attr |
| 498 | |
| 499 | return items |
| 500 | |
| 501 | def current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_app_is_admin().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_app_is_admin().(self)) -> boolscip-python python python-stdlib 3.11 builtins/bool#: |
| 502 | """Returns boolean whether current application is Admin contrib.""" |
| 503 | warningsscip-python python python-stdlib 3.11 warnings/__init__:.warnscip-python python python-stdlib 3.11 _warnings/warn().( |
| 504 | 'Accessing .current_app_is_admin() is deprecated.', |
| 505 | DeprecationWarningscip-python python python-stdlib 3.11 builtins/DeprecationWarning#, 2) |
| 506 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_app_is_admin().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin. |
| 507 | |
| 508 | def get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self), aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias): strscip-python python python-stdlib 3.11 builtins/str#) -> Tuplescip-python python python-stdlib 3.11 typing/Tuple.[strscip-python python python-stdlib 3.11 builtins/str#, Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']]: |
| 509 | """Gets site tree items from the given site tree. |
| 510 | Caches result to dictionary. |
| 511 | Returns (tree alias, tree items) tuple. |
| 512 | |
| 513 | :param alias: |
| 514 | |
| 515 | """ |
| 516 | cache_ = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache. |
| 517 | get_cache_entry = cache_.get_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry(). |
| 518 | set_cache_entry = cache_.set_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#set_entry(). |
| 519 | |
| 520 | caching_required = False |
| 521 | |
| 522 | if not selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin.: |
| 523 | # We do not need i18n for a tree rendered in Admin dropdown. |
| 524 | aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).resolve_tree_i18n_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias)) |
| 525 | |
| 526 | sitetree = get_cache_entry('sitetrees', aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias)) |
| 527 | |
| 528 | if not sitetree: |
| 529 | if DYNAMIC_ONLYscip-python python django-sitetree 1.18.0 `sitetree.settings`/DYNAMIC_ONLY.DYNAMIC_ONLY.: |
| 530 | sitetree = [] |
| 531 | |
| 532 | else: |
| 533 | sitetree = ( |
| 534 | MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS..objects. |
| 535 | select_related('parent', 'tree'). |
| 536 | prefetch_related('access_permissions__content_type'). |
| 537 | filter(tree__alias__exact=aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias)). |
| 538 | order_by('parent__sort_order', 'sort_order')) |
| 539 | |
| 540 | sitetree = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).attach_dynamic_tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#attach_dynamic_tree_items().(aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), sitetree) |
| 541 | set_cache_entry('sitetrees', aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), sitetree) |
| 542 | caching_required = True |
| 543 | |
| 544 | parents = get_cache_entry('parents', aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias)) |
| 545 | if not parents: |
| 546 | parents = defaultdictscip-python python python-stdlib 3.11 collections/defaultdict#(listscip-python python python-stdlib 3.11 builtins/list#) |
| 547 | for item in sitetree: |
| 548 | parent = getattrscip-python python python-stdlib 3.11 builtins/getattr().(item, 'parent') |
| 549 | parents[parent].appendscip-python python python-stdlib 3.11 builtins/list#append().(item) |
| 550 | set_cache_entry('parents', aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), parents) |
| 551 | |
| 552 | # Prepare items by ids cache if needed. |
| 553 | if caching_required: |
| 554 | # We need this extra pass to avoid future problems on items depth calculation. |
| 555 | cache_update = cache_.update_entry_valuescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#update_entry_value(). |
| 556 | for item in sitetree: |
| 557 | cache_update('items_by_ids', aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), {item.id: item}) |
| 558 | |
| 559 | url = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).urlscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url(). |
| 560 | calculate_item_depth = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).calculate_item_depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth(). |
| 561 | |
| 562 | for item in sitetree: |
| 563 | if caching_required: |
| 564 | item.has_children = False |
| 565 | |
| 566 | if not hasattr(item, 'depth'): |
| 567 | item.depth = calculate_item_depth(aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), item.id) |
| 568 | item.depth_range = rangescip-python python python-stdlib 3.11 builtins/range#(item.depth) |
| 569 | |
| 570 | # Resolve item permissions. |
| 571 | if item.access_restricted: |
| 572 | permissions_src = ( |
| 573 | item.permissions if getattrscip-python python python-stdlib 3.11 builtins/getattr().(item, 'is_dynamic', False) |
| 574 | else item.access_permissions.all()) |
| 575 | |
| 576 | item.perms = setscip-python python python-stdlib 3.11 builtins/set#( |
| 577 | [f'{perm.content_type.app_label}.{perm.codename}' for perm in permissions_src]) |
| 578 | |
| 579 | # Contextual properties. |
| 580 | item.url_resolved = url(item) |
| 581 | item.title_resolved = LazyTitlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/LazyTitle#(item.title) if VARIABLE_TAG_START in item.title else item.title |
| 582 | item.is_current = False |
| 583 | item.in_current_branch = False |
| 584 | |
| 585 | # Get current item for the given sitetree. |
| 586 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(self).get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias)) |
| 587 | |
| 588 | # Save sitetree data into cache if needed. |
| 589 | if caching_required: |
| 590 | cache_.savescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#save().() |
| 591 | |
| 592 | return aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(alias), sitetree |
| 593 | |
| 594 | def calculate_item_depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, item_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(item_id): intscip-python python python-stdlib 3.11 builtins/int#, depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth): intscip-python python python-stdlib 3.11 builtins/int# = 0): |
| 595 | """Calculates depth of the item in the tree. |
| 596 | |
| 597 | :param tree_alias: |
| 598 | :param item_id: |
| 599 | :param depth: |
| 600 | |
| 601 | """ |
| 602 | item = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(self).get_item_by_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(tree_alias), item_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(item_id)) |
| 603 | |
| 604 | if hasattr(item, 'depth'): |
| 605 | depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth) = item.depth + depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth) |
| 606 | |
| 607 | else: |
| 608 | if item.parent is not None: |
| 609 | depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(self).calculate_item_depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(tree_alias), item.parent.id, depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth) + 1) |
| 610 | |
| 611 | return depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#calculate_item_depth().(depth) |
| 612 | |
| 613 | def get_item_by_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, item_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(item_id): intscip-python python python-stdlib 3.11 builtins/int#) -> 'TreeItemBase': |
| 614 | """Get the item from the tree by its ID. |
| 615 | |
| 616 | :param tree_alias: |
| 617 | :param item_id: |
| 618 | |
| 619 | """ |
| 620 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache..get_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().('items_by_ids', tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(tree_alias))[item_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(item_id)] |
| 621 | |
| 622 | def get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#) -> Optionalscip-python python python-stdlib 3.11 typing/Optional.['TreeItemBase']: |
| 623 | """Resolves current tree item of 'tree_alias' tree matching current |
| 624 | request path against URL of given tree item. |
| 625 | |
| 626 | :param tree_alias: |
| 627 | |
| 628 | """ |
| 629 | current_item = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self)._current_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_items..getscip-python python python-stdlib 3.11 builtins/dict#get().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias), _UNSETscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_UNSET.) |
| 630 | |
| 631 | if current_item is not _UNSETscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_UNSET.: |
| 632 | |
| 633 | if current_item is not None: |
| 634 | current_item.is_current = True # Could be reset by .get_sitetree() |
| 635 | |
| 636 | return current_item # noqa |
| 637 | |
| 638 | current_item = None |
| 639 | |
| 640 | if selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin.: |
| 641 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self)._current_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_items.[tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias)] = current_item |
| 642 | return None |
| 643 | |
| 644 | current_url = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self).current_requestscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_request..path |
| 645 | |
| 646 | if current_url: |
| 647 | # url quote is an attempt to support non-ascii in url. |
| 648 | current_url = iri_to_uri(current_url) |
| 649 | |
| 650 | for url_item, url in selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self)._items_urlsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_items_urls..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 651 | # Iterate each as this dict may contains "current" items for various trees. |
| 652 | if url != current_url: |
| 653 | continue |
| 654 | |
| 655 | url_item.is_current = True |
| 656 | if url_item.tree.alias == tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias): |
| 657 | current_item = url_item |
| 658 | |
| 659 | if current_item is not None: |
| 660 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(self)._current_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_items.[tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias)] = current_item |
| 661 | |
| 662 | return current_item |
| 663 | |
| 664 | def urlscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self), sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item): Unionscip-python python python-stdlib 3.11 typing/Union.['TreeItemBase', FilterExpression], contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context# = None) -> strscip-python python python-stdlib 3.11 builtins/str#: |
| 665 | """Resolves item's URL. |
| 666 | |
| 667 | :param sitetree_item: TreeItemBase heir object, 'url' property of which |
| 668 | is processed as URL pattern or simple URL. |
| 669 | |
| 670 | :param context: |
| 671 | |
| 672 | """ |
| 673 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(context) = contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(context) or selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context. |
| 674 | resolve_var = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self).resolve_varscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var(). |
| 675 | |
| 676 | if not isinstance(sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item), MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS.): |
| 677 | sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item) = resolve_var(sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(context)) |
| 678 | |
| 679 | resolved_url = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self)._items_urlsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_items_urls..getscip-python python python-stdlib 3.11 builtins/dict#get().(sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item)) |
| 680 | if resolved_url is not None: |
| 681 | return resolved_url |
| 682 | |
| 683 | # Resolve only if item's URL is marked as pattern. |
| 684 | if sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item).urlaspattern: |
| 685 | url = sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item).url |
| 686 | view_path = url |
| 687 | all_arguments = [] |
| 688 | |
| 689 | if ' ' in url: |
| 690 | view_path = url.split(' ') |
| 691 | # We should try to resolve URL parameters from site tree item. |
| 692 | for view_argument in view_path[1:]: |
| 693 | all_arguments.appendscip-python python python-stdlib 3.11 builtins/list#append().(resolve_var(view_argument)) |
| 694 | |
| 695 | view_path = view_path[0].strip('"\' ') |
| 696 | |
| 697 | try: |
| 698 | resolved_url = reverse( |
| 699 | view_path, |
| 700 | args=all_arguments, |
| 701 | current_app=selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self)._current_appscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app. |
| 702 | ) |
| 703 | |
| 704 | except NoReverseMatch: |
| 705 | resolved_url = UNRESOLVED_ITEM_MARKERscip-python python django-sitetree 1.18.0 `sitetree.settings`/UNRESOLVED_ITEM_MARKER.UNRESOLVED_ITEM_MARKER. |
| 706 | |
| 707 | else: |
| 708 | resolved_url = f'{sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item).url}' |
| 709 | |
| 710 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(self)._items_urlsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_items_urls.[sitetree_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#url().(sitetree_item)] = resolved_url |
| 711 | |
| 712 | return resolved_url |
| 713 | |
| 714 | def init_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().( |
| 715 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(self), |
| 716 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, |
| 717 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context# |
| 718 | ) -> Tuplescip-python python python-stdlib 3.11 typing/Tuple.[Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#], Optionalscip-python python python-stdlib 3.11 typing/Optional.[Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']]]: |
| 719 | """Initializes sitetree in memory. |
| 720 | |
| 721 | Returns tuple with resolved tree alias and items on success. |
| 722 | |
| 723 | On fail returns (None, None). |
| 724 | |
| 725 | :param tree_alias: |
| 726 | :param context: |
| 727 | |
| 728 | """ |
| 729 | request = contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(context).get('request', None) |
| 730 | |
| 731 | if request is None: |
| 732 | |
| 733 | if any(exc_infoscip-python python python-stdlib 3.11 sys/exc_info().()): |
| 734 | # Probably we're in a technical |
| 735 | # exception handling view. So we won't mask |
| 736 | # the initial exception with the one below. |
| 737 | return None, None |
| 738 | |
| 739 | raise SiteTreeErrorscip-python python django-sitetree 1.18.0 `sitetree.exceptions`/SiteTreeError#( |
| 740 | 'Sitetree requires "django.core.context_processors.request" template context processor to be active. ' |
| 741 | 'If it is, check that your view pushes request data into the template.') |
| 742 | |
| 743 | if id(request) != id(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(self).current_requestscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_request.): |
| 744 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(self).initscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init().(contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(context)) |
| 745 | |
| 746 | # Resolve tree_alias from the context. |
| 747 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(self).resolve_varscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias)) |
| 748 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias), sitetree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(self).get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias)) |
| 749 | |
| 750 | if not sitetree_items: |
| 751 | return None, None |
| 752 | |
| 753 | return tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_alias), sitetree_items |
| 754 | |
| 755 | def get_current_page_titlescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(tree_alias): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> strscip-python python python-stdlib 3.11 builtins/str#: |
| 756 | """Returns resolved from sitetree title for current page. |
| 757 | |
| 758 | :param tree_alias: |
| 759 | :param context: |
| 760 | |
| 761 | """ |
| 762 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(self).get_current_page_attrscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().('title_resolved', tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(tree_alias), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_title().(context)) |
| 763 | |
| 764 | def get_current_page_attrscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(self), attr_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(attr_name): strscip-python python python-stdlib 3.11 builtins/str#, tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(tree_alias): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> strscip-python python python-stdlib 3.11 builtins/str#: |
| 765 | """Returns an arbitrary attribute of a sitetree item resolved as current for current page. |
| 766 | |
| 767 | :param attr_name: |
| 768 | :param tree_alias: |
| 769 | :param context: |
| 770 | |
| 771 | """ |
| 772 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(tree_alias), sitetree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(self).init_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(tree_alias), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(context)) |
| 773 | current_item = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(self).get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(tree_alias)) |
| 774 | |
| 775 | if current_item is None: |
| 776 | if settings.DEBUG and RAISE_ITEMS_ERRORS_ON_DEBUGscip-python python django-sitetree 1.18.0 `sitetree.settings`/RAISE_ITEMS_ERRORS_ON_DEBUG.RAISE_ITEMS_ERRORS_ON_DEBUG.: |
| 777 | raise SiteTreeErrorscip-python python django-sitetree 1.18.0 `sitetree.exceptions`/SiteTreeError#( |
| 778 | f'Unable to resolve current sitetree item to get a `{attr_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(attr_name)}` for current page. Check whether ' |
| 779 | 'there is an appropriate sitetree item defined for current URL.') |
| 780 | |
| 781 | return '' |
| 782 | |
| 783 | return getattrscip-python python python-stdlib 3.11 builtins/getattr().(current_item, attr_namescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_current_page_attr().(attr_name), '') |
| 784 | |
| 785 | def get_ancestor_levelscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(self), current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item): 'TreeItemBase', depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(depth): intscip-python python python-stdlib 3.11 builtins/int# = 1) -> 'TreeItemBase': |
| 786 | """Returns ancestor of level `deep` recursively |
| 787 | |
| 788 | :param current_item: |
| 789 | :param depth: |
| 790 | |
| 791 | """ |
| 792 | if current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item).parent is None: |
| 793 | return current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item) |
| 794 | |
| 795 | if depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(depth) <= 1: |
| 796 | return current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item).parent |
| 797 | |
| 798 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(self).get_ancestor_levelscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item).parent, depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(depth)=depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(depth)-1) |
| 799 | |
| 800 | def menuscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., tree_branchesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_branches): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 801 | """Builds and returns menu structure for 'sitetree_menu' tag. |
| 802 | |
| 803 | :param tree_alias: |
| 804 | :param tree_branches: |
| 805 | :param context: |
| 806 | |
| 807 | """ |
| 808 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias), sitetree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).init_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(context)) |
| 809 | |
| 810 | if not sitetree_items: |
| 811 | return [] |
| 812 | |
| 813 | tree_branchesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_branches) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).resolve_varscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(tree_branchesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_branches)) |
| 814 | |
| 815 | parent_isnull = False |
| 816 | parent_ids = [] |
| 817 | parent_aliases = [] |
| 818 | |
| 819 | current_item = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias)) |
| 820 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).tree_climberscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias), current_item) |
| 821 | |
| 822 | # Support item addressing both through identifiers and aliases. |
| 823 | for branch_id in tree_branchesscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_branches).splitscip-python python python-stdlib 3.11 builtins/str#split().(','): |
| 824 | branch_id = branch_id.stripscip-python python python-stdlib 3.11 builtins/str#strip().() |
| 825 | |
| 826 | if branch_id == ALIAS_TRUNKscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_TRUNK.: |
| 827 | parent_isnull = True |
| 828 | |
| 829 | elif branch_id == ALIAS_THIS_CHILDRENscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_CHILDREN. and current_item is not None: |
| 830 | branch_id = current_item.id |
| 831 | parent_ids.appendscip-python python python-stdlib 3.11 builtins/list#append().(branch_id) |
| 832 | |
| 833 | elif branch_id == ALIAS_THIS_ANCESTOR_CHILDRENscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_ANCESTOR_CHILDREN. and current_item is not None: |
| 834 | branch_id = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).get_ancestor_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias), current_item).id |
| 835 | parent_ids.appendscip-python python python-stdlib 3.11 builtins/list#append().(branch_id) |
| 836 | |
| 837 | elif branch_id == ALIAS_THIS_SIBLINGSscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_SIBLINGS. and current_item is not None and current_item.parent is not None: |
| 838 | branch_id = current_item.parent.id |
| 839 | parent_ids.appendscip-python python python-stdlib 3.11 builtins/list#append().(branch_id) |
| 840 | |
| 841 | elif branch_id == ALIAS_THIS_PARENT_SIBLINGSscip-python python django-sitetree 1.18.0 `sitetree.settings`/ALIAS_THIS_PARENT_SIBLINGS. and current_item is not None: |
| 842 | branch_id = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).get_ancestor_levelscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(current_item, depthscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_level().(depth)=2).id |
| 843 | parent_ids.appendscip-python python python-stdlib 3.11 builtins/list#append().(branch_id) |
| 844 | |
| 845 | elif branch_id.isdigitscip-python python python-stdlib 3.11 builtins/str#isdigit().(): |
| 846 | parent_ids.appendscip-python python python-stdlib 3.11 builtins/list#append().(intscip-python python python-stdlib 3.11 builtins/int#(branch_id)) |
| 847 | |
| 848 | else: |
| 849 | parent_aliases.appendscip-python python python-stdlib 3.11 builtins/list#append().(branch_id) |
| 850 | |
| 851 | check_access = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).check_accessscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access(). |
| 852 | |
| 853 | menu_items = [] |
| 854 | for item in sitetree_items: |
| 855 | if not item.hidden and item.inmenu and check_access(item, contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(context)): |
| 856 | if item.parent is None: |
| 857 | if parent_isnull: |
| 858 | menu_items.appendscip-python python python-stdlib 3.11 builtins/list#append().(item) |
| 859 | else: |
| 860 | if item.parent.id in parent_ids or item.parent.alias in parent_aliases: |
| 861 | menu_items.appendscip-python python python-stdlib 3.11 builtins/list#append().(item) |
| 862 | |
| 863 | menu_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(menu_items, 'menu') |
| 864 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(self).update_has_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#menu().(tree_alias), menu_items, 'menu') |
| 865 | |
| 866 | return menu_items |
| 867 | |
| 868 | def apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(self), itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(items): Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase'], senderscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(sender): strscip-python python python-stdlib 3.11 builtins/str#) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 869 | """Applies a custom items processing hook to items supplied, and returns processed list. |
| 870 | Suitable for items filtering and other manipulations. |
| 871 | |
| 872 | Returns initial items list if no hook is registered. |
| 873 | |
| 874 | .. note:: Use `SITETREE_CLS` setting customization and override this method. |
| 875 | |
| 876 | :param items: |
| 877 | :param sender: menu, breadcrumbs, sitetree, {type}.children, {type}.has_children |
| 878 | |
| 879 | """ |
| 880 | processor = _ITEMS_PROCESSORscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR._ITEMS_PROCESSOR. |
| 881 | |
| 882 | if processor is None: |
| 883 | return itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(items) |
| 884 | |
| 885 | if _ITEMS_PROCESSOR_ARGS_LENscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_ITEMS_PROCESSOR_ARGS_LEN._ITEMS_PROCESSOR_ARGS_LEN. == 2: |
| 886 | return processor(tree_items=itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(items), tree_sender=senderscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(sender)) |
| 887 | |
| 888 | return processor(tree_items=itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(items), tree_sender=senderscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(sender), context=selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context.) |
| 889 | |
| 890 | def check_access_authscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(self), itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(item): 'TreeItemBase', contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> boolscip-python python python-stdlib 3.11 builtins/bool#: |
| 891 | """Performs authentication related checks: whether the current user has an access to a certain item. |
| 892 | |
| 893 | :param item: |
| 894 | :param context: |
| 895 | |
| 896 | """ |
| 897 | authenticated = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(self).current_requestscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_request..user.is_authenticated |
| 898 | |
| 899 | if hasattr(authenticated, '__call__'): |
| 900 | authenticated = authenticated() |
| 901 | |
| 902 | if itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(item).access_loggedin and not authenticated: |
| 903 | return False |
| 904 | |
| 905 | if itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(item).access_guest and authenticated: |
| 906 | return False |
| 907 | |
| 908 | return True |
| 909 | |
| 910 | def check_access_permsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(self), itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(item): 'TreeItemBase', contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> boolscip-python python python-stdlib 3.11 builtins/bool#: |
| 911 | """Performs permissions related checks: whether the current user has an access to a certain item. |
| 912 | |
| 913 | :param item: |
| 914 | :param context: |
| 915 | |
| 916 | """ |
| 917 | if itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(item).access_restricted: |
| 918 | user_perms = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(self)._current_user_permissionsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_user_permissions. |
| 919 | |
| 920 | if user_perms is _UNSETscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_UNSET.: |
| 921 | user_perms = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(self).get_permissionsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(self).current_requestscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_request..user, itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(item)) |
| 922 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(self)._current_user_permissionsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_user_permissions. = user_perms |
| 923 | |
| 924 | perms = itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(item).perms # noqa dynamic attr |
| 925 | |
| 926 | if itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(item).access_perm_type == MODEL_TREE_ITEM_CLASSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/MODEL_TREE_ITEM_CLASS..PERM_TYPE_ALL: |
| 927 | if len(perms) != len(perms.intersection(user_perms)): |
| 928 | return False |
| 929 | else: |
| 930 | if not len(perms.intersection(user_perms)): |
| 931 | return False |
| 932 | |
| 933 | return True |
| 934 | |
| 935 | def check_access_dynscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(self), itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(item): 'TreeItemBase', contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> Optionalscip-python python python-stdlib 3.11 typing/Optional.[boolscip-python python python-stdlib 3.11 builtins/bool#]: |
| 936 | """Performs dynamic item access check. |
| 937 | |
| 938 | :param item: The item is expected to have `access_check` callable attribute implementing the check. |
| 939 | :param context: |
| 940 | |
| 941 | """ |
| 942 | result = None |
| 943 | access_check_func = getattrscip-python python python-stdlib 3.11 builtins/getattr().(itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(item), 'access_check', None) |
| 944 | |
| 945 | if access_check_func: |
| 946 | return access_check_func(tree=selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(self)) |
| 947 | |
| 948 | return None |
| 949 | |
| 950 | def check_accessscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(self), itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(item): 'TreeItemBase', contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> boolscip-python python python-stdlib 3.11 builtins/bool#: |
| 951 | """Checks whether a current user has an access to a certain item. |
| 952 | |
| 953 | :param item: |
| 954 | :param context: |
| 955 | |
| 956 | """ |
| 957 | dyn_check = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(self).check_access_dynscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_dyn().(itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(item), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(context)) |
| 958 | |
| 959 | if dyn_check is not None: |
| 960 | return dyn_check |
| 961 | |
| 962 | if not selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(self).check_access_authscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_auth().(itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(item), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(context)): |
| 963 | return False |
| 964 | |
| 965 | if not selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(self).check_access_permsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access_perms().(itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(item), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access().(context)): |
| 966 | return False |
| 967 | |
| 968 | return True |
| 969 | |
| 970 | def get_permissionsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(self), userscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(user): 'User', itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(item): 'TreeItemBase') -> setscip-python python python-stdlib 3.11 builtins/set#: |
| 971 | """Returns a set of user and group level permissions for a given user. |
| 972 | |
| 973 | :param user: |
| 974 | :param item: |
| 975 | |
| 976 | """ |
| 977 | return userscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_permissions().(user).get_all_permissions() |
| 978 | |
| 979 | def breadcrumbsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 980 | """Builds and returns breadcrumb trail structure for 'sitetree_breadcrumbs' tag. |
| 981 | |
| 982 | :param tree_alias: |
| 983 | :param context: |
| 984 | |
| 985 | """ |
| 986 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias), sitetree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).init_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(context)) |
| 987 | |
| 988 | if not sitetree_items: |
| 989 | return [] |
| 990 | |
| 991 | current_item = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias)) |
| 992 | |
| 993 | breadcrumbs = [] |
| 994 | |
| 995 | if current_item is not None: |
| 996 | |
| 997 | context_ = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context. |
| 998 | check_access = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).check_accessscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access(). |
| 999 | get_item_by_id = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).get_item_by_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id(). |
| 1000 | |
| 1001 | def climbscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item)): |
| 1002 | """Climbs up the site tree to build breadcrumb path. |
| 1003 | |
| 1004 | :param TreeItemBase base_item: |
| 1005 | """ |
| 1006 | if base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item).inbreadcrumbs and not base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item).hidden and check_access(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item), context_): |
| 1007 | breadcrumbs.appendscip-python python python-stdlib 3.11 builtins/list#append().(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item)) |
| 1008 | |
| 1009 | if hasattr(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item), 'parent') and base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item).parent is not None: |
| 1010 | climbscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(get_item_by_id(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias), base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(base_item).parent.id)) |
| 1011 | |
| 1012 | climbscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#climb().(current_item) |
| 1013 | breadcrumbs.reversescip-python python python-stdlib 3.11 typing/MutableSequence#reverse().() |
| 1014 | |
| 1015 | items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(breadcrumbs, 'breadcrumbs') |
| 1016 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(self).update_has_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#breadcrumbs().(tree_alias), items, 'breadcrumbs') |
| 1017 | |
| 1018 | return items |
| 1019 | |
| 1020 | def treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(tree_alias): TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context#) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 1021 | """Builds and returns tree structure for 'sitetree_tree' tag. |
| 1022 | |
| 1023 | :param tree_alias: |
| 1024 | :param context: |
| 1025 | |
| 1026 | """ |
| 1027 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(tree_alias), sitetree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self).init_treescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#init_tree().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(tree_alias), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(context)) |
| 1028 | |
| 1029 | if not sitetree_items: |
| 1030 | return [] |
| 1031 | |
| 1032 | tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self).filter_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self).get_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(tree_alias), None), 'sitetree') |
| 1033 | tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self).apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(tree_items, 'sitetree') |
| 1034 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(self).update_has_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree().(tree_alias), tree_items, 'sitetree') |
| 1035 | |
| 1036 | return tree_items |
| 1037 | |
| 1038 | def childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().( |
| 1039 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self), |
| 1040 | parent_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(parent_item): Unionscip-python python python-stdlib 3.11 typing/Union.[strscip-python python python-stdlib 3.11 builtins/str#, 'TreeItemBase'], |
| 1041 | navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(navigation_type): strscip-python python python-stdlib 3.11 builtins/str#, |
| 1042 | use_templatescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(use_template): strscip-python python python-stdlib 3.11 builtins/str#, |
| 1043 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context# |
| 1044 | ) -> strscip-python python python-stdlib 3.11 builtins/str#: |
| 1045 | """Builds and returns site tree item children structure for 'sitetree_children' tag. |
| 1046 | |
| 1047 | :param parent_item: |
| 1048 | :param navigation_type: menu, sitetree |
| 1049 | :param use_template: |
| 1050 | :param context: |
| 1051 | |
| 1052 | """ |
| 1053 | # Resolve parent item and current tree alias. |
| 1054 | parent_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(parent_item) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).resolve_varscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(parent_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(parent_item), contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context)) |
| 1055 | tree_alias, tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).get_sitetreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_sitetree().(parent_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(parent_item).tree.alias) |
| 1056 | |
| 1057 | # Mark path to current item. |
| 1058 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).tree_climberscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_alias, selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).get_tree_current_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_tree_current_item().(tree_alias)) |
| 1059 | |
| 1060 | tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).get_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_alias, parent_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(parent_item)) |
| 1061 | tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).filter_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(tree_items, navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(navigation_type)) |
| 1062 | tree_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook().(tree_items, f'{navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(navigation_type)}.children') |
| 1063 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(self).update_has_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_alias, tree_items, navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(navigation_type)) |
| 1064 | |
| 1065 | my_template = get_template(use_templatescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(use_template)) |
| 1066 | |
| 1067 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context).push() |
| 1068 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context)['sitetree_items'] = tree_items |
| 1069 | rendered = my_template.render(contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context).flatten()) |
| 1070 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#children().(context).pop() |
| 1071 | |
| 1072 | return rendered |
| 1073 | |
| 1074 | def get_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(item): Optionalscip-python python python-stdlib 3.11 typing/Optional.['TreeItemBase']) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 1075 | """Returns item's children. |
| 1076 | |
| 1077 | :param tree_alias: |
| 1078 | :param item: |
| 1079 | |
| 1080 | """ |
| 1081 | if not selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin.: |
| 1082 | # We do not need i18n for a tree rendered in Admin dropdown. |
| 1083 | tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_alias) = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(self).resolve_tree_i18n_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_tree_i18n_alias().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_alias)) |
| 1084 | |
| 1085 | return selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(self).cachescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#cache..get_entryscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/Cache#get_entry().('parents', tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(tree_alias))[itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children().(item)] |
| 1086 | |
| 1087 | def update_has_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_items): Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase'], navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(navigation_type): strscip-python python python-stdlib 3.11 builtins/str#): |
| 1088 | """Updates 'has_children' attribute for tree items inplace. |
| 1089 | |
| 1090 | :param tree_alias: |
| 1091 | :param tree_items: |
| 1092 | :param navigation_type: sitetree, breadcrumbs, menu |
| 1093 | |
| 1094 | """ |
| 1095 | get_children = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(self).get_childrenscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_children(). |
| 1096 | filter_items = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(self).filter_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items(). |
| 1097 | apply_hook = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(self).apply_hookscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#apply_hook(). |
| 1098 | |
| 1099 | for tree_item in tree_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_items): |
| 1100 | children = get_children(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(tree_alias), tree_item) |
| 1101 | children = filter_items(children, navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(navigation_type)) |
| 1102 | children = apply_hook(children, f'{navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#update_has_children().(navigation_type)}.has_children') |
| 1103 | tree_item.has_children = len(children) > 0 |
| 1104 | |
| 1105 | def filter_itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(self), itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(items): Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase'], navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(navigation_type): strscip-python python python-stdlib 3.11 builtins/str# = None) -> Listscip-python python python-stdlib 3.11 typing/List.['TreeItemBase']: |
| 1106 | """Filters sitetree item's children if hidden and by navigation type. |
| 1107 | |
| 1108 | NB: We do not apply any filters to sitetree in admin app. |
| 1109 | |
| 1110 | :param items: |
| 1111 | :param navigation_type: sitetree, breadcrumbs, menu |
| 1112 | |
| 1113 | """ |
| 1114 | if selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(self)._current_app_is_adminscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#_current_app_is_admin.: |
| 1115 | return itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(items) |
| 1116 | |
| 1117 | items_filtered = [] |
| 1118 | |
| 1119 | context = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context. |
| 1120 | check_access = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(self).check_accessscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#check_access(). |
| 1121 | |
| 1122 | for item in itemsscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(items): |
| 1123 | if item.hidden: |
| 1124 | continue |
| 1125 | |
| 1126 | if not check_access(item, context): |
| 1127 | continue |
| 1128 | |
| 1129 | if not getattrscip-python python python-stdlib 3.11 builtins/getattr().(item, f'in{navigation_typescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#filter_items().(navigation_type)}', True): # Hidden for current nav type |
| 1130 | continue |
| 1131 | |
| 1132 | items_filtered.appendscip-python python python-stdlib 3.11 builtins/list#append().(item) |
| 1133 | |
| 1134 | return items_filtered |
| 1135 | |
| 1136 | def get_ancestor_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(base_item): 'TreeItemBase') -> 'TreeItemBase': |
| 1137 | """Climbs up the site tree to resolve root item for chosen one. |
| 1138 | |
| 1139 | :param tree_alias: |
| 1140 | :param base_item: |
| 1141 | |
| 1142 | """ |
| 1143 | parent = None |
| 1144 | |
| 1145 | if hasattr(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(base_item), 'parent') and base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(base_item).parent is not None: |
| 1146 | parent = selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(self).get_ancestor_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(tree_alias), selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(self).get_item_by_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(tree_alias), base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(base_item).parent.id)) |
| 1147 | |
| 1148 | if parent is None: |
| 1149 | return base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_ancestor_item().(base_item) |
| 1150 | |
| 1151 | return parent |
| 1152 | |
| 1153 | def tree_climberscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(self), tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_alias): strscip-python python python-stdlib 3.11 builtins/str#, base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item): 'TreeItemBase'): |
| 1154 | """Climbs up the site tree to mark items of current branch. |
| 1155 | |
| 1156 | :param tree_alias: |
| 1157 | :param base_item: |
| 1158 | |
| 1159 | """ |
| 1160 | if base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item) is not None: |
| 1161 | base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item).in_current_branch = True |
| 1162 | if hasattr(base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item), 'parent') and base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item).parent is not None: |
| 1163 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(self).tree_climberscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_alias), selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(self).get_item_by_idscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#get_item_by_id().(tree_aliasscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(tree_alias), base_itemscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#tree_climber().(base_item).parent.id)) |
| 1164 | |
| 1165 | def resolve_varscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().( |
| 1166 | selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(self), |
| 1167 | varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname): Unionscip-python python python-stdlib 3.11 typing/Union.[TypeStrExprscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/TypeStrExpr., 'TreeItemBase'], |
| 1168 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(context): Contextscip-python python django-sitetree 1.18.0 `django.template.context`/Context# = None |
| 1169 | ) -> Anyscip-python python python-stdlib 3.11 typing/Any.: |
| 1170 | """Resolves name as a variable in a given context. |
| 1171 | |
| 1172 | If no context specified page context is considered as context. |
| 1173 | |
| 1174 | :param varname: |
| 1175 | :param context: |
| 1176 | |
| 1177 | """ |
| 1178 | contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(context) = contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(context) or selfscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(self).current_page_contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#current_page_context. |
| 1179 | |
| 1180 | if isinstance(varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname), FilterExpression): |
| 1181 | varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) = varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname).resolve(contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(context)) |
| 1182 | |
| 1183 | else: |
| 1184 | varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) = varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname).stripscip-python python python-stdlib 3.11 builtins/str#strip().() |
| 1185 | |
| 1186 | try: |
| 1187 | varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) = Variable(varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname)).resolve(contextscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(context)) |
| 1188 | except VariableDoesNotExist: |
| 1189 | varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) = varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) |
| 1190 | |
| 1191 | return varnamescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree#resolve_var().(varname) |
| 1192 | |
| 1193 | |
| 1194 | _SITETREE_CLSscip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/_SITETREE_CLS. = module_loadingscip-python python Django 5.2.15 `django.utils.module_loading`/__init__:.import_string(SITETREE_CLSscip-python python django-sitetree 1.18.0 `sitetree.settings`/SITETREE_CLS.SITETREE_CLS.) if SITETREE_CLSscip-python python django-sitetree 1.18.0 `sitetree.settings`/SITETREE_CLS.SITETREE_CLS. else SiteTreescip-python python django-sitetree 1.18.0 `sitetree.sitetreeapp`/SiteTree# |