Skip to content

Commit

Permalink
Correct dcat_catalog content type.
Browse files Browse the repository at this point in the history
Use i18n values from i18n module.
Add i18n field properties for title and description.
Use correct content type names for linked content.
  • Loading branch information
thomasmassmann committed Feb 7, 2018
1 parent ac58ee7 commit c68472c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 99 deletions.
19 changes: 10 additions & 9 deletions src/pkan/dcatapde/constants.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# -*- coding: utf-8 -*-
"""Constants for easier access."""

# content types
# Content Types
CT_DCAT_CATALOG = 'dcat_catalog'
CT_FOAF_AGENT = 'foaf_agent'
CT_DCAT_DATASET = 'dcat_dataset'
CT_DCAT_DISTRIBUTION = 'dcat_distribution'
CT_DCT_LICENSEDOCUMENT = 'dct_licensedocument'
CT_DCT_LOCATION = 'dct_location'
CT_DCT_MEDIATYPEOREXTENT = 'dct_mediatypeorextent'
CT_DCAT_DISTRIBUTION = 'dcat_distribution'
CT_DCAT_DATASET = 'dcat_dataset'
CT_HARVESTER_FOLDER = 'harvesterfolder'
CT_FOAF_AGENT = 'foaf_agent'
CT_HARVESTER = 'harvester'
CT_HARVESTER_FIELD_CONFIG = 'harvester_field_config'
CT_HARVESTER_FOLDER = 'harvesterfolder'
CT_SKOS_CONCEPT = 'skos_concept'
CT_SKOS_CONCEPTSCHEME = 'skos_conceptscheme'

# folder CTs to contain CTs
CT_LICENSE_FOLDER = 'LicenseFolder'
# Folder CTs to contain CTs
CT_AGENT_FOLDER = 'AgentFolder'
CT_CONCEPT_FOLDER = 'ConceptFolder'
CT_CONCEPTSCHEME_FOLDER = 'ConceptSchemeFolder'
CT_FORMAT_FOLDER = 'FormatFolder'
CT_LICENSE_FOLDER = 'LicenseFolder'
CT_MEDIATYPE_FOLDER = 'MediaTypeFolder'
CT_CONCEPTSCHEME_FOLDER = 'ConceptSchemeFolder'
CT_CONCEPT_FOLDER = 'ConceptFolder'

# list of DCAT CTs
DCAT_CTs = [
Expand Down
169 changes: 79 additions & 90 deletions src/pkan/dcatapde/content/dcat_catalog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""Catalog Content Type."""
"""DCATCatalog Content Type."""

from pkan.dcatapde import _
from pkan.dcatapde.constants import CT_DCAT_CATALOG
from pkan.dcatapde.constants import CT_DCT_LICENSEDOCUMENT
from pkan.dcatapde.constants import CT_FOAF_AGENT
from pkan.dcatapde import constants
from pkan.dcatapde import i18n
from pkan.dcatapde.content.base import DCATMixin
from pkan.widgets.relateditems import RelatedItemsFieldWidget
from plone.app.z3cform.widget import AjaxSelectFieldWidget
Expand All @@ -14,231 +12,222 @@
from plone.supermodel import model
from ps.zope.i18nfield.field import I18NText
from ps.zope.i18nfield.field import I18NTextLine
from ps.zope.i18nfield.fieldproperty import I18NFieldProperty
from ps.zope.i18nfield.fieldproperty import I18NTextProperty
from z3c.relationfield import RelationChoice
from zope.interface import implementer

import zope.schema as schema


class IDCATCatalog(model.Schema):
"""Marker interfce and Dexterity Python Schema for Catalog."""
"""Marker interfce and Dexterity Python Schema for DCATCatalog."""

# Fieldsets
# -------------------------------------------------------------------------
model.fieldset(
'linking',
label=i18n.FIELDSET_RELATIONS,
fields=[
'dct_hasPart',
'dct_isPartOf',
'dct_spatial',
],
)

# Mandatory
# ------------------------------
# -------------------------------------------------------------------------
dct_title = I18NTextLine(
required=True,
title=_(u'Title'),
title=i18n.LABEL_DCT_TITLE,
)

dct_description = I18NText(
required=True,
title=_(u'Description'),
title=i18n.LABEL_DCT_DESCRIPTION,
)

form.widget(
'dct_publisher',
RelatedItemsFieldWidget,
content_type=CT_FOAF_AGENT,
content_type_title=_(u'Publisher'),
content_type=constants.CT_FOAF_AGENT,
content_type_title=i18n.LABEL_DCT_PUBLISHER,
initial_path='/publisher/',
pattern_options={
'selectableTypes': [CT_FOAF_AGENT],
'selectableTypes': [constants.CT_FOAF_AGENT],
},
)

dct_publisher = RelationChoice(
description=_(
u'Add a new publisher or chose one from the list of publishers',
),
description=i18n.HELP_DCT_PUBLISHER,
required=True,
title=_(u'Publisher'),
title=i18n.LABEL_DCT_PUBLISHER,
vocabulary='plone.app.vocabularies.Catalog',
)

# Recommended
# ------------------------------
# -------------------------------------------------------------------------
form.widget(
'dct_license',
RelatedItemsFieldWidget,
content_type=CT_DCT_LICENSEDOCUMENT,
content_type_title=_(u'License'),
content_type=constants.CT_DCT_LICENSEDOCUMENT,
content_type_title=i18n.LABEL_DCT_LICENSE,
initial_path='/licenses/',
pattern_options={
'selectableTypes': [CT_DCT_LICENSEDOCUMENT],
'selectableTypes': [constants.CT_DCT_LICENSEDOCUMENT],
},
)

dct_license = RelationChoice(
description=_(
u'Add a new license or chose one from the list of licenses',
),
description=i18n.HELP_DCT_LICENSE,
required=False,
title=_(u'License'),
title=i18n.LABEL_DCT_LICENSE,
vocabulary='plone.app.vocabularies.Catalog',
)

foaf_homepage = schema.URI(
required=False,
title=(u'Homepage'),
title=i18n.LABEL_FOAF_HOMEPAGE,
)

form.widget(
'dct_language',
AjaxSelectFieldWidget,
vocabulary='plone.app.vocabularies.AvailableContentLanguages',
)

dct_language = schema.List(
title=_(u'Languages'),
required=False,
title=i18n.LABEL_DCT_LANGUAGE,
value_type=schema.Choice(
vocabulary='plone.app.vocabularies.AvailableContentLanguages',
),
required=False,
)

form.widget(
'dcat_themeTaxonomy',
RelatedItemsFieldWidget,
content_type='dct_licensedocument',
content_type_title=_(u'Theme Taxonomy'),
content_type=constants.CT_DCT_LICENSEDOCUMENT,
content_type_title=i18n.LABEL_DCT_THEMETAXONOMY,
initial_path='/licenses/',
pattern_options={
'selectableTypes': ['dct_licensedocument'],
'selectableTypes': [constants.CT_DCT_LICENSEDOCUMENT],
},
)

dcat_themeTaxonomy = RelationChoice(
description=_(
u'Add a new Theme Taxonomy or chose one from the list',
),
description=i18n.HELP_DCT_THEMETAXONOMY,
required=False,
title=_(u'Theme Taxonomy'),
title=i18n.LABEL_DCT_THEMETAXONOMY,
vocabulary='plone.app.vocabularies.Catalog',
)

# Optional
# -----------------------------------------------------

# -------------------------------------------------------------------------
form.widget(
'dct_rights',
RelatedItemsFieldWidget,
content_type='dct_licensedocument',
content_type_title=_(u'Rights'),
content_type=constants.CT_DCT_LICENSEDOCUMENT,
content_type_title=i18n.LABEL_DCT_RIGHTS,
initial_path='/licenses/',
pattern_options={
'selectableTypes': ['dct_licensedocument'],
'selectableTypes': [constants.CT_DCT_LICENSEDOCUMENT],
},
)

dct_rights = RelationChoice(
description=_(
u'Add a new rights statement or chose one from the list of '
u'statements',
),
description=i18n.HELP_DCT_RIGHTS,
required=False,
title=_(u'Rights'),
title=i18n.LABEL_DCT_RIGHTS,
vocabulary='plone.app.vocabularies.Catalog',
)

dct_issued = schema.Date(
required=False,
title=(u'Issued'),
title=i18n.LABEL_DCT_ISSUED,
)

dct_modified = schema.Date(
required=False,
title=(u'Modified'),
)

model.fieldset(
'linking',
label=_(u'Relations'),
fields=[
'dct_hasPart',
'dct_isPartOf',
'dct_spatial',
],
title=i18n.LABEL_DCT_MODIFIED,
)

form.widget(
'dct_hasPart',
RelatedItemsFieldWidget,
content_type='catalog',
content_type_title=_(u'Parts'),
content_type=constants.CT_DCAT_CATALOG,
content_type_title=i18n.LABEL_DCT_HASPART,
initial_path='/',
pattern_options={
'selectableTypes': ['catalog'],
'selectableTypes': [constants.CT_DCAT_CATALOG],
},
)

dct_hasPart = RelationChoice(
title=_(u'Parts'),
description=_(
u'Add a new Catalog or link to an existing',
),
description=i18n.HELP_DCT_HASPART,
required=False,
title=i18n.LABEL_DCT_HASPART,
vocabulary='plone.app.vocabularies.Catalog',
)

form.widget(
'dct_isPartOf',
RelatedItemsFieldWidget,
content_type='catalog',
content_type_title=_(u'Parent Catalog'),
content_type=constants.CT_DCAT_CATALOG,
content_type_title=i18n.LABEL_DCT_ISPARTOF,
initial_path='/',
pattern_options={
'selectableTypes': ['catalog'],
'selectableTypes': [constants.CT_DCAT_CATALOG],
},
)

dct_isPartOf = RelationChoice(
description=_(
u'Add a new Parent Catalog or link to an existing',
),
description=i18n.HELP_DCT_ISPARTOF,
required=False,
title=_(u'Parent Catalog'),
title=i18n.LABEL_DCT_ISPARTOF,
vocabulary='plone.app.vocabularies.Catalog',
)

form.widget(
'dct_spatial',
RelatedItemsFieldWidget,
content_type='dct_location',
content_type_title=_(u'Spatial relevance'),
content_type=constants.CT_DCT_LOCATION,
content_type_title=i18n.LABEL_DCT_SPATIAL,
initial_path='/locations/',
pattern_options={
'selectableTypes': ['dct_location'],
'selectableTypes': [constants.CT_DCT_LOCATION],
},
)

dct_spatial = RelationChoice(
description=_(
u'Add a new Location or link to an existing',
),
description=i18n.HELP_DCT_SPATIAL,
required=False,
title=_(u'Spatial relevance'),
title=i18n.LABEL_DCT_SPATIAL,
vocabulary='plone.app.vocabularies.Catalog',
)


@implementer(IDCATCatalog)
class DCATCatalog(Container, DCATMixin):
"""Catalog Content Type."""
"""DCATCatalog Content Type."""

_namespace = 'dcat'
_ns_class = 'catalog'

dct_title = I18NFieldProperty(IDCATCatalog['dct_title'])
dct_description = I18NTextProperty(IDCATCatalog['dct_description'])

def Title(self):
return unicode(self.dct_title)

def Description(self):
return self.dct_description


class DCATCatalogDefaultFactory(DexterityFactory):
"""Custom DX factory for Catalog."""
"""Custom DX factory for DCATCatalog."""

def __init__(self):
self.portal_type = CT_DCAT_CATALOG
self.portal_type = constants.CT_DCAT_CATALOG

def __call__(self, *args, **kw):
from pkan.dcatapde.api.catalog import clean_catalog

data, errors = clean_catalog(**kw)
folder = DexterityFactory.__call__(self, *args, **data)

return folder
return super(
DCATCatalogDefaultFactory,
self,
).__call__(*args, **data)
Loading

0 comments on commit c68472c

Please sign in to comment.