Skip to content

Commit

Permalink
Merge pull request #13 from BB-Open/harvesting_refacturing
Browse files Browse the repository at this point in the history
Harvesting refacturing
  • Loading branch information
sandrarum committed Feb 15, 2018
2 parents 219411d + 42f2586 commit 7df53e9
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ script:
- bin/code-analysis
- bin/test
after_success:
- bin/createcoverage
- travis_wait 30 bin/createcoverage
- pip install coveralls
- coveralls
notifications:
Expand Down
25 changes: 22 additions & 3 deletions src/pkan/dcatapde/api/harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# Data Cleaning Methods
def clean_harvester(**data):
"""Clean harvester."""
if not data:
return data, ()

if 'title' not in data:
data['title'] = data['url']

Expand All @@ -33,6 +36,7 @@ def clean_harvester(**data):
def clean_harvesterfolder(**data):
"""Clean Harvesterfolder."""
test_obj = Harvesterfolder()

test_obj.id = constants.HARVESTER_FOLDER_ID
test_obj.title = constants.HARVESTER_FOLDER_TITLE

Expand Down Expand Up @@ -67,11 +71,13 @@ def add_harvester_folder(context, **data):
data, errors = clean_harvesterfolder(**data)

# set id and title, title for presentation and id for addressing the object
if 'title' not in data:
data['title'] = constants.HARVESTER_FOLDER_TITLE
if 'id' not in data:
data['id'] = constants.HARVESTER_FOLDER_ID
harvester_folder = api.content.create(
container=context,
type=constants.CT_HARVESTER_FOLDER,
title=constants.HARVESTER_FOLDER_TITLE,
id=constants.HARVESTER_FOLDER_ID,
**data)

return harvester_folder
Expand All @@ -92,7 +98,7 @@ def get_harvester_folder():


def get_all_harvester():
"""Find the folder where the harvester_folder live."""
"""Get all harvester,"""
portal = getSite()
if not portal:
return None
Expand All @@ -104,6 +110,19 @@ def get_all_harvester():
return harvester


def get_all_harvester_folder():
"""Find all HarvesterFolder"""
portal = getSite()
if not portal:
return None
catalog = portal.portal_catalog
res = catalog.searchResults({'portal_type': constants.CT_HARVESTER_FOLDER})
folder = []
for brain in res:
folder.append(brain.getObject())
return folder


# Delete Methods
def delete_harvester(object):
"""Remove a harvester."""
Expand Down
8 changes: 8 additions & 0 deletions src/pkan/dcatapde/browser/content_views/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
for="*"
name="harvester_overview"
class=".harvester.HarvesterOverview"
template="templates/harvester_overview.pt"
permission="cmf.ManagePortal"
/>

<browser:page
for="pkan.dcatapde.content.harvesterfolder.IHarvesterfolder"
name="harvester_overview"
class=".harvester.HarvesterFolderView"
template="templates/harvester.pt"
permission="cmf.ManagePortal"
/>
Expand Down
85 changes: 64 additions & 21 deletions src/pkan/dcatapde/browser/content_views/harvester.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from pkan.dcatapde import utils
from pkan.dcatapde.api.functions import get_ancestor
from pkan.dcatapde.api.harvester import get_all_harvester
from pkan.dcatapde.api.harvester import get_all_harvester_folder
from pkan.dcatapde.api.harvester_field_config import get_field_config
from pkan.dcatapde.constants import CT_HARVESTER
from pkan.dcatapde.content.harvester_field_config import CT_FIELD_RELATION
Expand All @@ -12,34 +12,77 @@
import copy


class HarvesterOverview(BrowserView):
class HarvesterListViewMixin(object):
"""
Reusable Methods needed by all Views listing Harvester
"""

def read_harvester_info(self, harv):

path = harv.absolute_url()
field_config = get_field_config(harv)

data = {
'title': harv.title,
'path': path,
'source_url': addTokenToUrl(harv.url),
'dry_run': addTokenToUrl(path + '/dry_run'),
'real_run': addTokenToUrl(path + '/real_run'),
'reset_fields': addTokenToUrl(path + '/reset_fields'),
'edit': addTokenToUrl(path + '/edit'),
}
if field_config:
data['field_config'] = addTokenToUrl(
field_config.absolute_url(),
)
else:
data['field_config'] = None

return data


class HarvesterFolderView(BrowserView, HarvesterListViewMixin):
"""
Listing Harvester of one Folder
"""

def __call__(self, *args, **kwargs):
harvester = get_all_harvester()
folder = self.context

self.data = []

for harv in harvester:
path = harv.absolute_url()
field_config = get_field_config(harv)

data = {
'title': harv.title,
'path': path,
'source_url': addTokenToUrl(harv.url),
'dry_run': addTokenToUrl(path + '/dry_run'),
'real_run': addTokenToUrl(path + '/real_run'),
'reset_fields': addTokenToUrl(path + '/reset_fields'),
}
if field_config:
data['field_config'] = addTokenToUrl(
field_config.absolute_url(),
)
else:
data['field_config'] = None
for harv_id, harv in folder.contentItems():

data = self.read_harvester_info(harv)

self.data.append(data)

return super(HarvesterFolderView, self).__call__(*args, **kwargs)


class HarvesterOverview(BrowserView, HarvesterListViewMixin):
"""
Listing all Harvester Folders with included Harvester.
"""

def __call__(self, *args, **kwargs):
harvester_folder = get_all_harvester_folder()

self.data = []

for folder in harvester_folder:
harvester = folder.contentItems()
folder_data = []
for harv_id, harv in harvester:
data = self.read_harvester_info(harv)

folder_data.append(data)
self.data.append({
'title': folder.title,
'elements': folder_data,
'path': folder.absolute_url(),
})

return super(HarvesterOverview, self).__call__(*args, **kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<table>
<thead>
<tr>
<td i18n:translate="">Harvester</td>
<td i18n:translate="">Harvester</td>
<td i18n:translate="">Data Source</td>
<td i18n:translate="">Edit</td>
<td i18n:translate="">Dry Run</td>
<td i18n:translate="">Real Run</td>
<td i18n:translate="">Field Config</td>
Expand All @@ -21,6 +22,8 @@
tal:content="harv/title"></a></td>
<td><a tal:attributes="href harv/source_url"
tal:content="harv/source_url"></a></td>
<td><a i18n:translate=""
tal:attributes="href harv/edit">Edit Harvester</a></td>
<td><a i18n:translate=""
tal:attributes="href harv/dry_run">Dry Run</a></td>
<td><a i18n:translate=""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="pkan.dcatapde">
<body>
<metal:content-core fill-slot="content-core">
<div tal:repeat="folder view/data">
<h2 tal:content="folder/title"/>
<a tal:attributes="href folder/path" i18n:translate="">View</a>
<p i18n:translate="">Content:</p>
<table>
<thead>
<tr>
<td i18n:translate="">Harvester</td>
<td i18n:translate="">Data Source</td>
<td i18n:translate="">Edit</td>
<td i18n:translate="">Dry Run</td>
<td i18n:translate="">Real Run</td>
<td i18n:translate="">Field Config</td>
<td i18n:translate="">Reset Fields</td>
</tr>
</thead>
<tbody>
<tr tal:repeat="harv folder/elements">
<td><a tal:attributes="href harv/path"
tal:content="harv/title"></a></td>
<td><a tal:attributes="href harv/source_url"
tal:content="harv/source_url"></a></td>
<td><a i18n:translate=""
tal:attributes="href harv/edit">Edit Harvester</a></td>
<td><a i18n:translate=""
tal:attributes="href harv/dry_run">Dry Run</a></td>
<td><a i18n:translate=""
tal:attributes="href harv/real_run">Real Run</a></td>
<td><a tal:omit-tag="not:harv/field_config" i18n:translate=""
tal:attributes="href harv/field_config">Field Config</a></td>
<td><a i18n:translate=""
tal:attributes="href harv/reset_fields">Reset Fields</a></td>
</tr>
</tbody>
</table>
</div>
</metal:content-core>
</body>
</html>
7 changes: 0 additions & 7 deletions src/pkan/dcatapde/config/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@
template="templates/controlpanel.pt"
/>

<browser:page
class=".views.HarvesterView"
for="*"
name="harvester-config"
permission="cmf.ManagePortal"
/>

</configure>
41 changes: 0 additions & 41 deletions src/pkan/dcatapde/config/interfaces.py

This file was deleted.

Loading

0 comments on commit 7df53e9

Please sign in to comment.