0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-28 08:48:04 +01:00

Refactor out a BoundCommentPanel class

This commit is contained in:
Matt Westcott 2022-03-22 19:14:46 +00:00 committed by Matt Westcott
parent 0bfe36cf90
commit d660333789

View File

@ -1116,28 +1116,9 @@ class PrivacyModalPanel(Panel):
)
class CommentPanel(Panel):
def get_form_options(self):
# add the comments formset
return {
# Adds the comment notifications field to the form.
# Note, this field is defined directly on WagtailAdminPageForm.
"fields": ["comment_notifications"],
"formsets": {
COMMENTS_RELATION_NAME: {
"form": CommentForm,
"fields": ["text", "contentpath", "position"],
"formset_name": "comments",
"inherit_kwargs": ["for_user"],
}
},
}
template = "wagtailadmin/panels/comments/comment_panel.html"
declarations_template = "wagtailadmin/panels/comments/comment_declarations.html"
class BoundCommentPanel(BoundPanel):
def html_declarations(self):
return render_to_string(self.declarations_template)
return render_to_string(self.panel.declarations_template)
def get_context(self):
def user_data(user):
@ -1188,10 +1169,36 @@ class CommentPanel(Panel):
}
def render(self):
panel = render_to_string(self.template, self.get_context())
panel = render_to_string(self.panel.template, self.get_context())
return panel
class CommentPanel(Panel):
def get_form_options(self):
# add the comments formset
return {
# Adds the comment notifications field to the form.
# Note, this field is defined directly on WagtailAdminPageForm.
"fields": ["comment_notifications"],
"formsets": {
COMMENTS_RELATION_NAME: {
"form": CommentForm,
"fields": ["text", "contentpath", "position"],
"formset_name": "comments",
"inherit_kwargs": ["for_user"],
}
},
}
template = "wagtailadmin/panels/comments/comment_panel.html"
declarations_template = "wagtailadmin/panels/comments/comment_declarations.html"
def get_bound_panel(self, instance=None, request=None, form=None):
return BoundCommentPanel(
panel=self, instance=instance, request=request, form=form
)
# Now that we've defined panels, we can set up wagtailcore.Page to have some.
def set_default_page_edit_handlers(cls):
cls.content_panels = [