-
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.
Fields dct_title and dct_description will be indexed for any DCAT-CT Similiarity check for foaf:Agent is active for harvesting Renaming of some files to be more consistent
- Loading branch information
1 parent
1ec67b7
commit d9b15b0
Showing
34 changed files
with
309 additions
and
117 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,79 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Work with FOAFAgents.""" | ||
|
||
from pkan.dcatapde.constants import CT_FOAF_AGENT | ||
from pkan.dcatapde.content.foaf_agent import FOAFAgent | ||
from pkan.dcatapde.content.foaf_agent import IFOAFAgent | ||
from plone import api | ||
from zope.schema import getValidationErrors | ||
|
||
|
||
# Data Cleaning Methods | ||
def clean_foafagent(**data): | ||
"""Clean foafagent.""" | ||
test_obj = FOAFAgent() | ||
|
||
# test object must have an id | ||
test_obj.id = 'test' | ||
test_obj.title = 'test' | ||
|
||
for attr in data: | ||
setattr(test_obj, attr, data[attr]) | ||
|
||
errors = getValidationErrors(IFOAFAgent, test_obj) | ||
|
||
return data, errors | ||
|
||
|
||
def find_foaf_agent(data): | ||
"""Find a given on a search pattern equivalent to an create dataset""" | ||
catalog = api.portal.get_tool('portal_catalog') | ||
|
||
search_data = data.copy() | ||
# strip the data of legacy fields like title and description | ||
for key in ['title', 'description']: | ||
try: | ||
del search_data[key] | ||
except KeyError: | ||
pass | ||
|
||
# add the portal type | ||
search_data['portal_type'] = FOAFAgent.portal_type | ||
|
||
results = catalog.searchResults(**search_data) | ||
|
||
if len(results) > 1: | ||
result = results[0] | ||
elif len(results) == 0: | ||
result = None | ||
else: | ||
result = results | ||
|
||
return result | ||
|
||
|
||
# Add Methods | ||
def add_foafagent(context, **data): | ||
"""Add a new foafagent.""" | ||
context = get_foafagent_context() | ||
|
||
data, errors = clean_foafagent(**data) | ||
|
||
# no such agent exits create a new one | ||
agent = api.content.create(container=context, type=CT_FOAF_AGENT, **data) | ||
|
||
return agent | ||
|
||
|
||
# Get Methods | ||
def get_foafagent_context(): | ||
"""Get content for an foafagent.""" | ||
# fix: context should not be the site | ||
context = api.portal.get() | ||
return context | ||
|
||
|
||
# Delete Methods | ||
|
||
|
||
# Related Methods |
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Utils""" | ||
|
||
|
||
def I18NField2Unique(obj): | ||
"""Expresses an i18Nfield as unique as possible as a string""" | ||
langs = obj.keys() | ||
langs.sort() | ||
result = [] | ||
for lang in langs: | ||
result.append(lang + ':' + obj[lang]) | ||
|
||
return ' '.join(result) |
Oops, something went wrong.