from sqlalchemy import distinct from ckan.model import Package from ckanext.harvest.model import HarvestSource, HarvestJob, HarvestObject, \ HarvestGatherError, HarvestObjectError def harvest_source_dictize(source, context): out = source.as_dict() out['jobs'] = [] for job in source.jobs: out['jobs'].append(job.as_dict()) out['status'] = _get_source_status(source, context) return out def harvest_job_dictize(job, context): out = job.as_dict() out['source'] = job.source_id out['objects'] = [] out['gather_errors'] = [] for obj in job.objects: out['objects'].append(obj.as_dict()) for error in job.gather_errors: out['gather_errors'].append(error.as_dict()) return out def harvest_object_dictize(obj, context): out = obj.as_dict() out['source'] = obj.harvest_source_id out['job'] = obj.harvest_job_id if obj.package: out['package'] = obj.package.id out['errors'] = [] for error in obj.errors: out['errors'].append(error.as_dict()) return out def _prettify(field_name): field_name = re.sub('(?