Skip to content

Commit

Permalink
Merge pull request #43 from plone/config-with-default-template-d8360894
Browse files Browse the repository at this point in the history
Config with default template
  • Loading branch information
jensens authored Apr 11, 2023
2 parents d836089 + 1f67789 commit f045aff
Show file tree
Hide file tree
Showing 50 changed files with 1,249 additions and 915 deletions.
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
#
# EditorConfig Configuration file, for more details see:
# http://EditorConfig.org
# EditorConfig is a convention description, that could be interpreted
# by multiple editors to enforce common coding conventions for specific
# file types

# top-most EditorConfig file:
# Will ignore other EditorConfig files in Home directory or upper tree level.
root = true


[*] # For All Files
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# Set default charset
charset = utf-8
# Indent style default
indent_style = space
# Max Line Length - a hard line wrap, should be disabled
max_line_length = off

[*.{py,cfg,ini}]
# 4 space indentation
indent_size = 4

[*.{yml,zpt,pt,dtml,zcml}]
# 2 space indentation
indent_size = 2

[{Makefile,.gitmodules}]
# Tab indentation (no size specified, but view as 4 spaces)
indent_style = tab
indent_size = unset
tab_width = unset
5 changes: 5 additions & 0 deletions .meta.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
[meta]
template = "default"
commit-id = "3333c742"
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
ci:
autofix_prs: false
autoupdate_schedule: monthly

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/collective/zpretty
rev: 3.0.3
hooks:
- id: zpretty
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
- repo: https://github.com/regebro/pyroma
rev: "4.2"
hooks:
- id: pyroma
44 changes: 25 additions & 19 deletions Products/CMFDiffTool/BaseDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""CMFDiffTool.py
Calculate differences between content objects
Expand All @@ -20,36 +19,45 @@
@implementer(IDifference)
class BaseDiff:
"""Basic diff type"""
__allow_access_to_unprotected_subobjects__ = 1
meta_type = 'Base Diff'

def __init__(self, obj1, obj2, field, id1=None, id2=None,
field_name=None, field_label=None, schemata=None):
__allow_access_to_unprotected_subobjects__ = 1
meta_type = "Base Diff"

def __init__(
self,
obj1,
obj2,
field,
id1=None,
id2=None,
field_name=None,
field_label=None,
schemata=None,
):
self.field = field
self.oldValue = _getValue(obj1, field, field_name)
self.newValue = _getValue(obj2, field, field_name)
self.same = (self.oldValue == self.newValue)
if not id1 and safe_hasattr(obj1, 'getId'):
self.same = self.oldValue == self.newValue
if not id1 and safe_hasattr(obj1, "getId"):
id1 = obj1.getId()
if not id2 and safe_hasattr(obj2, 'getId'):
if not id2 and safe_hasattr(obj2, "getId"):
id2 = obj2.getId()
self.id1 = id1
self.id2 = id2
self.label = field_label or field
self.schemata = schemata or 'default'
self.schemata = schemata or "default"
fld1 = _getValue(obj1, field, field_name, convert_to_str=False)
fld2 = _getValue(obj2, field, field_name, convert_to_str=False)
if safe_hasattr(fld1, 'getFilename'):
if safe_hasattr(fld1, "getFilename"):
self.oldFilename = fld1.getFilename()
else:
self.oldFilename = None
if safe_hasattr(fld2, 'getFilename'):
if safe_hasattr(fld2, "getFilename"):
self.newFilename = fld2.getFilename()
else:
self.newFilename = None
if self.oldFilename is not None and self.newFilename is not None \
and self.same:
self.same = (self.oldFilename == self.newFilename)
if self.oldFilename is not None and self.newFilename is not None and self.same:
self.same = self.oldFilename == self.newFilename

def testChanges(self, ob):
"""Test the specified object to determine if the change set
Expand All @@ -61,10 +69,8 @@ def applyChanges(self, ob):
pass

def filenameTitle(self, filename):
"""Translate the filename leading text
"""
msg = _(u'Filename: ${filename}',
mapping={'filename': filename})
"""Translate the filename leading text"""
msg = _("Filename: ${filename}", mapping={"filename": filename})
return translate(msg)


Expand All @@ -77,7 +83,7 @@ def _getValue(ob, field, field_name, convert_to_str=True):
# as `subject` attribute but the schema name is `subjects`
# see plone.app.dexterity.behaviors.metadata.ICategorization and
# plone.dexterity.content.DexterityContent
if field == 'subjects':
if field == "subjects":
value = ob.Subject()
else:
value = getattr(ob, field, None)
Expand Down
19 changes: 11 additions & 8 deletions Products/CMFDiffTool/BinaryDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from os import linesep
from Products.CMFDiffTool.BaseDiff import _getValue
Expand All @@ -9,7 +8,7 @@
class BinaryDiff(FieldDiff):
"""Simple binary difference"""

meta_type = 'Binary Diff'
meta_type = "Binary Diff"
inlinediff_fmt = """
<div class="%s">
<del>%s</del>
Expand All @@ -33,8 +32,9 @@ def testChanges(self, ob):
"""
value = _getValue(ob, self.field)
if not self.same and value != self.oldValue:
raise ValueError('Conflict Error during merge',
self.field, value, self.oldValue)
raise ValueError(
"Conflict Error during merge", self.field, value, self.oldValue
)

def applyChanges(self, ob):
"""Update the specified object with the difference"""
Expand All @@ -46,13 +46,16 @@ def applyChanges(self, ob):
def inline_diff(self):
"""Simple inline diff that just checks that the filename
has changed."""
css_class = 'FilenameDiff'
css_class = "FilenameDiff"
html = []
if self.oldFilename != self.newFilename:
html.append(
self.inlinediff_fmt % (css_class,
self.filenameTitle(html_escape(self.oldFilename)),
self.filenameTitle(html_escape(self.newFilename))),
self.inlinediff_fmt
% (
css_class,
self.filenameTitle(html_escape(self.oldFilename)),
self.filenameTitle(html_escape(self.newFilename)),
),
)

if html:
Expand Down
13 changes: 5 additions & 8 deletions Products/CMFDiffTool/CMFDTHtmlDiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from AccessControl.class_init import InitializeClass
from Products.CMFDiffTool.libs import htmldiff
from Products.CMFDiffTool.TextDiff import TextDiff
Expand All @@ -11,22 +10,20 @@
class CMFDTHtmlDiff(TextDiff):
"""Text difference"""

meta_type = 'HTML Diff'
meta_type = "HTML Diff"

def inline_diff(self):
"""Return a specialized diff for HTML"""
a = '\n'.join(self._parseField(self.oldValue,
filename=self.oldFilename))
b = '\n'.join(self._parseField(self.newValue,
filename=self.newFilename))
a = "\n".join(self._parseField(self.oldValue, filename=self.oldFilename))
b = "\n".join(self._parseField(self.newValue, filename=self.newFilename))
return htmldiff.htmldiff(html_safe(a), html_safe(b))

def _parseField(self, value, filename=None):
"""Use the field's raw value if available."""
if value is None:
value = ''
value = ""
else:
value = getattr(value, 'raw', value)
value = getattr(value, "raw", value)
return TextDiff._parseField(self, value, filename)


Expand Down
Loading

0 comments on commit f045aff

Please sign in to comment.