Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MO-P
Odevzdávací Systém MO
Commits
7acb33d7
Commit
7acb33d7
authored
Sep 24, 2021
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
DB: find_place_nth_parent()
parent
74b95e60
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/db.py
+11
-1
11 additions, 1 deletion
mo/db.py
with
11 additions
and
1 deletion
mo/db.py
+
11
−
1
View file @
7acb33d7
...
...
@@ -11,8 +11,9 @@ from sqlalchemy import \
text
,
func
,
\
create_engine
,
inspect
,
select
from
sqlalchemy.engine
import
Engine
from
sqlalchemy.orm
import
relationship
,
sessionmaker
,
Session
,
class_mapper
,
joinedload
from
sqlalchemy.orm
import
relationship
,
sessionmaker
,
Session
,
class_mapper
,
joinedload
,
aliased
from
sqlalchemy.orm.attributes
import
get_history
from
sqlalchemy.orm.query
import
Query
from
sqlalchemy.dialects.postgresql
import
JSONB
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.sql.expression
import
CTE
...
...
@@ -819,6 +820,15 @@ def get_place_descendants(place: Place, min_level: Optional[int] = None, max_lev
return
q
.
all
()
def
filter_place_nth_parent
(
query
:
Query
,
place_attr
:
Any
,
n
:
int
,
parent_id
:
int
)
->
Query
:
assert
n
>=
0
for
_
in
range
(
n
):
pp
=
aliased
(
Place
)
query
=
query
.
join
(
pp
,
pp
.
place_id
==
place_attr
)
place_attr
=
pp
.
parent
return
query
.
filter
(
place_attr
==
parent_id
)
def
get_object_changes
(
obj
):
"""
Given a model instance, returns dict of pending
changes waiting for database flush/commit.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment