-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from BB-Open/collection_catalog
Collection catalog
- Loading branch information
Showing
19 changed files
with
497 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/pkan/dcatapde/browser/content_views/dcat_collection_catalog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
117
src/pkan/dcatapde/browser/content_views/templates/folder_listing.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
— | ||
<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> | ||
— | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.