Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
ots
hypha
Commits
d63901ca
Commit
d63901ca
authored
6 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Make the parent_page data for unique to the request
parent
99585315
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/funds/models/applications.py
+8
-14
8 additions, 14 deletions
opentech/apply/funds/models/applications.py
opentech/apply/funds/wagtail_hooks.py
+4
-2
4 additions, 2 deletions
opentech/apply/funds/wagtail_hooks.py
with
12 additions
and
16 deletions
opentech/apply/funds/models/applications.py
+
8
−
14
View file @
d63901ca
...
...
@@ -144,13 +144,6 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore
ObjectList
(
SubmittableStreamForm
.
promote_panels
,
heading
=
'
Promote
'
),
])
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
# We attached the parent page as part of the before_create_hook
if
hasattr
(
self
,
'
parent_page
'
):
self
.
workflow_name
=
self
.
parent_page
.
workflow_name
self
.
reviewers
=
self
.
parent_page
.
reviewers
.
all
()
def
get_template
(
self
,
request
,
*
args
,
**
kwargs
):
# Make sure all children use the shared template
return
'
funds/round.html
'
...
...
@@ -169,19 +162,20 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore
def
save
(
self
,
*
args
,
**
kwargs
):
is_new
=
not
self
.
id
if
is_new
and
hasattr
(
self
,
'
parent_page
'
):
# Ensure that the workflow hasn't changed
self
.
workflow_name
=
self
.
parent_page
.
workflow_name
if
is_new
:
parent_page
=
self
.
parent_page
[
self
.
__class__
][
self
.
title
]
self
.
workflow_name
=
parent_page
.
workflow_name
self
.
reviewers
=
parent_page
.
reviewers
.
all
()
super
().
save
(
*
args
,
**
kwargs
)
if
is_new
and
hasattr
(
self
,
'
parent_page
'
)
:
if
is_new
:
# Would be nice to do this using model clusters as part of the __init__
self
.
_copy_forms
(
'
forms
'
)
self
.
_copy_forms
(
'
review_forms
'
)
def
_copy_forms
(
self
,
field
):
for
form
in
getattr
(
self
.
parent
_page
,
field
).
all
():
for
form
in
getattr
(
self
.
get_
parent
().
specific
,
field
).
all
():
new_form
=
self
.
_meta
.
get_field
(
field
).
related_model
self
.
_copy_form
(
form
,
new_form
)
...
...
@@ -220,10 +214,10 @@ class RoundBase(WorkflowStreamForm, SubmittableStreamForm): # type: ignore
Q
(
end_date__gte
=
self
.
start_date
)
)
if
hasattr
(
self
,
'
parent_page
'
)
:
if
not
self
.
id
:
# Check if the create hook has added the parent page, we aren't an object yet.
# Ensures we can access related objects during the clean phase instead of save.
base_query
=
RoundBase
.
objects
.
child_of
(
self
.
parent_page
)
base_query
=
RoundBase
.
objects
.
child_of
(
self
.
parent_page
[
self
.
__class__
][
self
.
title
]
)
else
:
# don't need parent page, we are an actual object now.
base_query
=
RoundBase
.
objects
.
sibling_of
(
self
)
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/funds/wagtail_hooks.py
+
4
−
2
View file @
d63901ca
...
...
@@ -10,6 +10,8 @@ modeladmin_register(ApplyAdminGroup)
@hooks.register
(
'
before_create_page
'
)
def
before_create_page
(
request
,
parent_page
,
page_class
):
if
issubclass
(
page_class
,
RoundBase
):
page_class
.
parent_page
=
parent_page
if
issubclass
(
page_class
,
RoundBase
)
and
request
.
POST
:
if
not
hasattr
(
page_class
,
'
parent_page
'
):
page_class
.
parent_page
=
{}
page_class
.
parent_page
.
setdefault
(
page_class
,
{})[
request
.
POST
[
'
title
'
]]
=
parent_page
return
page_class
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