def harvest_source_create(context, data_dict): log.info('Creating harvest source: %r', data_dict) check_access('harvest_source_create', context, data_dict) model = context['model'] session = context['session'] schema = context.get('schema') or default_harvest_source_schema() data, errors = validate(data_dict, schema) if errors: session.rollback() log.warn('Harvest source does not validate: %r', errors) raise ValidationError(errors, _error_summary(errors)) source = HarvestSource() source.url = data['url'].strip() source.type = data['type'] opt = [ 'active', 'title', 'description', 'user_id', 'publisher_id', 'config' ] for o in opt: if o in data and data[o] is not None: source.__setattr__(o, data[o]) if 'active' in data_dict: source.active = data['active'] source.save() log.info('Harvest source created: %s', source.id) return harvest_source_dictize(source, context)
def harvest_source_create(context,data_dict): log.info('Creating harvest source: %r', data_dict) check_access('harvest_source_create',context,data_dict) model = context['model'] session = context['session'] schema = context.get('schema') or default_harvest_source_schema() data, errors = validate(data_dict, schema) if errors: session.rollback() log.warn('Harvest source does not validate: %r', errors) raise ValidationError(errors,_error_summary(errors)) source = HarvestSource() source.url = data['url'].strip() source.type = data['type'] opt = ['active','title','description','user_id','publisher_id','config'] for o in opt: if o in data and data[o] is not None: source.__setattr__(o,data[o]) if 'active' in data_dict: source.active = data['active'] source.save() log.info('Harvest source created: %s', source.id) return harvest_source_dictize(source,context)
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
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() # Avoids clashes with the dataset type source.type = data_dict['source_type'] 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) return source
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() # Avoids clashes with the dataset type source.type = data_dict['source_type'] 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) return source