Files
old-saburly-wagtail-web/env/lib/python3.10/site-packages/treebeard/__pycache__/models.cpython-310.pyc

366 lines
22 KiB
Plaintext
Raw Normal View History

2024-08-27 20:33:44 +02:00
o
<00><><EFBFBD>f<EFBFBD>U<00>@s^dZddlZddlmZddlmZddlmZmZm Z ddl
m Z m Z Gdd<08>dej <0A>ZdS) zModels and base API<50>N)<01>reduce<63><01>Q)<03>models<6C>router<65> connections)<02>InvalidPosition<6F>MissingNodeOrderByc@seZdZdZdZedd<04><00>Zedd<06><00>Zedd<08><00>Zedgd
d <0B><01>Z edhd d<0E><01>Z
edd<10><00>Z edd<12><00>Z edd<14><00>Z edd<16><00>Zedd<18><00>Zedidd<1A><01>Zedidd<1C><01>Zdd<1E>Zdd <20>Zd!d"<22>Zd#d$<24>Zd%d&<26>Zd'd(<28>Zd)d*<2A>Zd+d,<2C>Zd-d.<2E>Zd/d0<64>Zd1d2<64>Zd3d4<64>Zd5d6<64>Zd7d8<64>Zd9d:<3A>Z d;d<<3C>Z!did=d><3E>Z"d?d@<40>Z#dAdB<64>Z$dCdD<64>Z%dEdF<64>Z&djdGdH<64>Z'didIdJ<64>Z(dKdL<64>Z)d e)_*d e)_+dMdN<64>Z,dOZ-dPZ.dQdR<64>Z/e-dSZ0e.dTZ1dUdV<64>Z2dWdX<64>Z3edYdZ<64><00>Z4edkd[d\<5C><01>Z5ed]d^<5E><00>Z6ed_d`<60><00>Z7edadb<64><00>Z8edcdd<64><00>Z9Gdedf<64>df<64>Z:dS)l<>Nodez
Node classNcK<00>t<00>)a<>
Adds a root node to the tree. The new root node will be the new
rightmost root node. If you want to insert a root node at a specific
position, use :meth:`add_sibling` in an already existing root node
instead.
:param `**kwargs`: object creation data that will be passed to the
inherited Node model
:param instance: Instead of passing object creation data, you can
pass an already-constructed (but not yet saved) model instance to
be inserted into the tree.
:returns: the created node object. It will be save()d by this method.
:raise NodeAlreadySaved: when the passed ``instance`` already exists
in the database
<20><01>NotImplementedError)<02>cls<6C>kwargs<67>r<00>R/home/amir/Desktop/saburlyweb/env/lib/python3.10/site-packages/treebeard/models.py<70>add_rootsz Node.add_rootcCs:i}|jjD]}|<02><02>dkr|jdkr|jj||j<q|S)zhGet foreign keys and models they refer to, so we can pre-process
the data for load_bulk
<20>
ForeignKey<EFBFBD>parent)<06>_meta<74>fields<64>get_internal_type<70>name<6D> remote_field<6C>model)r<00> foreign_keys<79>fieldrrr<00>get_foreign_keys&s  
<02>zNode.get_foreign_keyscCs4|<01><00>D]}||vr||jj||d<01>||<qdS)z<>For each foreign key try to load the actual object so load_bulk
doesn't fail trying to load an int where django expects a
model instance
<20><01>pkN)<03>keys<79>objects<74>get)rr<00> node_data<74>keyrrr<00>_process_foreign_keys4s 

<EFBFBD><02><04>zNode._process_foreign_keysFc
s<>g}<04>fdd<02>|ddd<04>D<00>}|<00><00>}|jjj}|rg|<05><04>\<02>}|d<00><05>} |<00>|| <09>|r5||| |<<00>r@<40>jdi| <09><01><01>n|jdi| <09><01><01>|<04> <09>j<02>d|vre|<05>
<EFBFBD>fdd<02>|dddd<04>D<00><01>|s|S) a<>
Loads a list/dictionary structure to the tree.
:param bulk_data:
The data that will be loaded, the structure is a list of
dictionaries with 2 keys:
- ``data``: will store arguments that will be passed for object
creation, and
- ``children``: a list of dictionaries, each one has it's own
``data`` and ``children`` keys (a recursive structure)
:param parent:
The node that will receive the structure as children, if not
specified the first level of the structure will be loaded as root
nodes
:param keep_ids:
If enabled, loads the nodes with the same primary keys that are
given in the structure. Will error if there are nodes without
primary key info or if the primary keys are already used.
:returns: A list of the added node ids.
c<00>g|]}<01>|f<02>qSrr<00><02>.0<EFBFBD>node)rrr<00>
<listcomp>esz"Node.load_bulk.<locals>.<listcomp>N<><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>data<74>childrencr&rrr')<01>node_objrrr*xs<06><06>r) rrr<00>attname<6D>pop<6F>copyr%<00> add_childr<00>append<6E>extend)
r<00> bulk_datar<00>keep_ids<64>added<65>stackr<00>pk_field<6C> node_structr#r)r.rr<00> load_bulk?s($
     <08><04>zNode.load_bulkTcCr )a<>
Dumps a tree branch to a python data structure.
:param parent:
The node whose descendants will be dumped. The node itself will be
included in the dump. If not given, the entire tree will be dumped.
:param keep_ids:
Stores the pk value (primary key) of every node. Enabled by
default.
:returns: A python data structure, described with detail in
:meth:`load_bulk`
r )rrr6rrr<00> dump_bulk~szNode.dump_bulkcCr )z;:returns: A queryset containing the root nodes in the tree.r <00>rrrr<00>get_root_nodes<65><00>zNode.get_root_nodescC<00>$z|<00><00>dWStyYdSw)zd
:returns:
The first root node in the tree or ``None`` if it is empty.
rN)r><00>
IndexErrorr=rrr<00>get_first_root_node<64>s
 <02>zNode.get_first_root_nodecC<00>(z |<00><00><00><01>dWStyYdSw)zc
:returns:
The last root node in the tree or ``None`` if it is empty.
rN)r><00>reverserAr=rrr<00>get_last_root_node<64>s
 <02>zNode.get_last_root_nodecCr )z*Checks for problems in the tree structure.r r=rrr<00> find_problems<6D>r?zNode.find_problemscCr )z<>
Solves problems that can appear when transactions are not used and
a piece of code breaks, leaving the tree in an inconsistent state.
r r=rrr<00>fix_tree<65>sz Node.fix_treecCr )z<>
:returns:
A list of nodes ordered as DFS, including the parent. If
no parent is given, the entire tree is returned.
r )rrrrr<00>get_tree<65><00>z Node.get_treecCs:|dur |<00><00>}n|<01><01>}t|<02>}|D]}|<04><03>|_q|S)a<>
Helper for a very common case: get a group of siblings and the number
of *descendants* (not only children) in every sibling.
:param parent:
The parent of the siblings to return. If no parent is given, the
root nodes will be returned.
:returns:
A `list` (**NOT** a Queryset) of node objects with an extra
attribute: `descendants_count`.
N)r><00> get_children<65>list<73>get_descendant_count<6E>descendants_count)rr<00>qset<65>nodesr)rrr<00>get_descendants_group_count<6E>s
 z Node.get_descendants_group_countcCr )z':returns: the depth (level) of the noder <00><01>selfrrr<00> get_depth<74><00>zNode.get_depthcCr )zv
:returns:
A queryset of all the node's siblings, including the node
itself.
r rQrrr<00> get_siblings<67><00>zNode.get_siblingscCr )z/:returns: A queryset of all the node's childrenr rQrrrrJ<00>rTzNode.get_childrencC<00> |<00><00><00><01>S)z+:returns: The number of the node's children)rJ<00>countrQrrr<00>get_children_count<6E><00> zNode.get_children_countcCr )z<>
:returns:
A queryset of all the node's descendants, doesn't
include the node itself (some subclasses may return a list).
r rQrrr<00>get_descendants<74>rVzNode.get_descendantscCrW)z.:returns: the number of descendants of a node.)r[rXrQrrrrL<00>rZzNode.get_descendant_countcCr@)zb
:returns:
The leftmost node's child, or None if it has no children.
rN)rJrArQrrr<00>get_first_childs
 <02>zNode.get_first_childcCrC)zc
:returns:
The rightmost node's child, or None if it has no children.
rN)rJrDrArQrrr<00>get_last_child s
 <02>zNode.get_last_childcCs |<00><00>dS)z<>
:returns:
The leftmost node's sibling, can return the node itself if
it was the leftmost sibling.
r)rUrQrrr<00>get_first_siblings zNode.get_first_siblingcCs|<00><00><00><01>dS)z<>
:returns:
The rightmost node's sibling, can return the node itself if
it was the rightmost sibling.
r)rUrDrQrrr<00>get_last_sibling szNode.get_last_siblingcCsH|<00><00>}dd<02>|D<00>}|j|vr |<02>|j<01>}|dkr"||dSdSdS)zy
:returns:
The previous node's sibling, or None if it was the leftmost
sibling.
cS<00>g|]}|j<00>qSrr<00>r(<00>objrrrr*1<00>z)Node.get_prev_sibling.<locals>.<listcomp>r<00>N)rUr<00>index<65>rR<00>siblings<67>ids<64>idxrrr<00>get_prev_sibling)s
  <04>zNode.get_prev_siblingcCsP|<00><00>}dd<02>|D<00>}|j|vr$|<02>|j<01>}|t|<01>dkr&||dSdSdS)zv
:returns:
The next node's sibling, or None if it was the rightmost
sibling.
cSr`rrrarrrr*?rcz)Node.get_next_sibling.<locals>.<listcomp>rdN)rUrre<00>lenrfrrr<00>get_next_sibling7s
  <04>zNode.get_next_siblingcCs|<00><00>j|jd<01><01><03>S)z<>
:returns: ``True`` if the node is a sibling of another node given as an
argument, else, returns ``False``
:param node:
The node that will be checked as a sibling
r)rU<00>filterr<00>exists<74>rRr)rrr<00> is_sibling_ofE<00> zNode.is_sibling_ofcCs|<01><00>j|jd<01><01><03>S)z<>
:returns: ``True`` if the node is a child of another node given as an
argument, else, returns ``False``
:param node:
The node that will be checked as a parent
r)rJrmrrnrorrr<00> is_child_ofPrqzNode.is_child_ofcCr )z<>
:returns: ``True`` if the node is a descendant of another node given
as an argument, else, returns ``False``
:param node:
The node that will be checked as an ancestor
r rorrr<00>is_descendant_of[s zNode.is_descendant_ofcKr )a<>
Adds a child to the node. The new node will be the new rightmost
child. If you want to insert a node at a specific position,
use the :meth:`add_sibling` method of an already existing
child node instead.
:param `**kwargs`:
Object creation data that will be passed to the inherited Node
model
:param instance: Instead of passing object creation data, you can
pass an already-constructed (but not yet saved) model instance to
be inserted into the tree.
:returns: The created node object. It will be save()d by this method.
:raise NodeAlreadySaved: when the passed ``instance`` already exists
in the database
r )rRrrrrr2fszNode.add_childcKr )a
Adds a new node as a sibling to the current node object.
:param pos:
The position, relative to the current node object, where the
new node will be inserted, can be one of:
- ``first-sibling``: the new node will be the new leftmost sibling
- ``left``: the new node will take the node's place, which will be
moved to the right 1 position
- ``right``: the new node will be inserted at the right of the node
- ``last-sibling``: the new node will be the new rightmost sibling
- ``sorted-sibling``: the new node will be at the right position
according to the value of node_order_by
:param `**kwargs`:
Object creation data that will be passed to the inherited
Node model
:param instance: Instead of passing object creation data, you can
pass an already-constructed (but not yet saved) model instance to
be inserted into the tree.
:returns:
The created node object. It will be saved by this method.
:raise InvalidPosition: when passing an invalid ``pos`` parm
:raise InvalidPosition: when :attr:`node_order_by` is enabled and the
``pos`` parm wasn't ``sorted-sibling``
:raise MissingNodeOrderBy: when passing ``sorted-sibling`` as ``pos``
and the :attr:`node_order_by` attribute is missing
:raise NodeAlreadySaved: when the passed ``instance`` already exists
in the database
r )rR<00>posrrrr<00> add_sibling|s%zNode.add_siblingcCr )z4:returns: the root node for the current node object.r rQrrr<00>get_root<6F>rTz Node.get_rootcCs|<00><00>j|jkS)z?:returns: True if the node is a root node (else, returns False))rvrrQrrr<00>is_root<6F>sz Node.is_rootcCs|<00><00><00><01> S)z?:returns: True if the node is a leaf node (else, returns False))rJrnrQrrr<00>is_leaf<61><00>z Node.is_leafcCr )z<>
:returns:
A queryset containing the current node object's ancestors,
starting by the root node and descending to the parent.
(some subclasses may return a list)
r rQrrr<00> get_ancestors<72>rIzNode.get_ancestorscCr )z<>
:returns: the parent node of the current node object.
Caches the result in the object itself to help in loops.
:param update: Updates the cached value.
r )rR<00>updaterrr<00>
get_parent<EFBFBD>rVzNode.get_parentcCr )ax
Moves the current node and all it's descendants to a new position
relative to another node.
:param target:
The node that will be used as a relative child/sibling when moving
:param pos:
The position, relative to the target node, where the
current node object will be moved to, can be one of:
- ``first-child``: the node will be the new leftmost child of the
``target`` node
- ``last-child``: the node will be the new rightmost child of the
``target`` node
- ``sorted-child``: the new node will be moved as a child of the
``target`` node according to the value of :attr:`node_order_by`
- ``first-sibling``: the node will be the new leftmost sibling of
the ``target`` node
- ``left``: the node will take the ``target`` node's place, which
will be moved to the right 1 position
- ``right``: the node will be moved to the right of the ``target``
node
- ``last-sibling``: the node will be the new rightmost sibling of
the ``target`` node
- ``sorted-sibling``: the new node will be moved as a sibling of
the ``target`` node according to the value of
:attr:`node_order_by`
.. note::
If no ``pos`` is given the library will use ``last-sibling``,
or ``sorted-sibling`` if :attr:`node_order_by` is enabled.
:returns: None
:raise InvalidPosition: when passing an invalid ``pos`` parm
:raise InvalidPosition: when :attr:`node_order_by` is enabled and the
``pos`` parm wasn't ``sorted-sibling`` or ``sorted-child``
:raise InvalidMoveToDescendant: when trying to move a node to one of
it's own descendants
:raise PathOverflow: when the library can't make room for the
node's new position
:raise MissingNodeOrderBy: when passing ``sorted-sibling`` or
``sorted-child`` as ``pos`` and the :attr:`node_order_by`
attribute is missing
r )rR<00>targetrtrrr<00>move<76>s2z Node.movecOs|jjj|jd<01>j|i|<02><01>S)z(Removes a node and all it's descendants.r)<05> __class__r!rmr<00>delete)rR<00>argsrrrrr<><00>sz Node.deletecCsl|dur |jr
d}nd}||vrtd|f<00><01>|jr)||vr)tdd<05>|<04>|f<00><01>||vr4|js4td<06><01>|S)N<>sorted-sibling<6E> last-siblingzInvalid relative position: %sz/Must use %s in %s when node_order_by is enabledz or z Missing node_order_by attribute.)<04> node_order_byr<00>joinr )rRrt<00> method_name<6D> valid_pos<6F>valid_sorted_posrrr<00>_prepare_pos_var<61>s
<04><04>zNode._prepare_pos_var)z first-sibling<6E>left<66>rightr<74>r<>)r<>cC<00>|<00>|d|j|j<02>S)Nru)r<><00>_valid_pos_for_add_sibling<6E>!_valid_pos_for_sorted_add_sibling<6E>rRrtrrr<00> _prepare_pos_var_for_add_sibling<00> <04>z%Node._prepare_pos_var_for_add_sibling)z first-childz
last-child<6C> sorted-child)r<>cCr<>)Nr~)r<><00>_valid_pos_for_move<76>_valid_pos_for_sorted_mover<65>rrr<00>_prepare_pos_var_for_mover<>zNode._prepare_pos_var_for_movec
Cspgg}}|jD]&}t||<05>}|<04>tdd<02>|D<00>tdid||i<01><01>g<00><00>|<03>||f<02>q|<01>ttj|<04><02>S)am
:returns:
A queryset of the nodes that must be moved to the right.
Called only for Node models with :attr:`node_order_by`
This function is based on _insertion_target_filters from django-mptt
(BSD licensed) by Jonathan Buchanan:
https://github.com/django-mptt/django-mptt/blob/0.3.0/mptt/signals.py
cSs"g|] \}}tdi||i<01><01><01>qS)rr)r(<00>f<>vrrrr*5s"z0Node.get_sorted_pos_queryset.<locals>.<listcomp>z%s__gtNr)r<><00>getattrr3rrmr<00>operator<6F>or_)rRrg<00>newobjr<00>filtersr<00>valuerrr<00>get_sorted_pos_queryset$s

 <02><02><04>zNode.get_sorted_pos_querysetc Cs<>gi}}d\}}|D]:}|<06><00>}|dur|}|o |dup ||k}|dur4||kr4ttd||<00><02>|d<|g||d<05>}|<02>||f<02>|}q |rY|dkrYttd||d<00><02>|d<|S)z9
Gets an annotated list from a queryset.
<20>NNNr<00>close)<03>openr<6E><00>levelrd)rSrK<00>ranger3) r<00>qs<71>result<6C>info<66> start_depth<74>
prev_depthr)<00>depthr<68>rrr<00>get_annotated_list_qs<s
 zNode.get_annotated_list_qscCs6gi}}d\}}|<00>|<01>}|r|j|d<02>}|<00>|<07>S)aR
Gets an annotated list from a tree branch.
:param parent:
The node whose descendants will be annotated. The node itself
will be included in the list. If not given, the entire tree
will be annotated.
:param max_depth:
Optionally limit to specified depth
r<>)<01>
depth__lte)rHrmr<>)rr<00> max_depthr<68>r<>r<>r<>r<>rrr<00>get_annotated_listQs

 
zNode.get_annotated_listcCs |}|jjr|jj}|jjs|S)z<>
Returns a model with a valid _meta.local_fields (serializable).
Basically, this means the original model, not a proxied model.
(this is a workaround for a bug in django)
)r<00>proxy<78>proxy_for_model)r<00> current_classrrr<00>_get_serializable_modelhs
 <08>zNode._get_serializable_modelcCs"tt<01>|<00>tt<01>|<00>d<01>|S)N)<02>read<61>write)rr<00> db_for_read<61> db_for_write<74>r<00>actionrrr<00>_get_database_connectionvs
 <04><04>zNode._get_database_connectioncCs |<00>|<01>jS)a 
returns the supported database vendor used by a treebeard model when
performing read (select) or write (update, insert, delete) operations.
:param action:
`read` or `write`
:returns: postgresql, mysql or sqlite
)r<><00>vendorr<72>rrr<00>get_database_vendor}s zNode.get_database_vendorcCs|<00>|<01><01><01>S<00>N)r<><00>cursorr<72>rrr<00>_get_database_cursor<6F>ryzNode._get_database_cursorc@seZdZdZdZdS)z Node.MetazAbstract model.TN)<05>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F>abstractrrrr<00>Meta<74>sr<>)NF)NTr<54>)Fr<46>);r<>r<>r<>r<><00>_db_connection<6F> classmethodrrr%r;r<r>rBrErFrGrHrPrSrUrJrYr[rLr\r]r^r_rjrlrprrrsr2rurvrwrxrzr|r~r<><00> alters_data<74> queryset_onlyr<79>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>rrrrr
s<>



> 




          
'
4
 



r
)r<>r<><00> functoolsr<00>django.db.modelsr<00> django.dbrrr<00>treebeard.exceptionsrr <00>Modelr
rrrr<00><module>s