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

Add dependency with collective.volto.enhancedlinks #237

Closed
wants to merge 12 commits into from
9 changes: 6 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
6.1.15 (unreleased)
-------------------

- Nothing changed yet.
- Add dependency with collective.volto.enhancedlinks.
[cekk]


6.1.14 (2024-02-20)
Expand All @@ -19,7 +20,6 @@ Changelog
[eikichi18]



6.1.13 (2024-02-08)
-------------------

Expand All @@ -42,13 +42,16 @@ 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]
- Add new flag in settings needed to choose to show or not auto-generated footer columns.
[cekk]
- Customize @navigation endpoint to expose also the new flag for frontend.
[cekk]


6.1.10 (2024-01-16)
-------------------

Expand Down
1 change: 1 addition & 0 deletions base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ design.plone.contenttypes =
#redturtle.volto = git https://github.com/RedTurtle/redturtle.volto.git [email protected]:RedTurtle/redturtle.volto.git
#redturtle.bandi = git https://github.com/RedTurtle/redturtle.bandi.git [email protected]: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 [email protected]: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
Expand Up @@ -66,6 +66,7 @@
"z3c.unconfigure",
"eea.api.taxonomy",
"openpyxl",
"collective.volto.enhancedlinks",
],
extras_require={
"test": [
Expand Down
1 change: 1 addition & 0 deletions src/design/plone/contenttypes/adapters/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
factory=".searchabletext_indexers.TextBlockSearchableText"
name="text"
/>

</configure>
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>7031</version>
<version>7040</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
Expand Up @@ -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 -->
Expand Down
5 changes: 5 additions & 0 deletions src/design/plone/contenttypes/restapi/serializers/bando.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def get_approfondimenti(self, bando_view):
contents = bando_view.retrieveContentsOfFolderDeepening(folder["path"])
if not contents:
continue
# fix results for enhancedlinks
for content in contents:
content["getObjSize"] = content.get("filesize", "")
content["mime_type"] = content.get("content-type", "")
content["enhanced_links_enabled"] = "filesize" in content
folder.update({"children": contents})
results.append(folder)
return results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
28 changes: 27 additions & 1 deletion src/design/plone/contenttypes/restapi/serializers/dxfields.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# -*- coding: utf-8 -*-
from AccessControl.unauthorized import Unauthorized
from Acquisition import aq_inner
from collective.volto.enhancedlinks.interfaces import IEnhancedLinksEnabled
from design.plone.contenttypes.interfaces import IDesignPloneContenttypesLayer
from design.plone.contenttypes.interfaces.servizio import IServizio
from plone import api
from plone.app.contenttypes.utils import replace_link_variables_by_paths
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
Expand All @@ -23,6 +28,7 @@
from zope.schema.interfaces import ISourceText
from zope.schema.interfaces import ITextLine


import json
import re

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

return json_compatible(result)

Expand All @@ -95,6 +107,20 @@ def get_file_view_mode(self, content_type):
return "@@download"


@adapter(INamedImageField, IDexterityContent, IDesignPloneContenttypesLayer)
class ImageFieldSerializer(BaseImageFieldSerializer):
def __call__(self):
result = super().__call__()
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:
Expand Down
3 changes: 3 additions & 0 deletions src/design/plone/contenttypes/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/design/plone/contenttypes/tests/test_ct_modulo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import unittest


class TestDocument(unittest.TestCase):
class TestModulo(unittest.TestCase):
layer = DESIGN_PLONE_CONTENTTYPES_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]

def test_behaviors_enabled_for_documento(self):
def test_behaviors_enabled_for_modulo(self):
portal_types = api.portal.get_tool(name="portal_types")
self.assertEqual(
portal_types["Modulo"].behaviors,
Expand All @@ -29,5 +29,6 @@ def test_behaviors_enabled_for_documento(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
Expand Up @@ -14,7 +14,7 @@
import unittest


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

def setUp(self):
Expand Down Expand Up @@ -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"])
10 changes: 10 additions & 0 deletions src/design/plone/contenttypes/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -828,4 +828,14 @@
handler=".upgrades.to_7031"
/>
</genericsetup:upgradeSteps>
<genericsetup:upgradeSteps
profile="design.plone.contenttypes:default"
source="7031"
destination="7040"
>
<genericsetup:upgradeStep
title="Add dependency to collective.volto.enhancedlinks"
handler=".upgrades.to_7040"
/>
</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
Expand Up @@ -1596,3 +1596,23 @@ def to_7031(context):
for ptype in ["News Item"]:
portal_types[ptype].default_view = "view"
portal_types[ptype].view_methods = ["view"]


def to_7040(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"])
Loading