Skip to content

Commit

Permalink
chore: black
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Mar 17, 2023
1 parent d489486 commit d0b802c
Show file tree
Hide file tree
Showing 17 changed files with 450 additions and 469 deletions.
7 changes: 1 addition & 6 deletions plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
__import__("pkg_resources").declare_namespace(__name__)
7 changes: 1 addition & 6 deletions plone/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
__import__("pkg_resources").declare_namespace(__name__)
12 changes: 6 additions & 6 deletions plone/app/versioningbehavior/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from zope.i18nmessageid import MessageFactory


_ = MessageFactory('plone')
_ = MessageFactory("plone")


def initialize(context):
"""Registers modifiers with zope (on zope startup).
"""
"""Registers modifiers with zope (on zope startup)."""
if HAVE_BLOBS:
from .modifiers import modifiers

for m in modifiers:
context.registerClass(
m['wrapper'], m['id'],
m["wrapper"],
m["id"],
permission=ManagePortal,
constructors=(m['form'], m['factory']),
icon=m['icon'],
constructors=(m["form"], m["factory"]),
icon=m["icon"],
)
51 changes: 27 additions & 24 deletions plone/app/versioningbehavior/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,38 @@


class IVersionable(model.Schema):
""" Behavior for enabling CMFEditions's versioning for dexterity
"""Behavior for enabling CMFEditions's versioning for dexterity
content types. Be shure to enable versioning in the plone types
control-panel for your content type.
"""

model.fieldset(
'settings',
label=_('Settings'),
fields=['versioning_enabled']
)
model.fieldset("settings", label=_("Settings"), fields=["versioning_enabled"])
changeNote = schema.TextLine(
title=_('label_change_note', default='Change Note'),
description=_('help_change_note',
default='Enter a comment that describes the changes you made. '
'If versioning is manual, you must set a change note '
'to create the new version.'),
required=False)
title=_("label_change_note", default="Change Note"),
description=_(
"help_change_note",
default="Enter a comment that describes the changes you made. "
"If versioning is manual, you must set a change note "
"to create the new version.",
),
required=False,
)

versioning_enabled = schema.Bool(
title=_('label_versioning_enabled', default='Versioning enabled'),
description=_('help_versioning_enabled',
default='Enable/disable versioning for this document.'),
title=_("label_versioning_enabled", default="Versioning enabled"),
description=_(
"help_versioning_enabled",
default="Enable/disable versioning for this document.",
),
default=True,
required=False)
required=False,
)

form.order_after(changeNote="*")
form.omitted("changeNote")
form.no_omit(IEditForm, "changeNote")
form.no_omit(IAddForm, "changeNote")

form.order_after(changeNote='*')
form.omitted('changeNote')
form.no_omit(IEditForm, 'changeNote')
form.no_omit(IAddForm, 'changeNote')

alsoProvides(IVersionable, IFormFieldProvider)

Expand All @@ -56,7 +59,7 @@ class IVersioningSupport(Interface):
@implementer(IVersionable)
@adapter(IDexterityContent)
class Versionable:
""" The Versionable adapter prohibits dexterity from saving the changeNote
"""The Versionable adapter prohibits dexterity from saving the changeNote
on the context. It stores it in a request-annotation for later use in
event-handlers
Expand All @@ -68,18 +71,18 @@ def __init__(self, context):

@property
def changeNote(self):
return ''
return ""

@changeNote.setter
def changeNote(self, value):
# store the value for later use (see events.py)
annotation = IAnnotations(self.context.REQUEST)
annotation['plone.app.versioningbehavior-changeNote'] = value
annotation["plone.app.versioningbehavior-changeNote"] = value

@property
def versioning_enabled(self):
return self.context.versioning_enabled

@versioning_enabled.setter
def versioning_enabled(self, value):
setattr(self.context, 'versioning_enabled', value)
setattr(self.context, "versioning_enabled", value)
44 changes: 23 additions & 21 deletions plone/app/versioningbehavior/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ def __init__(self, context, request):
# Example: ++widget++form.widgets.my_interface.my_field/@@download/my_file.txt
# Example: view-name/++widget++form.widgets.my_field/@@download/my_file.txt
(
r'([@a-zA-Z0-9_-]+/)?'
r'\+\+widget\+\+form\.widgets\.([a-zA-Z0-9_-]+\.)?(?P<field_id>[a-zA-Z0-9_-]+)'
r"([@a-zA-Z0-9_-]+/)?"
r"\+\+widget\+\+form\.widgets\.([a-zA-Z0-9_-]+\.)?(?P<field_id>[a-zA-Z0-9_-]+)"
r'/@@download/(?P<filename>[^"\']+)'
),

# Example: @@download/my_field/my_file.txt
r'@@download/(?P<field_id>[a-zA-Z0-9_-]+)/(?P<filename>[^"\']+)',

# Example: @@images/aedf-0123.png
r'@@images/[0-9a-f\-]+\.[a-z]+',
r"@@images/[0-9a-f\-]+\.[a-z]+",
)

def __call__(self):
version_id = self.request.get('version_id', None)
version_id = self.request.get("version_id", None)
if not version_id:
raise ValueError('Missing parameter on the request: version_id')
raise ValueError("Missing parameter on the request: version_id")

content_core_view = getMultiAdapter((self.context, self.request), name='content-core')
content_core_view = getMultiAdapter(
(self.context, self.request), name="content-core"
)
html = content_core_view()
return self._convert_download_links(html, version_id)

Expand All @@ -57,28 +57,28 @@ def repl(match):
groups = match.groupdict()
return self._get_download_version_link(
version_id=version_id,
field_id=groups.get('field_id'),
filename=groups.get('filename'),
field_id=groups.get("field_id"),
filename=groups.get("filename"),
)

context_url = self.context.absolute_url()
for pattern in self._download_url_patterns:
compiled_pattern = re.compile(context_url + '/' + pattern)
compiled_pattern = re.compile(context_url + "/" + pattern)
transformed_html = compiled_pattern.sub(repl, transformed_html)

return transformed_html

def _get_download_version_link(self, version_id, field_id=None, filename=None):
parameters = [('version_id', version_id)]
parameters = [("version_id", version_id)]

if field_id:
parameters.append(('field_id', field_id))
parameters.append(("field_id", field_id))

if filename:
parameters.append(('filename', filename))
parameters.append(("filename", filename))

query_string = urlencode(parameters)
return f'{self.context.absolute_url()}/@@download-version?{query_string}'
return f"{self.context.absolute_url()}/@@download-version?{query_string}"


class DownloadVersion:
Expand All @@ -100,15 +100,17 @@ def __init__(self, context, request):
self.request = request

def __call__(self):
version_id = self.request.get('version_id', None)
version_id = self.request.get("version_id", None)
if not version_id:
raise ValueError('Missing parameter on the request: version_id')
raise ValueError("Missing parameter on the request: version_id")

field_id = self.request.get('field_id') or IPrimaryFieldInfo(self.context).fieldname
filename = self.request.get('filename')
do_not_stream = self.request.get('do_not_stream')
field_id = (
self.request.get("field_id") or IPrimaryFieldInfo(self.context).fieldname
)
filename = self.request.get("filename")
do_not_stream = self.request.get("do_not_stream")

repository = getToolByName(self.context, 'portal_repository')
repository = getToolByName(self.context, "portal_repository")
old_obj = repository.retrieve(self.context, version_id).object

# Will only work if the file is stored as an attribute with the same
Expand Down
Loading

0 comments on commit d0b802c

Please sign in to comment.