Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
23b2218f
Commit
23b2218f
authored
3 years ago
by
OndraRehounek
Browse files
Options
Downloads
Patches
Plain Diff
district and region: Page chooser hook filtering parents only - concept version
parent
0f6515de
No related branches found
No related tags found
2 merge requests
!435
Release upgrades
,
!430
Feature/majak misc enhancements
Pipeline
#7144
passed
3 years ago
Stage: build
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
district/wagtail_hooks.py
+46
-0
46 additions, 0 deletions
district/wagtail_hooks.py
with
46 additions
and
0 deletions
district/wagtail_hooks.py
0 → 100644
+
46
−
0
View file @
23b2218f
import
re
from
wagtail.core
import
hooks
# FIXME hooks are loaded globally so it doesn't make sense to have it in this module
@hooks.register
(
"
construct_page_chooser_queryset
"
)
def
this_web_only
(
pages
,
request
):
add_result
=
re
.
search
(
"
page/(.*)/
"
,
request
.
META
.
get
(
"
HTTP_REFERER
"
)
)
# FIXME better regex
edit_result
=
re
.
search
(
"
pages/(.*)/edit
"
,
request
.
META
.
get
(
"
HTTP_REFERER
"
))
if
add_result
:
return
handle_add_page_selection
(
pages
=
pages
,
add_result
=
add_result
)
if
edit_result
:
return
handle_edit_page_selection
(
pages
=
pages
,
edit_result
=
edit_result
)
return
pages
def
handle_add_page_selection
(
pages
,
add_result
):
parent_page_id
=
add_result
.
group
(
1
)
if
parent_page_id
==
1
:
# pro novou homepage žádné podstránky nejsou
return
pages
.
none
()
parent_page
=
pages
.
model
.
objects
.
get
(
id
=
parent_page_id
)
root_page
=
getattr
(
parent_page
.
specific
,
"
root_page
"
,
None
)
return
get_only_root_page_descendants
(
pages
=
pages
,
root_page
=
root_page
)
def
handle_edit_page_selection
(
pages
,
edit_result
):
current_page_id
=
edit_result
.
group
(
1
)
current_page
=
pages
.
model
.
objects
.
get
(
id
=
current_page_id
)
root_page
=
getattr
(
current_page
.
specific
,
"
root_page
"
,
None
)
return
get_only_root_page_descendants
(
pages
=
pages
,
root_page
=
root_page
)
def
get_only_root_page_descendants
(
pages
,
root_page
):
if
not
root_page
:
return
pages
web_pages_id_list
=
root_page
.
get_descendants
().
live
().
values_list
(
"
id
"
,
flat
=
True
)
return
pages
.
filter
(
id__in
=
web_pages_id_list
)
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
register
or
sign in
to comment