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
96741f69
Commit
96741f69
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Update the edit handlers for 2.0
parent
4af8a33b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentech/apply/funds/edit_handlers.py
+13
-58
13 additions, 58 deletions
opentech/apply/funds/edit_handlers.py
with
13 additions
and
58 deletions
opentech/apply/funds/edit_handlers.py
+
13
−
58
View file @
96741f69
...
...
@@ -5,7 +5,7 @@ from django.template.loader import render_to_string
from
django.utils.translation
import
ugettext_lazy
as
_
from
wagtail.core.models
import
Page
from
wagtail.admin.edit_handlers
import
BaseFieldPanel
,
EditHandler
,
FieldPanel
from
wagtail.admin.edit_handlers
import
EditHandler
,
FieldPanel
def
reverse_edit
(
obj
):
...
...
@@ -39,10 +39,15 @@ class DisplayField(Field):
widget
=
ReadonlyWidget
class
Base
ReadOnlyPanel
(
EditHandler
):
class
ReadOnlyPanel
(
EditHandler
):
template
=
'
wagtailadmin/edit_handlers/single_field_panel.html
'
field_template
=
'
wagtailadmin/shared/field.html
'
def
__init__
(
self
,
attr
,
**
kwargs
):
self
.
attr
=
attr
super
().
__init__
(
**
kwargs
)
self
.
heading
=
pretty_name
(
self
.
attr
)
if
self
.
heading
is
None
else
self
.
heading
def
context
(
self
):
try
:
value
=
getattr
(
self
.
instance
,
self
.
attr
)
...
...
@@ -68,53 +73,12 @@ class BaseReadOnlyPanel(EditHandler):
return
render_to_string
(
self
.
field_template
,
self
.
context
())
class
ReadOnlyPanel
:
def
__init__
(
self
,
attr
,
heading
=
None
,
classname
=
''
):
self
.
attr
=
attr
self
.
heading
=
pretty_name
(
self
.
attr
)
if
heading
is
None
else
heading
self
.
classname
=
classname
def
bind_to_model
(
self
,
model
):
kwargs
=
{
'
attr
'
:
self
.
attr
,
'
heading
'
:
self
.
heading
,
'
classname
'
:
self
.
classname
,
}
return
type
(
str
(
_
(
'
ReadOnlyPanel
'
)),
(
BaseReadOnlyPanel
,),
kwargs
)
class
BaseReadOnlyInlinePanel
(
BaseReadOnlyPanel
):
class
ReadOnlyInlinePanel
(
ReadOnlyPanel
):
template
=
'
wagtailadmin/edit_handlers/multi_field_panel.html
'
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
def
on_model_bound
(
self
,
model
):
values
=
getattr
(
self
.
instance
,
self
.
attr
).
all
()
self
.
children
=
[
BaseReadOnlyPanel
(
value
,
form
=
self
.
form
)
for
value
in
values
]
class
ReadOnlyInlinePanel
:
def
__init__
(
self
,
attr
,
heading
=
None
,
classname
=
''
,
help_text
=
''
):
self
.
attr
=
attr
self
.
heading
=
pretty_name
(
self
.
attr
)
if
heading
is
None
else
heading
self
.
classname
=
classname
self
.
help_text
=
help_text
def
bind_to_model
(
self
,
model
):
kwargs
=
{
'
attr
'
:
self
.
attr
,
'
heading
'
:
self
.
heading
,
'
classname
'
:
self
.
classname
,
'
help_text
'
:
self
.
help_text
}
return
type
(
str
(
_
(
'
ReadOnlyPanel
'
)),
(
BaseReadOnlyInlinePanel
,),
kwargs
)
class
BaseFilteredFieldPanel
(
BaseFieldPanel
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
target_model
=
self
.
bound_field
.
field
.
queryset
.
model
self
.
bound_field
.
field
.
queryset
=
target_model
.
objects
.
filter
(
**
self
.
filter_query
)
self
.
children
=
[
ReadOnlyPanel
(
value
,
form
=
self
.
form
)
for
value
in
values
]
class
FilteredFieldPanel
(
FieldPanel
):
...
...
@@ -122,15 +86,6 @@ class FilteredFieldPanel(FieldPanel):
self
.
filter_query
=
filter_query
super
().
__init__
(
*
args
,
**
kwargs
)
def
bind_to_model
(
self
,
model
):
base
=
{
'
model
'
:
model
,
'
field_name
'
:
self
.
field_name
,
'
classname
'
:
self
.
classname
,
'
filter_query
'
:
self
.
filter_query
}
if
self
.
widget
:
base
[
'
widget
'
]
=
self
.
widget
return
type
(
str
(
'
_BaseFilteredFieldPanel
'
),
(
BaseFilteredFieldPanel
,),
base
)
def
on_model_bound
(
self
,
model
):
target_model
=
self
.
bound_field
.
field
.
queryset
.
model
self
.
bound_field
.
field
.
queryset
=
target_model
.
objects
.
filter
(
**
self
.
filter_query
)
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