Skip to content

Commit

Permalink
Merge pull request #8 from plone/config-with-default-template-6ba59e5b
Browse files Browse the repository at this point in the history
Config with default template
  • Loading branch information
jensens authored Apr 10, 2023
2 parents 6ba59e5 + 5415692 commit 79ddf4b
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 110 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 = "3b8337e6"
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Fixes:
1.0b2 2010-02-22
-------------------

- fixed dependecy of import profiles
- fixed dependency of import profiles
[naro]

1.0b1 2010-02-07
Expand Down
2 changes: 2 additions & 0 deletions news/3b8337e6.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update configuration files.
[plone devs]
3 changes: 1 addition & 2 deletions plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
3 changes: 1 addition & 2 deletions plone/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
1 change: 0 additions & 1 deletion plone/app/intid/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
19 changes: 13 additions & 6 deletions plone/app/intid/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.app.intid">
i18n_domain="plone.app.intid"
>

<include package="five.intid" file="base.zcml" />
<include package="five.intid" file="cmfdirectoryview.zcml" />
<include
package="five.intid"
file="base.zcml"
/>
<include
package="five.intid"
file="cmfdirectoryview.zcml"
/>
<include file="profiles.zcml" />

<!-- Register intid handlers for all CMF/Plone content -->
<subscriber
handler="five.intid.intid.addIntIdSubscriber"
for="Products.CMFCore.interfaces.IDynamicType
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler="five.intid.intid.addIntIdSubscriber"
/>
<subscriber
handler="five.intid.intid.removeIntIdSubscriber"
for="Products.CMFCore.interfaces.IDynamicType
zope.lifecycleevent.interfaces.IObjectRemovedEvent"
handler="five.intid.intid.removeIntIdSubscriber"
/>
<subscriber
handler="five.intid.intid.moveIntIdSubscriber"
for="Products.CMFCore.interfaces.IDynamicType
zope.lifecycleevent.interfaces.IObjectMovedEvent"
handler="five.intid.intid.moveIntIdSubscriber"
/>

</configure>
53 changes: 28 additions & 25 deletions plone/app/intid/profiles.zcml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="plone.app.intid">
i18n_domain="plone.app.intid"
>

<genericsetup:registerProfile
name="default"
title="plone.app.intid: install utility"
directory="profiles/default"
description="Extension profile to install an intid utility in a Plone site"
for="Products.CMFCore.interfaces.ISiteRoot"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<genericsetup:registerProfile
name="default"
title="plone.app.intid: install utility"
description="Extension profile to install an intid utility in a Plone site"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFCore.interfaces.ISiteRoot"
directory="profiles/default"
/>

<genericsetup:importStep
name="import-intid-util"
title="Import IntId Utility"
description="Import intid utility."
handler=".setuphandlers.installIntIds">
<depends name="toolset"/>
</genericsetup:importStep>
<genericsetup:importStep
name="import-intid-util"
title="Import IntId Utility"
description="Import intid utility."
handler=".setuphandlers.installIntIds"
>
<depends name="toolset" />
</genericsetup:importStep>

<genericsetup:importStep
name="intid-register-content"
title="Register content with IntId utility"
description="Register all plone content with intid utility."
handler=".setuphandlers.registerContent">
<depends name="catalog"/>
<depends name="import-intid-util"/>
</genericsetup:importStep>
<genericsetup:importStep
name="intid-register-content"
title="Register content with IntId utility"
description="Register all plone content with intid utility."
handler=".setuphandlers.registerContent"
>
<depends name="catalog" />
<depends name="import-intid-util" />
</genericsetup:importStep>

</configure>
</configure>
2 changes: 1 addition & 1 deletion plone/app/intid/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>1</version>
</metadata>
36 changes: 11 additions & 25 deletions plone/app/intid/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from five.intid.intid import IntIds
from five.intid.site import addUtility
from Products.CMFCore.interfaces import IContentish
Expand All @@ -12,34 +11,20 @@
logger = logging.getLogger(__name__)


try:
# XXX here we must consider plone.app.multilingual as well!
import Products.LinguaPlone
Products.LinguaPlone
HAS_LINGUAPLONE = True
except ImportError:
HAS_LINGUAPLONE = False


def register_all_content_for_intids(portal):
"""Registers all existing content with the intid utility.
This will not be fast."""
cat = getToolByName(portal, 'portal_catalog', None)
cat = getToolByName(portal, "portal_catalog", None)
if cat is None:
return
intids = getUtility(IIntIds)
# Take advantage of paths stored in keyreferences in five.intid to optimize
# registration
registered_paths = {
ref.path for ref in intids.ids
if hasattr(ref, 'path')
}
registered_paths = {ref.path for ref in intids.ids if hasattr(ref, "path")}
# Count how many objects we register
registered = 0
existing = 0
query = {'object_provides': IContentish.__identifier__}
if HAS_LINGUAPLONE:
query['Language'] = 'all'
query = {"object_provides": IContentish.__identifier__}
for brain in cat(query):
if brain.getPath() in registered_paths:
existing += 1
Expand All @@ -56,22 +41,23 @@ def register_all_content_for_intids(portal):


def add_intids(context):
addUtility(context, IIntIds, IntIds, ofs_name='intids',
findroot=False)
addUtility(context, IIntIds, IntIds, ofs_name="intids", findroot=False)


def installIntIds(context):
if context.readDataFile('install_intids.txt') is None:
if context.readDataFile("install_intids.txt") is None:
return
portal = context.getSite()
add_intids(portal)
return 'Added intid utility.'
return "Added intid utility."


def registerContent(context):
if context.readDataFile('intid_register_content.txt') is None:
if context.readDataFile("intid_register_content.txt") is None:
return
portal = context.getSite()
registered, existing = register_all_content_for_intids(portal)
return ('Assigned intids to {0} content objects, {1} objects '
'already had intids.'.format(registered, existing))
return (
"Assigned intids to {} content objects, {} objects "
"already had intids.".format(registered, existing)
)
7 changes: 3 additions & 4 deletions plone/app/intid/testing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# -*- coding: utf-8 -*-
from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer


class IntidSetupFixture(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE, )
defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
# pylint: disable=W0613
import plone.app.intid

self.loadZCML(package=plone.app.intid)


SETUP_TESTING = IntegrationTesting(
bases=(IntidSetupFixture(), ),
name='IntidSetupFixture:Setup'
bases=(IntidSetupFixture(),), name="IntidSetupFixture:Setup"
)
31 changes: 15 additions & 16 deletions plone/app/intid/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.app.intid.testing import SETUP_TESTING
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
Expand All @@ -14,33 +13,33 @@ class TestSetup(unittest.TestCase):
layer = SETUP_TESTING

def setUp(self):
self.portal = self.layer['portal']
# XXX below code is only needed if theres no Folder FTI already setup.
typetool = getToolByName(self.portal, 'portal_types')
if 'Folder' not in typetool.objectIds():
self.portal = self.layer["portal"]
# XXX below code is only needed if there's no Folder FTI already setup.
typetool = getToolByName(self.portal, "portal_types")
if "Folder" not in typetool.objectIds():
# XXX Check if this is needed for Plone 5.0! In 4.3 the FTI is
# already setup
fti = DexterityFTI('Folder')
typetool._setObject('Folder', fti)
fti = DexterityFTI("Folder")
typetool._setObject("Folder", fti)

def tearDown(self):
setRoles(self.portal, TEST_USER_ID, ['Member'])
setRoles(self.portal, TEST_USER_ID, ["Member"])

def test_already_installed(self):
"""plone.app.intid is a dependency of plone.app.linkintegrity
which is a dependency of CMFPlone, so it is always installed.
This tests if this is true.
"""
# we create a folder
setRoles(self.portal, TEST_USER_ID, ['Manager'])
folder_id = self.portal.invokeFactory('Folder', 'folder')
setRoles(self.portal, TEST_USER_ID, ["Manager"])
folder_id = self.portal.invokeFactory("Folder", "folder")
folder = self.portal[folder_id]
intids = getUtility(IIntIds)
self.assertIsNotNone(intids.getId(folder))

@unittest.skip('p.a.intid is always installed')
@unittest.skip("p.a.intid is always installed")
def test_install(self):
"""When p.app.intid is intalled it registers some utility
"""When p.app.intid is installed it registers some utility
from zope.intid and five.intid and search in portal_catalog
all contents in order to register them in these utilities.
Expand All @@ -50,9 +49,9 @@ def test_install(self):
from plone.app.intid.setuphandlers import add_intids
from plone.app.testing import applyProfile

# we create a folder before the intallation of plone.app.intid
setRoles(self.portal, TEST_USER_ID, ['Manager'])
folder_id = self.portal.invokeFactory('Folder', 'folder')
# we create a folder before the installation of plone.app.intid
setRoles(self.portal, TEST_USER_ID, ["Manager"])
folder_id = self.portal.invokeFactory("Folder", "folder")
folder = self.portal[folder_id]

# now we install manually the intid utilities
Expand All @@ -63,5 +62,5 @@ def test_install(self):
self.assertRaises(KeyError, intids.getId, folder)

# when we install p.app.intid our folder is referencend by intid
applyProfile(self.portal, 'plone.app.intid:default')
applyProfile(self.portal, "plone.app.intid:default")
self.assertIsNotNone(intids.getId(folder))
Loading

0 comments on commit 79ddf4b

Please sign in to comment.