find -name "*.py" -exec pyupgrade --py3-only --py37-plus {} +

This commit is contained in:
Jens W. Klein
2022-05-01 23:14:41 +02:00
parent 34b758f2bd
commit 75c6a5dcc1
38 changed files with 315 additions and 361 deletions
+1 -2
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Captcha validator, see captcha.txt for design notes.
from persistent import Persistent
from plone.app.discussion.browser.comments import CommentForm
@@ -23,7 +22,7 @@ from zope.publisher.interfaces.browser import IDefaultBrowserLayer
class Captcha(Persistent):
"""Captcha input field."""
captcha = u""
captcha = ""
Captcha = factory(Captcha)
+9 -10
View File
@@ -1,4 +1,3 @@
# coding: utf-8
from .comments import CommentForm
from AccessControl import getSecurityManager
from Acquisition import aq_inner
@@ -48,9 +47,9 @@ class View(BrowserView):
will redirect right to the binary object, bypassing comments.
"""
if obj.portal_type in view_action_types:
url = "{0}/view".format(url)
url = f"{url}/view"
self.request.response.redirect("{0}#{1}".format(url, context.id))
self.request.response.redirect(f"{url}#{context.id}")
class EditCommentForm(CommentForm):
@@ -58,10 +57,10 @@ class EditCommentForm(CommentForm):
ignoreContext = True
id = "edit-comment-form"
label = _(u"edit_comment_form_title", default=u"Edit comment")
label = _("edit_comment_form_title", default="Edit comment")
def updateWidgets(self):
super(EditCommentForm, self).updateWidgets()
super().updateWidgets()
self.widgets["text"].value = self.context.text
# We have to rename the id, otherwise TinyMCE can't initialize
# because there are two textareas with the same id.
@@ -70,12 +69,12 @@ class EditCommentForm(CommentForm):
def _redirect(self, target=""):
if not target:
portal_state = getMultiAdapter(
(self.context, self.request), name=u"plone_portal_state"
(self.context, self.request), name="plone_portal_state"
)
target = portal_state.portal_url()
self.request.response.redirect(target)
@button.buttonAndHandler(_(u"label_save", default=u"Save"), name="comment")
@button.buttonAndHandler(_("label_save", default="Save"), name="comment")
def handleComment(self, action):
# Validate form
@@ -96,14 +95,14 @@ class EditCommentForm(CommentForm):
# Redirect to comment
IStatusMessage(self.request).add(
_(u"comment_edit_notification", default="Comment was edited"), type="info"
_("comment_edit_notification", default="Comment was edited"), type="info"
)
return self._redirect(target=self.action.replace("@@edit-comment", "@@view"))
@button.buttonAndHandler(_(u"cancel_form_button", default=u"Cancel"), name="cancel")
@button.buttonAndHandler(_("cancel_form_button", default="Cancel"), name="cancel")
def handle_cancel(self, action):
IStatusMessage(self.request).add(
_(u"comment_edit_cancel_notification", default=u"Edit comment cancelled"),
_("comment_edit_cancel_notification", default="Edit comment cancelled"),
type="info",
)
return self._redirect(target=self.context.absolute_url())
+28 -31
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl import getSecurityManager
from AccessControl import Unauthorized
from Acquisition import aq_inner
@@ -35,28 +34,28 @@ from zope.interface import alsoProvides
COMMENT_DESCRIPTION_PLAIN_TEXT = _(
u"comment_description_plain_text",
default=u"You can add a comment by filling out the form below. "
u"Plain text formatting.",
"comment_description_plain_text",
default="You can add a comment by filling out the form below. "
"Plain text formatting.",
)
COMMENT_DESCRIPTION_MARKDOWN = _(
u"comment_description_markdown",
default=u"You can add a comment by filling out the form below. "
u"Plain text formatting. You can use the Markdown syntax for "
u"links and images.",
"comment_description_markdown",
default="You can add a comment by filling out the form below. "
"Plain text formatting. You can use the Markdown syntax for "
"links and images.",
)
COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _(
u"comment_description_intelligent_text",
default=u"You can add a comment by filling out the form below. "
u"Plain text formatting. Web and email addresses are "
u"transformed into clickable links.",
"comment_description_intelligent_text",
default="You can add a comment by filling out the form below. "
"Plain text formatting. Web and email addresses are "
"transformed into clickable links.",
)
COMMENT_DESCRIPTION_MODERATION_ENABLED = _(
u"comment_description_moderation_enabled",
default=u"Comments are moderated.",
"comment_description_moderation_enabled",
default="Comments are moderated.",
)
@@ -64,7 +63,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
ignoreContext = True # don't use context to get widget data
id = None
label = _(u"Add a comment")
label = _("Add a comment")
fields = field.Fields(IComment).omit(
"portal_type",
"__parent__",
@@ -79,16 +78,16 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
)
def updateFields(self):
super(CommentForm, self).updateFields()
super().updateFields()
self.fields["user_notification"].widgetFactory = SingleCheckBoxFieldWidget
def updateWidgets(self):
super(CommentForm, self).updateWidgets()
super().updateWidgets()
# Widgets
self.widgets["in_reply_to"].mode = interfaces.HIDDEN_MODE
self.widgets["text"].addClass("autoresize")
self.widgets["user_notification"].label = _(u"")
self.widgets["user_notification"].label = _("")
# Reset widget field settings to their defaults, which may be changed
# further on. Otherwise, the email field might get set to required
# when an anonymous user visits, and then remain required when an
@@ -140,7 +139,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
self.widgets["user_notification"].mode = interfaces.HIDDEN_MODE
def updateActions(self):
super(CommentForm, self).updateActions()
super().updateActions()
self.actions["cancel"].addClass("btn btn-secondary")
self.actions["cancel"].addClass("hide")
self.actions["comment"].addClass("btn btn-primary")
@@ -148,7 +147,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
def get_author(self, data):
context = aq_inner(self.context)
# some attributes are not always set
author_name = u""
author_name = ""
# Make sure author_name/ author_email is properly encoded
if "author_name" in data:
@@ -219,16 +218,14 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
else: # pragma: no cover
raise Unauthorized(
u"Anonymous user tries to post a comment, but anonymous "
u"commenting is disabled. Or user does not have the "
u"'reply to item' permission.",
"Anonymous user tries to post a comment, but anonymous "
"commenting is disabled. Or user does not have the "
"'reply to item' permission.",
)
return comment
@button.buttonAndHandler(
_(u"add_comment_button", default=u"Comment"), name="comment"
)
@button.buttonAndHandler(_("add_comment_button", default="Comment"), name="comment")
def handleComment(self, action):
context = aq_inner(self.context)
@@ -254,7 +251,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
anon = portal_membership.isAnonymousUser()
if captcha_enabled and anonymous_comments and anon:
if "captcha" not in data:
data["captcha"] = u""
data["captcha"] = ""
captcha = CaptchaValidator(
self.context, self.request, None, ICaptcha["captcha"], None
)
@@ -296,7 +293,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Redirect to comment (inside a content object page)
self.request.response.redirect(self.action + "#" + str(comment_id))
@button.buttonAndHandler(_(u"Cancel"))
@button.buttonAndHandler(_("Cancel"))
def handleCancel(self, action):
# This method should never be called, it's only there to show
# a cancel button that is handled by a jQuery method.
@@ -309,7 +306,7 @@ class CommentsViewlet(ViewletBase):
index = ViewPageTemplateFile("comments.pt")
def update(self):
super(CommentsViewlet, self).update()
super().update()
discussion_allowed = self.is_discussion_allowed()
anonymous_allowed_or_can_reply = (
self.is_anonymous()
@@ -483,7 +480,7 @@ class CommentsViewlet(ViewletBase):
if username is None:
return None
else:
return "{0}/author/{1}".format(self.context.portal_url(), username)
return f"{self.context.portal_url()}/author/{username}"
def get_commenter_portrait(self, username=None):
@@ -523,7 +520,7 @@ class CommentsViewlet(ViewletBase):
return portal_membership.isAnonymousUser()
def login_action(self):
return "{0}/login_form?came_from={1}".format(
return "{}/login_form?came_from={}".format(
self.navigation_root_url,
quote(self.request.get("URL", "")),
)
+27 -28
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.discussion.interfaces import _
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.discussion.upgrades import update_registry
@@ -32,22 +31,22 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
schema = IDiscussionSettings
id = "DiscussionSettingsEditForm"
label = _(u"Discussion settings")
label = _("Discussion settings")
description = _(
u"help_discussion_settings_editform",
default=u"Some discussion related settings are not "
u"located in the Discussion Control Panel.\n"
u"To enable comments for a specific content type, "
u"go to the Types Control Panel of this type and "
u'choose "Allow comments".\n'
u"To enable the moderation workflow for comments, "
u"go to the Types Control Panel, choose "
u'"Comment" and set workflow to '
u'"Comment Review Workflow".',
"help_discussion_settings_editform",
default="Some discussion related settings are not "
"located in the Discussion Control Panel.\n"
"To enable comments for a specific content type, "
"go to the Types Control Panel of this type and "
'choose "Allow comments".\n'
"To enable the moderation workflow for comments, "
"go to the Types Control Panel, choose "
'"Comment" and set workflow to '
'"Comment Review Workflow".',
)
def updateFields(self):
super(DiscussionSettingsEditForm, self).updateFields()
super().updateFields()
self.fields["globally_enabled"].widgetFactory = SingleCheckBoxFieldWidget
self.fields["moderation_enabled"].widgetFactory = SingleCheckBoxFieldWidget
self.fields["edit_comment_enabled"].widgetFactory = SingleCheckBoxFieldWidget
@@ -65,20 +64,20 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
def updateWidgets(self):
try:
super(DiscussionSettingsEditForm, self).updateWidgets()
super().updateWidgets()
except KeyError:
# upgrade profile not visible in prefs_install_products_form
# provide auto-upgrade
update_registry(self.context)
super(DiscussionSettingsEditForm, self).updateWidgets()
self.widgets["globally_enabled"].label = _(u"Enable Comments")
self.widgets["anonymous_comments"].label = _(u"Anonymous Comments")
self.widgets["show_commenter_image"].label = _(u"Commenter Image")
super().updateWidgets()
self.widgets["globally_enabled"].label = _("Enable Comments")
self.widgets["anonymous_comments"].label = _("Anonymous Comments")
self.widgets["show_commenter_image"].label = _("Commenter Image")
self.widgets["moderator_notification_enabled"].label = _(
u"Moderator Email Notification",
"Moderator Email Notification",
)
self.widgets["user_notification_enabled"].label = _(
u"User Email Notification",
"User Email Notification",
)
@button.buttonAndHandler(_("Save"), name=None)
@@ -88,14 +87,14 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
self.status = self.formErrorsMessage
return
self.applyChanges(data)
IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"), "info")
IStatusMessage(self.request).addStatusMessage(_("Changes saved"), "info")
self.context.REQUEST.RESPONSE.redirect("@@discussion-controlpanel")
@button.buttonAndHandler(_("Cancel"), name="cancel")
def handleCancel(self, action):
IStatusMessage(self.request).addStatusMessage(_(u"Edit cancelled"), "info")
IStatusMessage(self.request).addStatusMessage(_("Edit cancelled"), "info")
self.request.response.redirect(
"{0}/{1}".format(
"{}/{}".format(
self.context.absolute_url(),
self.control_panel_view,
),
@@ -111,7 +110,7 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
def __call__(self):
self.mailhost_warning()
self.custom_comment_workflow_warning()
return super(DiscussionSettingsControlPanel, self).__call__()
return super().__call__()
@property
def site_url(self):
@@ -180,8 +179,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
pass
else:
message = _(
u"discussion_text_no_mailhost_configured",
default=u"You have not configured a mail host or a site 'From' address, various features including contact forms, email notification and password reset will not work. Go to the E-Mail Settings to fix this.",
"discussion_text_no_mailhost_configured",
default="You have not configured a mail host or a site 'From' address, various features including contact forms, email notification and password reset will not work. Go to the E-Mail Settings to fix this.",
) # noqa: E501
IStatusMessage(self.request).addStatusMessage(message, "warning")
@@ -195,8 +194,8 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
pass
else:
message = _(
u"discussion_text_custom_comment_workflow",
default=u"You have configured a custom workflow for the 'Discussion Item' content type. You can enable/disable the comment moderation in this control panel only if you use one of the default 'Discussion Item' workflows. Go to the Types control panel to choose a workflow for the 'Discussion Item' type.",
"discussion_text_custom_comment_workflow",
default="You have configured a custom workflow for the 'Discussion Item' content type. You can enable/disable the comment moderation in this control panel only if you use one of the default 'Discussion Item' workflows. Go to the Types control panel to choose a workflow for the 'Discussion Item' type.",
) # noqa: E501
IStatusMessage(self.request).addStatusMessage(message, "warning")
+1 -2
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base
from Acquisition import aq_chain
from Acquisition import aq_inner
@@ -34,7 +33,7 @@ def traverse_parents(context):
return None
class ConversationView(object):
class ConversationView:
def enabled(self):
if DEXTERITY_INSTALLED and IDexterityContent.providedBy(self.context):
return self._enabled_for_dexterity_types()
+3 -4
View File
@@ -1,4 +1,3 @@
# coding: utf-8
from AccessControl import getSecurityManager
from AccessControl import Unauthorized
from Acquisition import aq_inner
@@ -51,7 +50,7 @@ class View(BrowserView):
pass
def __init__(self, context, request):
super(View, self).__init__(context, request)
super().__init__(context, request)
self.workflowTool = getToolByName(self.context, "portal_workflow")
self.transitions = []
@@ -229,7 +228,7 @@ class DeleteOwnComment(DeleteComment):
def __call__(self):
if self.can_delete():
super(DeleteOwnComment, self).__call__()
super().__call__()
else:
raise Unauthorized("You're not allowed to delete this comment.")
@@ -318,7 +317,7 @@ class BulkActionsView(BrowserView):
"""
def __init__(self, context, request):
super(BulkActionsView, self).__init__(context, request)
super().__init__(context, request)
self.workflowTool = getToolByName(context, "portal_workflow")
def __call__(self):
+2 -3
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Implement the ++comments++ traversal namespace. This should return the
IDiscussion container for the context, from which traversal will continue
into an actual comment object.
@@ -15,7 +14,7 @@ from zope.traversing.interfaces import TraversalError
@implementer(ITraversable)
@adapter(Interface, IBrowserRequest)
class ConversationNamespace(object):
class ConversationNamespace:
"""Allow traversal into a conversation via a ++conversation++name
namespace. The name is the name of an adapter from context to
IConversation. The special name 'default' will be taken as the default
@@ -30,7 +29,7 @@ class ConversationNamespace(object):
def traverse(self, name, ignore):
if name == "default":
name = u""
name = ""
conversation = queryAdapter(self.context, IConversation, name=name)
if conversation is None:
+1 -2
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Captcha validator, see captcha.txt for design notes.
"""
from Acquisition import aq_inner
@@ -39,7 +38,7 @@ class CaptchaValidator(validator.SimpleFieldValidator):
# We adapt the CaptchaValidator class to all form fields (IField)
def validate(self, value):
super(CaptchaValidator, self).validate(value)
super().validate(value)
registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False)