Skip to content

Commit

Permalink
Merge pull request #33 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
alecghica authored Jun 19, 2024
2 parents 2dedd7d + f4ae1dd commit b1a03f1
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

3.8 - (2024-06-19)
---------------------------
* Change: Release
[avoinea]

3.7 - (2024-04-09)
---------------------------
* Change: updated Organizations taxonomy, added EMA.
Expand Down
5 changes: 5 additions & 0 deletions eea/coremetadata/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@

<adapter factory=".indexer.temporal_coverage_indexer" name="temporal_coverage" />
<adapter factory=".indexer.data_provenance_indexer" name="data_provenance" />

<utility
name="eea.coremetadata.other_organisations"
component=".vocabulary.OtherOrganisationsVocabularyFactory"
/>
</configure>
18 changes: 15 additions & 3 deletions eea/coremetadata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from zope.schema import Choice, Datetime, Text, TextLine, Tuple
from zope.schema.interfaces import IContextAwareDefaultFactory


try:
from plone.app.dexterity import _
from plone.app.z3cform.widget import SelectFieldWidget
Expand All @@ -36,6 +35,12 @@
from z3c.form.browser.select import SelectFieldWidget
from Products.CMFCore.permissions import ModifyPortalContent, View

has_ajax_widget = True
AjaxSelectFieldWidget = None
try:
from plone.app.z3cform.widgets.select import AjaxSelectFieldWidget
except ImportError:
has_ajax_widget = False

_marker = []
_zone = DateTime().timezone()
Expand Down Expand Up @@ -183,10 +188,17 @@ class ICoreMetadata(model.Schema):
"of this item"
), # noqa
required=False,
value_type=Choice(vocabulary="organisations_vocabulary"),
defaultFactory=defaultOrganisations,
value_type=TextLine(),
missing_value=(),
)

if has_ajax_widget:
directives.widget(
"other_organisations",
AjaxSelectFieldWidget,
vocabulary="eea.coremetadata.other_organisations"
)

directives.widget("topics", SelectFieldWidget)
topics = Tuple(
title=_("Topics"),
Expand Down
2 changes: 1 addition & 1 deletion eea/coremetadata/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>3.5</version>
<version>3.6</version>
<dependencies>
<dependency>profile-collective.taxonomy:default</dependency>
</dependencies>
Expand Down
9 changes: 9 additions & 0 deletions eea/coremetadata/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@
/>
</genericsetup:upgradeSteps>

<genericsetup:upgradeStep
title="Register index other_organisations in portal_catalog"
description=""
source="3.5"
destination="3.6"
handler=".to_36.to_36"
profile="eea.coremetadata:default"
/>

</configure>
76 changes: 76 additions & 0 deletions eea/coremetadata/upgrades/to_36.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# pylint: disable=W1201, C0301, C0111, W0640, W1202
# -*- coding: utf-8 -*-
""" Upgrade to 3.6 """
import logging

from Products.CMFCore.utils import getToolByName
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
from Products.ZCatalog.Catalog import CatalogError
from plone.dexterity.utils import iterSchemataForType
from plone import api
from Acquisition import aq_self
from eea.coremetadata.behaviors.vocabulary import get_vocabulary
from eea.coremetadata.metadata import ICoreMetadata

logger = logging.getLogger("eea.coremetadata.upgrade")

VOCAB_NAME = "collective.taxonomy.eeaorganisationstaxonomy"
INDEX_NAME = "other_organisations"
OLD_INDEX_NAME = "taxonomy_eeaorganisationstaxonomy"


def to_36(context):
catalog = getToolByName(context.aq_parent, "portal_catalog")

idx_object = KeywordIndex(INDEX_NAME)

try:
catalog.addIndex(INDEX_NAME, idx_object)
except CatalogError:
logging.info(
"Index {0} already exists, we hope it is proper configured".format( # noqa: E501
INDEX_NAME
) # noqa: E501
)

types = getToolByName(context, 'portal_types').listTypeInfo()
migrated_types = []

for _type in types:
portal_type = _type.getId()
for schemata in iterSchemataForType(portal_type):
if schemata is ICoreMetadata:
migrated_types.append(portal_type)

vocabulary = get_vocabulary(context, VOCAB_NAME)

org_translated = {key: val if ord(
val[0]) < 255 else val[1:] for val, key in vocabulary}
brains = api.content.find(portal_type=migrated_types)

for brain in brains:
obj = brain.getObject()
obj = aq_self(obj)
orgs = getattr(obj, 'other_organisations', None)
logger.info("Check for (%s) - %s",
brain.getURL(), obj.other_organisations)

if orgs:
translated = tuple([
org_translated[key] if key in org_translated else key
for key in orgs
])
obj.other_organisations = translated
obj._p_changed = True
obj.reindexObject()
logger.info("Migrated organisations for obj (%s) - %s -> %s",
brain.getURL(), orgs, obj.other_organisations)

catalog.reindexIndex(INDEX_NAME, idx_object)
try:
catalog.delIndex(OLD_INDEX_NAME)
logging.info("Old index {0} was deleted".format(INDEX_NAME))
except CatalogError:
logging.info("Old index {0} was not found".format(INDEX_NAME))

logger.info("Upgraded to 3.6")
2 changes: 1 addition & 1 deletion eea/coremetadata/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7
3.8
16 changes: 16 additions & 0 deletions eea/coremetadata/vocabulary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""vocabularies"""
from plone.app.vocabularies.catalog import KeywordsVocabulary as BKV
from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory


@implementer(IVocabularyFactory)
class OtherOrganisationKeywords(BKV):
"""Core metada other organisation keywords"""

def __init__(self, index):
self.keyword_index = index


OtherOrganisationsVocabularyFactory = OtherOrganisationKeywords(
"other_organisations")

0 comments on commit b1a03f1

Please sign in to comment.