Skip to content

Commit

Permalink
Merge pull request #187 from collective/vocabulary-lookup-fix
Browse files Browse the repository at this point in the history
Vocabulary lookup fix in `++add++` forms
  • Loading branch information
petschki authored May 13, 2024
2 parents b1b3503 + 6b20c21 commit 8ac53a6
Show file tree
Hide file tree
Showing 25 changed files with 408 additions and 27 deletions.
6 changes: 4 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
root = true


[*] # For All Files
[*]
# Default settings for all files.
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
Expand All @@ -33,7 +34,8 @@ indent_size = 4
# 2 space indentation
indent_size = 2

[*.{json,jsonl,js,jsx,ts,tsx,css,less,scss}] # Frontend development
[*.{json,jsonl,js,jsx,ts,tsx,css,less,scss}]
# Frontend development
# 2 space indentation
indent_size = 2
max_line_length = 80
Expand Down
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See the inline comments on how to expand/tweak this configuration file
[meta]
template = "default"
commit-id = "5d3e918e"
commit-id = "5d669ee9"

[pyproject]
codespell_skip = "*.js,*.min.js,*.min.js.map,*.css.map,yarn.lock,robot_*,test_*"
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -16,7 +16,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/collective/zpretty
Expand All @@ -32,7 +32,7 @@ repos:
# """
##
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8

Expand Down Expand Up @@ -71,7 +71,7 @@ repos:
- id: check-python-versions
args: ['--only', 'setup.py,pyproject.toml']
- repo: https://github.com/collective/i18ndude
rev: "6.1.0"
rev: "6.2.0"
hooks:
- id: i18ndude

Expand Down
17 changes: 5 additions & 12 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
Changelog
=========

3.0.3 (unreleased)
------------------

- For the JSON deserializer, skip empty values from non-required fields.
This fixes a problem where empty non-required fields would break deserialization.
[thet]
.. You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst
- configure with `plone/meta`.
[petschki]

- fix the DictRowConverter when the field schema changes fields and no value
for the new column field is available yet.
[petschki]
.. towncrier release notes start
3.0.2 (2023-09-11)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ exclude constraints-mxdev.txt
exclude requirements-mxdev.txt
global-exclude *.pyc
global-exclude *.pyo
recursive-exclude news *
11 changes: 11 additions & 0 deletions dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generated from:
# https://github.com/plone/meta/tree/main/config/default
# See the inline comments on how to expand/tweak this configuration file
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
Empty file added news/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions news/0.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fix the DictRowConverter when the field schema changes fields and no value
for the new column field is available yet.
[petschki]
2 changes: 2 additions & 0 deletions news/0.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configure with `plone/meta`.
[petschki]
3 changes: 3 additions & 0 deletions news/184.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
For the JSON deserializer, skip empty values from non-required fields.
This fixes a problem where empty non-required fields would break deserialization.
[thet]
3 changes: 3 additions & 0 deletions news/187.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix bug in vocabulary lookup on `++add++` forms. Override `IFieldPermissionChecker`
the same as for `IDexterityContent`.
[petschki]
47 changes: 45 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@
[build-system]
requires = ["setuptools>=68.2"]

[tool.towncrier]
directory = "news/"
filename = "CHANGES.rst"
title_format = "{version} ({project_date})"
underlines = ["-", ""]

[[tool.towncrier.type]]
directory = "breaking"
name = "Breaking changes:"
showcontent = true

[[tool.towncrier.type]]
directory = "feature"
name = "New features:"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bug fixes:"
showcontent = true

[[tool.towncrier.type]]
directory = "internal"
name = "Internal:"
showcontent = true

[[tool.towncrier.type]]
directory = "documentation"
name = "Documentation:"
showcontent = true

[[tool.towncrier.type]]
directory = "tests"
name = "Tests"
showcontent = true

##
# Add extra configuration options in .meta.toml:
# [pyproject]
Expand Down Expand Up @@ -97,20 +133,27 @@ python-dateutil = ['dateutil']
[tool.check-manifest]
ignore = [
".editorconfig",
".flake8",
".meta.toml",
".pre-commit-config.yaml",
"tox.ini",
".flake8",
"dependabot.yml",
"mx.ini",
"tox.ini",

]

##
# Add extra configuration options in .meta.toml:
# [pyproject]
# check_manifest_ignores = """
# "*.map.js",
# "*.pyc",
# """
# check_manifest_extra_lines = """
# ignore-bad-ideas = [
# "some/test/file/PKG-INFO",
# ]
# """
##


Expand Down
14 changes: 12 additions & 2 deletions src/collective/z3cform/datagridfield/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:z3c="http://namespaces.zope.org/z3c"
xmlns:zcml="http://namespaces.zope.org/zcml"
Expand All @@ -9,11 +10,20 @@

<i18n:registerTranslations directory="locales" />

<include package="plone.app.z3cform" />
<include package="plone.app.dexterity" />

<include
package="z3c.form"
file="meta.zcml"
/>
<include package=".demo" />


<!-- NOTE: demo package is only installed in tests. If you want to use it
include this line somewhere in your integration package:
<include package="collective.z3cform.datagridfield.demo" />
-->

<include file="profiles.zcml" />
<include package=".upgrades" />

Expand Down Expand Up @@ -77,7 +87,7 @@

<configure zcml:condition="installed plone.supermodel">
<utility
name="collective.z3cform.datagridfield.DictRow"
name="collective.z3cform.datagridfield.row.DictRow"
component=".supermodel.DictRowHandler"
/>
</configure>
Expand Down
60 changes: 60 additions & 0 deletions src/collective/z3cform/datagridfield/demo/behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from collective.z3cform.datagridfield.datagridfield import DataGridFieldWidgetFactory
from collective.z3cform.datagridfield.row import DictRow
from plone.app.z3cform.widgets.select import AjaxSelectFieldWidget
from plone.autoform import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.namedfile import field as namedfile
from plone.supermodel import model
from z3c.relationfield.schema import RelationChoice
from z3c.relationfield.schema import RelationList
from zope import schema
from zope.interface import Interface
from zope.interface import provider
from zope.schema.vocabulary import SimpleVocabulary


class ITableRow(Interface):
col1 = schema.TextLine(title="Column1")
col2 = schema.Choice(
vocabulary=SimpleVocabulary.fromValues(["yes", "no"]), required=False
)
links = RelationList(
title="Related Links",
value_type=RelationChoice(
vocabulary="plone.app.vocabularies.Catalog",
),
required=False,
)

tags = schema.Tuple(
title="Tags",
value_type=schema.TextLine(),
required=False,
)

directives.widget(
"tags",
AjaxSelectFieldWidget,
vocabulary="plone.app.vocabularies.Keywords",
)

image = namedfile.NamedBlobImage(
title="Image",
required=False,
)


@provider(IFormFieldProvider)
class IDatagridfieldMetadata(model.Schema):

tabular_field = schema.List(
title="datagridfield",
value_type=DictRow(schema=ITableRow),
required=False,
)
directives.widget(
"tabular_field",
DataGridFieldWidgetFactory,
auto_append=True,
allow_reorder=True,
)
17 changes: 17 additions & 0 deletions src/collective/z3cform/datagridfield/demo/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:plone="http://namespaces.plone.org/plone"
>
<browser:page
name="demo-collective.z3cform.datagrid-menu"
Expand Down Expand Up @@ -148,4 +150,19 @@
permission="zope2.View"
layer="collective.z3cform.datagridfield.interfaces.IDataGridFieldLayer"
/>

<genericsetup:registerProfile
name="demo"
title="Data Grid Field demo setup"
description=""
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profile"
/>

<plone:behavior
name="datagridfield.behavior"
title="Datagridfield Metadata"
provides=".behavior.IDatagridfieldMetadata"
/>

</configure>
33 changes: 33 additions & 0 deletions src/collective/z3cform/datagridfield/demo/content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# from collective.z3cform.datagridfield.datagridfield import DataGridFieldWidgetFactory
# from collective.z3cform.datagridfield.demo.interfaces import ITableRow
# from collective.z3cform.datagridfield.row import DictRow
# from plone import schema
# from plone.autoform import directives
from plone.dexterity.content import Item
from plone.supermodel import model
from zope.interface import implementer


class IDGFTest(model.Schema):
"""Marker interface and Dexterity Python Schema for DGFTest"""

# You can define the fields in the schema interface directly or load an XML
# file ... see below
# tabular_field = schema.List(
# title="datagridfield",
# value_type=DictRow(schema=ITableRow),
# required=False,
# )
# directives.widget(
# "tabular_field",
# DataGridFieldWidgetFactory,
# auto_append=True,
# allow_reorder=True,
# )

model.load("dgftest.xml")


@implementer(IDGFTest)
class DGFTest(Item):
"""Content-type class for IDGFTest"""
20 changes: 20 additions & 0 deletions src/collective/z3cform/datagridfield/demo/dgftest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<model xmlns="http://namespaces.plone.org/supermodel/schema"
xmlns:form="http://namespaces.plone.org/supermodel/form"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:security="http://namespaces.plone.org/supermodel/security"
i18n:domain="collective.z3cform.datagridfield"
>
<schema>
<field form:widget="collective.z3cform.datagridfield.datagridfield.DataGridFieldWidgetFactory"
name="table"
type="zope.schema.List"
>
<title>Tabular Field</title>
<description />
<value_type type="collective.z3cform.datagridfield.row.DictRow">
<schema>collective.z3cform.datagridfield.demo.interfaces.ITableRow</schema>
</value_type>
</field>
</schema>
</model>
Loading

0 comments on commit 8ac53a6

Please sign in to comment.