Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code improvements #247

Merged
merged 38 commits into from
Mar 5, 2024
Merged
Changes from 8 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cea20d6
improved tests
cekk Oct 13, 2023
3ad0dae
make package more extensible
cekk Oct 16, 2023
27ab421
Do not show fieldsets with no visible fields in @types endpoint.
cekk Oct 24, 2023
6eb94bc
lower log level
cekk Oct 25, 2023
d2e5acd
Merge branch 'main' into v2v3_test
cekk Nov 7, 2023
43e74fa
fix test
cekk Nov 7, 2023
d5abe98
Add getObjSize info in File field serializer
cekk Jan 25, 2024
f14babd
add collective.volto.enhancedlinks dependency (needed for slate integ…
cekk Jan 26, 2024
08d5bac
initial work
cekk Jan 26, 2024
d8fb433
Merge branch 'main' into add_getobjsize_info_in_serializer
cekk Jan 26, 2024
fa4cf9f
remove customizations
cekk Jan 26, 2024
8a55b80
Merge branch 'main' into add_getobjsize_info_in_serializer
mamico Jan 26, 2024
e2206dd
Add new flag in settings needed to choose to show or not auto-generat…
cekk Jan 27, 2024
9a01432
zpretty
cekk Jan 27, 2024
9dd91ea
update readme
cekk Jan 27, 2024
eb4ebc3
Merge branch 'main' into v2v3_test
cekk Jan 29, 2024
2f564e0
Merge remote-tracking branch 'origin/add_getobjsize_info_in_serialize…
cekk Jan 29, 2024
9c39869
add info also for image fields
cekk Jan 29, 2024
fae8de8
Merge branch 'add_getobjsize_info_in_serializer' of github.com:RedTur…
cekk Jan 29, 2024
d21a2a2
Merge branch 'add_getobjsize_info_in_serializer' into v2v3_test
cekk Jan 29, 2024
460bc1f
Merge branch 'v2v3_test' of github.com:RedTurtle/design.plone.content…
cekk Jan 29, 2024
6d5fbff
fix imports
cekk Jan 30, 2024
ada5678
Merge branch 'add_getobjsize_info_in_serializer' into v2v3_test
cekk Jan 30, 2024
61f9a75
Merge branch 'main' into optional_navigation
cekk Jan 31, 2024
a2bb209
Merge branch 'optional_navigation' into v2v3_test
cekk Jan 31, 2024
a3d0279
enhance Bandi serializer for enhancedlinks features
cekk Jan 31, 2024
bacbc65
Merge branch 'add_getobjsize_info_in_serializer' into v2v3_test
cekk Jan 31, 2024
a897111
Merge branch 'main' into v2v3_test
cekk Feb 7, 2024
4b6eb12
fix check
cekk Feb 7, 2024
1fe7f29
Fix in @scadenziario endpoint: return future events if afterToday cri…
cekk Feb 12, 2024
7d452df
Merge branch 'fix_scadenziario_with_afterToday_crit' into v2v3_test
cekk Feb 12, 2024
5a467c4
Merge branch 'main' into v2v3_test
cekk Feb 28, 2024
3944b7f
fix upgrade-steps
cekk Feb 28, 2024
aeabe20
removed unused logger
cekk Mar 4, 2024
d4821fd
fix tests
cekk Mar 4, 2024
92ece11
standardize subfolders creation in events
cekk Mar 4, 2024
e8087f0
update changelog
cekk Mar 4, 2024
2e08c7f
zpretty
cekk Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -9,9 +9,10 @@ Changelog

- Fixed script to update pdc with description
[eikichi18]
- Add getObjSize info in File field serializer.
- Add collective.volto.enhancedlinks dependency (needed for slate integration).
[cekk]
- Add enhancedlinks infos in File field serializer.
[cekk]


6.1.10 (2024-01-16)
-------------------
@@ -31,6 +32,83 @@ Changelog

- Do not show fieldsets with no visible fields in @types endpoint.
[cekk]
- Add UID to UOJSONSummarySerializer
[eikichi18]


6.1.8 (2023-12-22)
------------------

- Add behavior argomento to Link CT
[lucabel]
- Removed maximumSelectionSize from all fields that had it greater than 0
[pnicolli]


6.1.7 (2023-12-20)
------------------

- Improved "Check notizie" view adding a way to set "a cura di" field
[lucabel]
- Fixed label for tassonomia_evento taxonomies.
[eikichi18]


6.1.6 (2023-12-15)
------------------

- Improved "Buone pratiche" view for Event: checking both for relation with Venue and coordinates.
[daniele]


6.1.5 (2023-12-13)
------------------

- Allow reorder of data grid fields.
[pnicolli]


6.1.4 (2023-12-04)
------------------

- Fix check_persone. When there are no relation.
[mamico]


6.1.3 (2023-11-28)
------------------

- "Buone pratiche" views: fixed check on Competenze field. Excluding expired events and news.
[daniele]

6.1.2 (2023-11-27)
------------------

- Added utility views: @@check-notizie and @@download-check-notizie.
[daniele]
- Fix event for obj parent update.
[eikichi18]

- Added utility views: @@check-eventi and @@download-check-eventi.
[daniele]

- Added utility views for Venue: @@check-luoghi and @@download-check-luoghi.
[daniele]

- Added utility view for Documento: @@check-documenti and @@download-check-documenti.
[daniele]

- Added utils view for UO: @@check-uo and @@download-check-uo.
[daniele]

- Added utility views for Persona: @@check-persone and @@download-check-persone.
[daniele]

6.1.1 (2023-11-21)
------------------

- Update default summary serializer to better handle geolocation information.
[lucabel]


6.1.0 (2023-11-07)
1 change: 1 addition & 0 deletions base.cfg
Original file line number Diff line number Diff line change
@@ -143,3 +143,4 @@ design.plone.contenttypes =
#redturtle.volto = git https://github.com/RedTurtle/redturtle.volto.git pushurl=git@github.com:RedTurtle/redturtle.volto.git
#redturtle.bandi = git https://github.com/RedTurtle/redturtle.bandi.git pushurl=git@github.com:RedTurtle/redturtle.bandi.git
#plone.restapi = git https://github.com/plone/plone.restapi.git
collective.volto.enhancedlinks = git https://github.com/RegioneER/collective.volto.enhancedlinks.git pushurl=git@github.com:RegioneER/collective.volto.enhancedlinks.git branch=main
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@
"z3c.unconfigure",
"eea.api.taxonomy",
"openpyxl",
"collective.volto.enhancedlinks",
],
extras_require={
"test": [
3 changes: 2 additions & 1 deletion src/design/plone/contenttypes/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>7023</version>
<version>7030</version>
<dependencies>
<dependency>profile-redturtle.bandi:default</dependency>
<dependency>profile-collective.venue:default</dependency>
<dependency>profile-redturtle.volto:default</dependency>
<dependency>profile-eea.api.taxonomy:default</dependency>
<dependency>profile-collective.z3cform.datagridfield:default</dependency>
<dependency>profile-design.plone.contenttypes:taxonomy</dependency>
<dependency>profile-collective.volto.enhancedlinks:default</dependency>
</dependencies>
</metadata>
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
<element value="plone.locking" />
<element value="design.plone.contenttypes.behavior.multi_file" />
<element value="plone.translatable" />
<element value="volto.enhanced_links_enabled" />
</property>

<!-- View information -->
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
<adapter factory=".dxcontent.SerializeFolderToJson" />
<adapter factory=".dxcontent.SerializeToJson" />
<adapter factory=".dxfields.FileFieldViewModeSerializer" />
<adapter factory=".dxfields.ImageFieldSerializer" />
<adapter factory=".dxfields.SourceTextSerializer" />
<adapter factory=".dxfields.TempiEScadenzeValueSerializer" />
<adapter factory=".dxfields.ServizioTextLineFieldSerializer" />
35 changes: 34 additions & 1 deletion src/design/plone/contenttypes/restapi/serializers/dxfields.py
Original file line number Diff line number Diff line change
@@ -8,12 +8,16 @@
from plone.base.utils import human_readable_size
from plone.dexterity.interfaces import IDexterityContent
from plone.namedfile.interfaces import INamedFileField
from plone.namedfile.interfaces import INamedImageField
from plone.outputfilters.browser.resolveuid import uuidToURL
from plone.restapi.interfaces import IBlockFieldSerializationTransformer
from plone.restapi.interfaces import IFieldSerializer
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.serializer.dxfields import DefaultFieldSerializer
from plone.restapi.serializer.dxfields import (
ImageFieldSerializer as BaseImageFieldSerializer,
)
from zope.component import adapter
from zope.component import getMultiAdapter
from zope.component import subscribers
@@ -23,6 +27,13 @@
from zope.schema.interfaces import ISourceText
from zope.schema.interfaces import ITextLine

try:
from collective.volto.enhancedlinks.interfaces import IEnhancedLinksEnabled

HAS_ENHANCEDLINKS = True
except ImportError:
HAS_ENHANCEDLINKS = False

import json
import re

@@ -80,9 +91,16 @@ def __call__(self):
"filename": namedfile.filename,
"content-type": namedfile.contentType,
"size": size,
"getObjSize": human_readable_size(size),
"download": url,
}
if HAS_ENHANCEDLINKS:
if IEnhancedLinksEnabled.providedBy(self.context):
result.update(
{
"getObjSize": human_readable_size(size),
"enhanced_links_enabled": True,
}
)

return json_compatible(result)

@@ -95,6 +113,21 @@ def get_file_view_mode(self, content_type):
return "@@download"


@adapter(INamedImageField, IDexterityContent, IDesignPloneContenttypesLayer)
class ImageFieldSerializer(BaseImageFieldSerializer):
def __call__(self):
result = super().__call__()
if HAS_ENHANCEDLINKS:
if IEnhancedLinksEnabled.providedBy(self.context):
result.update(
{
"getObjSize": human_readable_size(result["size"]),
"enhanced_links_enabled": True,
}
)
return result


def serialize_data(context, json_data, show_children=False):
request = getRequest()
if not json_data:
3 changes: 3 additions & 0 deletions src/design/plone/contenttypes/testing.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import collective.venue
import collective.volto.blocksfield
import collective.volto.cookieconsent
import collective.volto.enhancedlinks
import collective.z3cform.datagridfield
import design.plone.contenttypes
import eea.api.taxonomy
@@ -32,6 +33,7 @@ def setUpZope(self, app, configurationContext):
super().setUpZope(app, configurationContext)
self.loadZCML(package=collective.venue)
self.loadZCML(package=collective.volto.blocksfield)
self.loadZCML(package=collective.volto.enhancedlinks)
self.loadZCML(package=design.plone.contenttypes, context=configurationContext)
self.loadZCML(package=plone.formwidget.geolocation)
self.loadZCML(name="overrides.zcml", package=design.plone.contenttypes)
@@ -71,6 +73,7 @@ def setUpZope(self, app, configurationContext):
super().setUpZope(app, configurationContext)
self.loadZCML(package=collective.venue)
self.loadZCML(package=collective.volto.blocksfield)
self.loadZCML(package=collective.volto.enhancedlinks)
self.loadZCML(package=design.plone.contenttypes, context=configurationContext)
self.loadZCML(package=plone.formwidget.geolocation)
self.loadZCML(package=eea.api.taxonomy)
1 change: 1 addition & 0 deletions src/design/plone/contenttypes/tests/test_ct_modulo.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ def test_behaviors_enabled_for_modulo(self):
"plone.locking",
"design.plone.contenttypes.behavior.multi_file",
"plone.translatable",
"volto.enhanced_links_enabled",
),
)

Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import unittest


class SummarySerializerTest(unittest.TestCase):
class FileFieldSerializerTest(unittest.TestCase):
layer = DESIGN_PLONE_CONTENTTYPES_API_FUNCTIONAL_TESTING

def setUp(self):
@@ -61,6 +61,11 @@ def test_if_visualize_files_true_so_dsiplay(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertIn("@@display-file", response["file_principale"]["download"])

def test_human_readable_obj_size_in_data(self):
def test_if_enhancedlinks_behavior_active_has_human_readable_obj_size_in_data(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertEqual("1 KB", response["file_principale"]["getObjSize"])

def test_if_enhancedlinks_behavior_active_has_flag_in_data(self):
response = self.api_session.get(self.modulo.absolute_url()).json()
self.assertIn("enhanced_links_enabled", response["file_principale"])
self.assertTrue(response["file_principale"]["enhanced_links_enabled"])
11 changes: 10 additions & 1 deletion src/design/plone/contenttypes/upgrades/configure.zcml
Original file line number Diff line number Diff line change
@@ -808,5 +808,14 @@
handler=".upgrades.add_canale_digitale_link_index"
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeSteps
profile="design.plone.contenttypes:default"
source="7022"
destination="7030"
>
<genericsetup:upgradeStep
title="Add collective.volto.enhancedlinks"
handler=".upgrades.to_7030"
/>
</genericsetup:upgradeSteps>
</configure>
20 changes: 20 additions & 0 deletions src/design/plone/contenttypes/upgrades/upgrades.py
Original file line number Diff line number Diff line change
@@ -1581,6 +1581,26 @@ def update_pdc_with_pdc_desc(context):
logger.info("Ends of update")


def to_7030(context):
installOrReinstallProduct(api.portal.get(), "collective.volto.enhancedlinks")
# add behavior to modulo
portal_types = api.portal.get_tool(name="portal_types")
modulo_behaviors = [x for x in portal_types["Modulo"].behaviors]
if "volto.enhanced_links_enabled" not in modulo_behaviors:
modulo_behaviors.append("volto.enhanced_links_enabled")
portal_types["Modulo"].behaviors = tuple(modulo_behaviors)

# update index/metadata
brains = api.content.find(portal_type=["File", "Image", "Modulo"])
tot = len(brains)
i = 0
for brain in brains:
i += 1
if i % 100 == 0:
logger.info("Progress: {}/{}".format(i, tot))
brain.getObject().reindexObject(idxs=["enhanced_links_enabled"])


def add_canale_digitale_link_index(context):
update_catalog(context)
update_registry(context)