def _create_harvest_source_object(context, data_dict): ''' Creates an actual HarvestSource object with the data dict of the harvest_source dataset. All validation and authorization checks should be used by now, so this function is not to be used directly to create harvest sources. The created harvest source will have the same id as the dataset. :param data_dict: A standard package data_dict :returns: The created HarvestSource object :rtype: HarvestSource object ''' log.info('Creating harvest source: %r', data_dict) source = HarvestSource() source.id = data_dict['id'] source.url = data_dict['url'].strip() source.catalogue_country=data_dict['catalogue_country'] source.language=data_dict['language'] source.catalogue_date_created=data_dict['catalogue_date_created'] source.catalogue_date_updated=data_dict['catalogue_date_updated'] # Avoids clashes with the dataset type source.type = data_dict['source_type'] #source.country=data['country'] opt = ['active', 'title', 'description', 'user_id', 'publisher_id', 'config', 'frequency'] for o in opt: if o in data_dict and data_dict[o] is not None: source.__setattr__(o,data_dict[o]) source.active = not data_dict.get('state', None) == 'deleted' # Don't commit yet, let package_create do it source.add() log.info('Harvest source created: %s', source.id) ##---------------save job to mongodb-------- client=pymongo.MongoClient(str(mongoclient),int(mongoport)) job={"cat_url":str(source.url),"type":str(source.type),"id":str(source.id),"description":str(source.description),"frequency":str(source.frequency),"title":str(source.title),'country':str(source.catalogue_country),'language':str(source.language),'catalogue_date_created':str(source.catalogue_date_created),'catalogue_date_updated':str(source.catalogue_date_updated)} db=client.odm collection=db.jobs collection.save(job) return source