Added harvest_log_list get action

This commit is contained in:
Petar Efnushev 2016-04-05 23:53:14 +02:00
parent a79ad2e325
commit 97cd64b172
2 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import logging
from itertools import groupby
from sqlalchemy import or_
from ckan.model import User
import datetime
@ -12,10 +13,11 @@ from ckan.logic import NotFound, check_access, side_effect_free
from ckanext.harvest import model as harvest_model
from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject)
from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject, HarvestLog)
from ckanext.harvest.logic.dictization import (harvest_source_dictize,
harvest_job_dictize,
harvest_object_dictize)
harvest_object_dictize,
harvest_log_dictize)
log = logging.getLogger(__name__)
@ -310,6 +312,38 @@ def harvesters_info_show(context,data_dict):
return available_harvesters
@side_effect_free
def harvest_log_list(context,data_dict):
'''Returns a list of harvester log entries grouped by level.
:param per_page: number of logs to be shown default: 100
:param offset: use with ``per_page`` default: 0
:param level: filter log entries by level(debug, info, warning, error, critical)
'''
check_access('harvest_log_list', context, data_dict)
model = context['model']
session = context['session']
per_page = data_dict.get('per_page', 100)
offset = data_dict.get('offset', 0)
level = data_dict.get('level', False)
query = session.query(HarvestLog)
if level:
query = query.filter(HarvestLog.level==level.upper())
query = query.order_by(HarvestLog.level.desc(), HarvestLog.created.desc())
logs = query.offset(offset).limit(per_page).all()
out = dict()
for k, g in groupby(logs, lambda l: l.level):
out.update({k: [harvest_log_dictize(obj, context) for obj in g]})
return out
def _get_sources_for_user(context,data_dict):
model = context['model']

View File

@ -97,6 +97,8 @@ def harvest_object_dictize(obj, context):
return out
def harvest_log_dictize(obj, context):
return obj.as_dict()
def _get_source_status(source, context):
'''