def register_harvesting_job(self, source_id, user_ref): from ckan.model import HarvestSource from ckan.model import HarvestingJob if re.match("(http|file)://", source_id): source_url = unicode(source_id) source_id = None sources = HarvestSource.filter(url=source_url).all() if sources: source = sources[0] else: source = self.create_harvest_source(url=source_url, user_ref=user_ref, publisher_ref=u"") else: source = HarvestSource.get(source_id) job = HarvestingJob(source=source, user_ref=user_ref, status=u"New") job.save() print "Created new harvesting job:" self.print_harvesting_job(job) status = u"New" jobs = HarvestingJob.filter(status=status).all() self.print_there_are("harvesting job", jobs, condition=status)
def create_harvesting_job(self, **kwds): from ckan.model import HarvestingJob job = HarvestingJob(**kwds) job.save() return job