def vocabulary_update(context, data_dict): model = context['model'] vocab_id = data_dict.get('id') if not vocab_id: raise ValidationError({'id': _('id not in data')}) vocab = model.vocabulary.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict['id'] = vocab.id if data_dict.has_key('name'): if data_dict['name'] == vocab.name: del data_dict['name'] check_access('vocabulary_update', context, data_dict) schema = context.get('schema') or ckan.logic.schema.default_update_vocabulary_schema() data, errors = validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = model_save.vocabulary_dict_update(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.vocabulary_dictize(updated_vocab, context)
def vocabulary_update(context, data_dict): model = context["model"] vocab_id = data_dict.get("id") if not vocab_id: raise ValidationError({"id": _("id not in data")}) vocab = model.vocabulary.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict["id"] = vocab.id if data_dict.has_key("name"): if data_dict["name"] == vocab.name: del data_dict["name"] check_access("vocabulary_update", context, data_dict) schema = context.get("schema") or default_update_vocabulary_schema() data, errors = validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = vocabulary_dict_update(data, context) if not context.get("defer_commit"): model.repo.commit() return vocabulary_dictize(updated_vocab, context)
def vocabulary_update(context, data_dict): model = context['model'] vocab_id = data_dict.get('id') if not vocab_id: raise ValidationError({'id': _('id not in data')}) vocab = model.vocabulary.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict['id'] = vocab.id if data_dict.has_key('name'): if data_dict['name'] == vocab.name: del data_dict['name'] check_access('vocabulary_update', context, data_dict) schema = context.get( 'schema') or ckan.logic.schema.default_update_vocabulary_schema() data, errors = validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = model_save.vocabulary_dict_update(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.vocabulary_dictize(updated_vocab, context)
def vocabulary_update(context: Context, data_dict: DataDict) -> ActionResult.VocabularyUpdate: '''Update a tag vocabulary. You must be a sysadmin to update vocabularies. For further parameters see :py:func:`~ckan.logic.action.create.vocabulary_create`. :param id: the id of the vocabulary to update :type id: string :returns: the updated vocabulary :rtype: dictionary ''' model = context['model'] vocab_id = data_dict.get('id') if not vocab_id: raise ValidationError({'id': _('id not in data')}) vocab = model.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict['id'] = vocab.id if 'name' in data_dict: if data_dict['name'] == vocab.name: del data_dict['name'] _check_access('vocabulary_update', context, data_dict) schema = context.get( 'schema') or schema_.default_update_vocabulary_schema() data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = model_save.vocabulary_dict_update(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.vocabulary_dictize(updated_vocab, context)
def vocabulary_update(context, data_dict): '''Update a tag vocabulary. You must be a sysadmin to update vocabularies. For further parameters see :py:func:`~ckan.logic.action.create.vocabulary_create`. :param id: the id of the vocabulary to update :type id: string :returns: the updated vocabulary :rtype: dictionary ''' model = context['model'] vocab_id = data_dict.get('id') if not vocab_id: raise ValidationError({'id': _('id not in data')}) vocab = model.vocabulary.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict['id'] = vocab.id if data_dict.has_key('name'): if data_dict['name'] == vocab.name: del data_dict['name'] _check_access('vocabulary_update', context, data_dict) schema = context.get('schema') or schema_.default_update_vocabulary_schema() data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = model_save.vocabulary_dict_update(data, context) if not context.get('defer_commit'): model.repo.commit() return model_dictize.vocabulary_dictize(updated_vocab, context)
def vocabulary_update(context, data_dict): """Update a tag vocabulary. You must be a sysadmin to update vocabularies. For further parameters see ``vocabulary_create()``. :param id: the id of the vocabulary to update :type id: string :returns: the updated vocabulary :rtype: dictionary """ model = context["model"] vocab_id = data_dict.get("id") if not vocab_id: raise ValidationError({"id": _("id not in data")}) vocab = model.vocabulary.Vocabulary.get(vocab_id) if vocab is None: raise NotFound(_('Could not find vocabulary "%s"') % vocab_id) data_dict["id"] = vocab.id if data_dict.has_key("name"): if data_dict["name"] == vocab.name: del data_dict["name"] _check_access("vocabulary_update", context, data_dict) schema = context.get("schema") or ckan.logic.schema.default_update_vocabulary_schema() data, errors = _validate(data_dict, schema, context) if errors: model.Session.rollback() raise ValidationError(errors) updated_vocab = model_save.vocabulary_dict_update(data, context) if not context.get("defer_commit"): model.repo.commit() return model_dictize.vocabulary_dictize(updated_vocab, context)