Skip to content

Commit

Permalink
Merge pull request #24 from BB-Open/collection_catalog
Browse files Browse the repository at this point in the history
Collection catalog
  • Loading branch information
sandrarum committed Mar 28, 2018
2 parents 59e2f10 + 0ba7754 commit 0665ff4
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/pkan/dcatapde/api/dcat_collection_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""Work with CollectionCatalogs."""

from pkan.dcatapde.constants import CT_DCAT_COLLECTION_CATALOG
from pkan.dcatapde.content.dcat_collectioncatalog import DCATCollectionCatalog
from pkan.dcatapde.content.dcat_collectioncatalog import IDCATCollectionCatalog
from plone.api.content import create
from zope.schema import getValidationErrors


# Data Cleaning Methods
def clean_collection(**data):
"""Clean CollectionCatalogs."""
test_catalog = DCATCollectionCatalog()

# test object must have an id
test_catalog.id = 'test'
test_catalog.title = 'test'

for attr in data:
setattr(test_catalog, attr, data[attr])

errors = getValidationErrors(IDCATCollectionCatalog, test_catalog)

return data, errors


# Add Methods
def add_collection_catalog(context, **data):
"""Add a new CollectionCatalog."""
data, errors = clean_collection(**data)

catalog = create(container=context,
type=CT_DCAT_COLLECTION_CATALOG,
**data)

return catalog

# Get Methods

# Delete Methods

# Related Methods
7 changes: 7 additions & 0 deletions src/pkan/dcatapde/browser/content_views/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,12 @@
permission="cmf.ManagePortal"
/>

<browser:page
for="pkan.dcatapde.content.dcat_collectioncatalog.IDCATCollectionCatalog"
name="folder_listing"
class=".dcat_collection_catalog.DcatCollectionCatalogFolderListing"
template="templates/folder_listing.pt"
permission="zope2.View"
/>

</configure>
34 changes: 34 additions & 0 deletions src/pkan/dcatapde/browser/content_views/dcat_collection_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from plone.app.contenttypes.behaviors.collection import ICollection
from plone.app.dexterity.browser.folder_listing import FolderView


class DcatCollectionCatalogFolderListing(FolderView):

@property
def collection_behavior(self):
return ICollection(aq_inner(self.context))

def results(self, **kwargs):
"""Return a content listing based result set with results from the
collection query.
:param **kwargs: Any keyword argument, which can be used for
catalog queries.
:type **kwargs: keyword argument
:returns: plone.app.contentlisting based result set.
:rtype: ``plone.app.contentlisting.interfaces.IContentListing``
based sequence.
"""
# Extra filter
contentFilter = dict(self.request.get('contentFilter', {}))
contentFilter.update(kwargs.get('contentFilter', {}))
kwargs.setdefault('custom_query', contentFilter)
kwargs.setdefault('batch', True)
kwargs.setdefault('b_size', self.b_size)
kwargs.setdefault('b_start', self.b_start)

results = self.collection_behavior.results(**kwargs)
return results
117 changes: 117 additions & 0 deletions src/pkan/dcatapde/browser/content_views/templates/folder_listing.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="plone">
<body>

<metal:content-core fill-slot="content-core">
<metal:block define-macro="content-core">

<metal:listingmacro define-macro="listing">
<tal:results define="batch view/batch">
<tal:listing condition="batch">
<div class="entries" metal:define-slot="entries">
<tal:repeat repeat="item batch" metal:define-macro="entries">
<tal:block tal:define="obj item/getObject;
item_url item/getURL;
item_id item/getId;
item_title item/Title;
item_description item/Description;
item_type item/PortalType;
item_modified item/ModificationDate;
item_created item/CreationDate;
item_type_class python:'contenttype-' + view.normalizeString(item_type);
item_wf_state item/review_state;
item_wf_state_class python:'state-' + view.normalizeString(item_wf_state);
item_creator item/Creator;
item_link python:item_type in view.use_view_action and item_url+'/view' or item_url;
item_has_image python:item.getIcon">
<metal:block define-slot="entry">
<article class="entry">
<header metal:define-macro="listitem">
<span class="summary" tal:attributes="title item_type">
<a tal:attributes="href item_link">
<img class="image-tile"
tal:condition="item_has_image"
tal:attributes="src string:$item_url/@@images/image/tile">
</a>
<a tal:attributes="href item_link;
class string:$item_type_class $item_wf_state_class url;
title item_type"
tal:content="item_title">

Item Title
</a>
</span>
<metal:block metal:define-macro="document_byline">
<div class="documentByLine">
<tal:byline condition="view/show_about">
&mdash;
<tal:name tal:condition="item_creator"
tal:define="author python:view.pas_member.info(item_creator);
creator_short_form author/username;
creator_long_form string:?author=${author/username};
creator_is_openid python:'/' in creator_short_form;
creator_id python:(creator_short_form, creator_long_form)[creator_is_openid];">
<span i18n:translate="label_by_author">
by
<a tal:attributes="href string:${view/navigation_root_url}/author/${item_creator}"
tal:content="author/name_or_id"
tal:omit-tag="not:author"
i18n:name="author">
Bob Dobalina
</a>
</span>
</tal:name>

<tal:modified>
&mdash;
<tal:mod i18n:translate="box_last_modified">last modified</tal:mod>
<span tal:replace="python:view.toLocalizedTime(item_modified,long_format=1)">
August 16, 2001 at 23:35:59
</span>
</tal:modified>

<metal:description define-slot="description_slot">
<tal:comment replace="nothing">
Place custom listing info for custom types here
</tal:comment>
</metal:description>
</tal:byline>
</div>
</metal:block>
</header>
<p class="description discreet"
tal:condition="item_description"
tal:content="item_description">
description
</p>
</article>
</metal:block>
</tal:block>
</tal:repeat>
</div>

<div metal:use-macro="context/batch_macros/macros/navigation" />

</tal:listing>

<metal:empty metal:define-slot="no_items_in_listing">
<p class="discreet"
tal:condition="not: view/batch"
tal:content="view/no_items_message">
There are currently no items in this folder.
</p>
</metal:empty>

</tal:results>
</metal:listingmacro>

</metal:block>
</metal:content-core>

</body>
</html>
2 changes: 2 additions & 0 deletions src/pkan/dcatapde/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Content Types
CT_DCAT_CATALOG = 'dcat_catalog'
CT_DCAT_COLLECTION_CATALOG = 'dcat_collection_catalog'
CT_DCAT_DATASET = 'dcat_dataset'
CT_DCAT_DISTRIBUTION = 'dcat_distribution'
CT_DCT_LICENSEDOCUMENT = 'dct_licensedocument'
Expand Down Expand Up @@ -32,6 +33,7 @@
# list of DCAT CTs
DCAT_CTs = [
CT_DCAT_CATALOG,
CT_DCAT_COLLECTION_CATALOG,
CT_DCAT_DATASET,
CT_DCAT_DISTRIBUTION,
CT_FOAF_AGENT,
Expand Down
14 changes: 14 additions & 0 deletions src/pkan/dcatapde/content/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
provides="plone.dexterity.interfaces.IDexterityFactory"
/>

<!-- DCATCollectionCatalog -->
<!-- =========== -->
<adapter
factory=".util.NameFromDCTTitle"
for=".dcat_collectioncatalog.IDCATCollectionCatalog"
provides="plone.app.content.interfaces.INameFromTitle"
/>

<utility
factory=".dcat_collectioncatalog.DCATCollectionCatalogDefaultFactory"
name="dcat_collection_catalog"
provides="plone.dexterity.interfaces.IDexterityFactory"
/>


<!-- DCATDataset -->
<!-- =========== -->
Expand Down
50 changes: 50 additions & 0 deletions src/pkan/dcatapde/content/dcat_collectioncatalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""DCATCatalog Content Type."""

from pkan.dcatapde import constants
from pkan.dcatapde.content.dcat_catalog import DCATCatalog
from pkan.dcatapde.content.dcat_catalog import IDCATCatalog
from plone.dexterity.factory import DexterityFactory
from ps.zope.i18nfield.fieldproperty import I18NTextProperty
from zope.interface import implementer


class IDCATCollectionCatalog(IDCATCatalog):
"""Marker interface and Dexterity Python Schema for
DCATCollectionCatalog."""


@implementer(IDCATCollectionCatalog)
class DCATCollectionCatalog(DCATCatalog):
"""DCATCatalog Content Type."""

portal_type = constants.CT_DCAT_COLLECTION_CATALOG
content_schema = IDCATCollectionCatalog
_namespace = 'dcat'
_ns_class = 'catalog'

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

def Title(self):
return self.title_from_title_field()

def Description(self):
return unicode(self.dct_description)


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

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

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

data, errors = clean_collection(**kw)

return super(
DCATCollectionCatalogDefaultFactory,
self,
).__call__(*args, **data)
2 changes: 2 additions & 0 deletions src/pkan/dcatapde/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
LABEL_DCAT_ACCESSURL = _(u'Access URL')
LABEL_DCAT_BYTESIZE = _(u'Byte size')
LABEL_DCAT_CATALOG = _(u'Catalog')
LABEL_DCAT_COLLECTION_CATALOG = _(u'Collection Catalog')
LABEL_DCAT_DATASET = _(u'Dataset')
LABEL_DCAT_DOWNLOADURL = _(u'Download URL')
LABEL_DCAT_DISTRIBUTION = _(u'Distribution')
Expand Down Expand Up @@ -207,6 +208,7 @@
# Content type labels
CT_LABELS = {
constants.CT_DCAT_CATALOG: LABEL_DCAT_CATALOG,
constants.CT_DCAT_COLLECTION_CATALOG: LABEL_DCAT_COLLECTION_CATALOG,
constants.CT_DCAT_DATASET: LABEL_DCAT_DATASET,
constants.CT_DCAT_DISTRIBUTION: LABEL_DCAT_DISTRIBUTION,
constants.CT_DCT_LICENSEDOCUMENT: LABEL_DCT_LICENSEDOCUMENT,
Expand Down
7 changes: 7 additions & 0 deletions src/pkan/dcatapde/io/rdf/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
provides=".interfaces.IObject2Surf"
/>

<adapter
factory=".dcat.CollectionCatalog2Surf"
for="pkan.dcatapde.content.dcat_catalog.IDCATCollectionCatalog
.interfaces.ISurfSession"
provides=".interfaces.IObject2Surf"
/>

<!-- rdfs adapters -->
<adapter factory=".dexterity.DexterityFTI2Surf" />

Expand Down
19 changes: 19 additions & 0 deletions src/pkan/dcatapde/io/rdf/dcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""DCAT 2 RDF."""

from pkan.dcatapde.content.dcat_catalog import IDCATCatalog
from pkan.dcatapde.content.dcat_collectioncatalog import IDCATCollectionCatalog
from pkan.dcatapde.content.foaf_agent import IFOAFAgent
from pkan.dcatapde.io.rdf.dexterity import Dexterity2Surf
from pkan.dcatapde.io.rdf.interfaces import ISurfSession
Expand Down Expand Up @@ -38,3 +39,21 @@ class Catalog2Surf(Dexterity2Surf):
# Stores the namespace for this resource
_namespace = surf.ns.DCAT
_prefix = 'dcat'


class CollectionCatalog2Surf(Dexterity2Surf):
"""Dexterity implementation of the Object2Surf."""

adapter(IDCATCollectionCatalog, ISurfSession)

_whitelist = [
'title',
'description',
'publisher',
'add_title',
'add_description',
]

# Stores the namespace for this resource
_namespace = surf.ns.DCAT
_prefix = 'dcat'
5 changes: 5 additions & 0 deletions src/pkan/dcatapde/permissions.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
title="pkan.dcatapde: Add DCATCatalog"
/>

<permission
id="pkan.dcatapde.AddDCATCollectionCatalog"
title="pkan.dcatapde: Add DCATCollectionCatalog"
/>

<permission
id="pkan.dcatapde.AddDCATDataset"
title="pkan.dcatapde: Add DCATDataset"
Expand Down
17 changes: 16 additions & 1 deletion src/pkan/dcatapde/profiles/default/registry.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<registry>
<registry
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="pkan.dcatapde">
<records interface="pkan.dcatapde.interfaces.IPKANBaseSettings" />
<records interface="pkan.dcatapde.interfaces.IPKANFolderSettings" />
<records interface="pkan.dcatapde.interfaces.IPKANImportSettings" />
Expand All @@ -19,4 +21,17 @@
<value key="compile">False</value>
<value key="depends">plone</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.dcat_theme">
<value key="title" i18n:translate="">Dcat Theme</value>
<value key="description" i18n:translate="">A Skos Concept Theme</value>
<value key="enabled">True</value>
<value key="sortable">False</value>
<value key="operations">
<element>plone.app.querystring.operation.selection.any</element>
</value>
<value key="vocabulary">pkan.dcatapde.vocabularies.SKOSConceptValues</value>
<value key="group" i18n:translate="">PKAN</value>
</records>
</registry>
Loading

0 comments on commit 0665ff4

Please sign in to comment.