Ejemplo n.º 1
0
    def initial_data(self, clean_db, app):
        self.app = app
        model = ckan.model
        context = {"model": model}

        genre = model.Vocabulary("Genre")
        time_period = ckan.model.Vocabulary("Time Period")
        composers = ckan.model.Vocabulary("Composers")
        model.Session.add_all([genre, time_period, composers])

        self.genre_vocab = model_dictize.vocabulary_dictize(genre, context)
        self.timeperiod_vocab = model_dictize.vocabulary_dictize(
            time_period, context)
        self.composers_vocab = model_dictize.vocabulary_dictize(
            composers, context)
        ckan.model.Session.commit()

        self.sysadmin_user = ckan.model.User.get("admin")
        self.normal_user = ckan.model.User.get("normal")
        if not self.sysadmin_user:
            normal_user = ckan.model.User(name=u"normal", password=u"annafan")
            sysadmin_user = ckan.model.User(name=u"admin",
                                            password=u"testsysadmin")
            sysadmin_user.sysadmin = True
            ckan.model.Session.add(normal_user)
            ckan.model.Session.add(sysadmin_user)
            ckan.model.Session.commit()
            self.sysadmin_user = ckan.model.User.get("admin")
            self.normal_user = ckan.model.User.get("normal")
        self.sysadmin_apikey = self.sysadmin_user.apikey
Ejemplo n.º 2
0
    def setup(self):
        self.clean_vocab()
        model = ckan.model
        context = {'model': model}

        genre = model.Vocabulary("Genre")
        time_period = ckan.model.Vocabulary("Time Period")
        composers = ckan.model.Vocabulary("Composers")
        model.Session.add_all([genre, time_period, composers])

        self.genre_vocab = model_dictize.vocabulary_dictize(genre, context)
        self.timeperiod_vocab = model_dictize.vocabulary_dictize(time_period, context)
        self.composers_vocab = model_dictize.vocabulary_dictize(composers, context)
        ckan.model.Session.commit()

        self.sysadmin_user = ckan.model.User.get('admin')
        self.normal_user = ckan.model.User.get('normal')
        if not self.sysadmin_user:
            normal_user = ckan.model.User(name=u'normal', password=u'annafan')
            sysadmin_user = ckan.model.User(name=u'admin', password=u'testsysadmin')
            ckan.model.Session.add(normal_user)
            ckan.model.Session.add(sysadmin_user)
            ckan.model.add_user_to_role(sysadmin_user, ckan.model.Role.ADMIN, ckan.model.System())
            ckan.model.Session.commit()
            self.sysadmin_user = ckan.model.User.get('admin')
            self.normal_user = ckan.model.User.get('normal')
Ejemplo n.º 3
0
    def setup(self):
        self.clean_vocab()
        model = ckan.model
        context = {'model': model}

        genre = model.Vocabulary("Genre")
        time_period = ckan.model.Vocabulary("Time Period")
        composers = ckan.model.Vocabulary("Composers")
        model.Session.add_all([genre, time_period, composers])

        self.genre_vocab = model_dictize.vocabulary_dictize(genre, context)
        self.timeperiod_vocab = model_dictize.vocabulary_dictize(
            time_period, context)
        self.composers_vocab = model_dictize.vocabulary_dictize(
            composers, context)
        ckan.model.Session.commit()

        self.sysadmin_user = ckan.model.User.get('admin')
        self.normal_user = ckan.model.User.get('normal')
        if not self.sysadmin_user:
            normal_user = ckan.model.User(name=u'normal', password=u'annafan')
            sysadmin_user = ckan.model.User(name=u'admin',
                                            password=u'testsysadmin')
            ckan.model.Session.add(normal_user)
            ckan.model.Session.add(sysadmin_user)
            ckan.model.add_user_to_role(sysadmin_user, ckan.model.Role.ADMIN,
                                        ckan.model.System())
            ckan.model.Session.commit()
            self.sysadmin_user = ckan.model.User.get('admin')
            self.normal_user = ckan.model.User.get('normal')
Ejemplo n.º 4
0
    def setup(self):
        self.clean_vocab()
        model = ckan.model
        context = {"model": model}

        genre = model.Vocabulary("Genre")
        time_period = ckan.model.Vocabulary("Time Period")
        composers = ckan.model.Vocabulary("Composers")
        model.Session.add_all([genre, time_period, composers])

        self.genre_vocab = model_dictize.vocabulary_dictize(genre, context)
        self.timeperiod_vocab = model_dictize.vocabulary_dictize(time_period, context)
        self.composers_vocab = model_dictize.vocabulary_dictize(composers, context)
        ckan.model.Session.commit()

        self.sysadmin_user = ckan.model.User.get("admin")
        self.normal_user = ckan.model.User.get("normal")
        if not self.sysadmin_user:
            normal_user = ckan.model.User(name=u"normal", password=u"annafan")
            sysadmin_user = ckan.model.User(name=u"admin", password=u"testsysadmin")
            sysadmin_user.sysadmin = True
            ckan.model.Session.add(normal_user)
            ckan.model.Session.add(sysadmin_user)
            ckan.model.Session.commit()
            self.sysadmin_user = ckan.model.User.get("admin")
            self.normal_user = ckan.model.User.get("normal")
        self.sysadmin_apikey = self.sysadmin_user.apikey
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def vocabulary_create(context, data_dict):

    model = context['model']
    schema = context.get(
        'schema') or ckan.logic.schema.default_create_vocabulary_schema()

    model.Session.remove()
    model.Session()._context = context

    check_access('vocabulary_create', context, data_dict)

    data, errors = validate(data_dict, schema, context)

    if errors:
        model.Session.rollback()
        raise ValidationError(errors, error_summary(errors))

    vocabulary = model_save.vocabulary_dict_save(data, context)

    if not context.get('defer_commit'):
        model.repo.commit()

    log.debug('Created Vocabulary %s' % str(vocabulary.name))

    return model_dictize.vocabulary_dictize(vocabulary, context)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
Archivo: update.py Proyecto: zydio/ckan
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)
Ejemplo n.º 9
0
def vocabulary_create(context, data_dict):
    '''Create a new tag vocabulary.

    You must be a sysadmin to create vocabularies.

    :param name: the name of the new vocabulary, e.g. ``'Genre'``
    :type name: string
    :param tags: the new tags to add to the new vocabulary, for the format of
        tag dictionaries see ``tag_create()``
    :type tags: list of tag dictionaries

    :returns: the newly-created vocabulary
    :rtype: dictionary

    '''
    model = context['model']
    schema = context.get(
        'schema') or ckan.logic.schema.default_create_vocabulary_schema()

    _check_access('vocabulary_create', context, data_dict)

    data, errors = _validate(data_dict, schema, context)

    if errors:
        model.Session.rollback()
        raise ValidationError(errors)

    vocabulary = model_save.vocabulary_dict_save(data, context)

    if not context.get('defer_commit'):
        model.repo.commit()

    log.debug('Created Vocabulary %s' % vocabulary.name)

    return model_dictize.vocabulary_dictize(vocabulary, context)
Ejemplo n.º 10
0
def vocabulary_create(context, data_dict):
    '''Create a new tag vocabulary.

    You must be a sysadmin to create vocabularies.

    :param name: the name of the new vocabulary, e.g. ``'Genre'``
    :type name: string
    :param tags: the new tags to add to the new vocabulary, for the format of
        tag dictionaries see ``tag_create()``
    :type tags: list of tag dictionaries

    :returns: the newly-created vocabulary
    :rtype: dictionary

    '''
    model = context['model']
    schema = context.get('schema') or ckan.logic.schema.default_create_vocabulary_schema()

    _check_access('vocabulary_create', context, data_dict)

    data, errors = _validate(data_dict, schema, context)

    if errors:
        model.Session.rollback()
        raise ValidationError(errors)

    vocabulary = model_save.vocabulary_dict_save(data, context)

    if not context.get('defer_commit'):
        model.repo.commit()

    log.debug('Created Vocabulary %s' % str(vocabulary.name))

    return model_dictize.vocabulary_dictize(vocabulary, context)
Ejemplo n.º 11
0
def vocabulary_show(context, data_dict):
    model = context['model']
    vocab_id = data_dict.get('id')
    if not vocab_id:
        raise ValidationError({'id': _('id not in data')})
    vocabulary = model.vocabulary.Vocabulary.get(vocab_id)
    if vocabulary is None:
        raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
    vocabulary_dict = model_dictize.vocabulary_dictize(vocabulary, context)
    return vocabulary_dict
Ejemplo n.º 12
0
def vocabulary_show(context, data_dict):
    model = context['model']
    vocab_id = data_dict.get('id')
    if not vocab_id:
        raise ValidationError({'id': _('id not in data')})
    vocabulary = model.vocabulary.Vocabulary.get(vocab_id)
    if vocabulary is None:
        raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
    vocabulary_dict = model_dictize.vocabulary_dictize(vocabulary, context)
    return vocabulary_dict
    def test_vocabulary_dictize_not_including_datasets(self):
        """By default datasets should not be included in vocab dicts."""
        vocab_dict = factories.Vocabulary(
            tags=[dict(name="test_tag_1"), dict(name="test_tag_2")])
        factories.Dataset(tags=vocab_dict["tags"])
        vocab_obj = model.Vocabulary.get(vocab_dict["name"])

        vocab_dict = model_dictize.vocabulary_dictize(
            vocab_obj, context={"model": model})

        assert len(vocab_dict["tags"]) == 2
        for tag in vocab_dict["tags"]:
            assert len(tag.get("packages", [])) == 0
    def test_vocabulary_dictize_including_datasets(self):
        """include_datasets=True should include datasets in vocab dicts."""
        vocab_dict = factories.Vocabulary(
            tags=[dict(name="test_tag_1"), dict(name="test_tag_2")])
        factories.Dataset(tags=vocab_dict["tags"])
        vocab_obj = model.Vocabulary.get(vocab_dict["name"])

        vocab_dict = model_dictize.vocabulary_dictize(
            vocab_obj, context={"model": model}, include_datasets=True)

        assert len(vocab_dict["tags"]) == 2
        for tag in vocab_dict["tags"]:
            assert len(tag["packages"]) == 1
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
Archivo: create.py Proyecto: zydio/ckan
def vocabulary_create(context, data_dict):

    model = context['model']
    schema = context.get('schema') or default_create_vocabulary_schema()

    model.Session.remove()
    model.Session()._context = context

    check_access('vocabulary_create', context, data_dict)

    data, errors = validate(data_dict, schema, context)

    if errors:
        model.Session.rollback()
        raise ValidationError(errors, package_error_summary(errors))

    vocabulary = vocabulary_dict_save(data, context)

    if not context.get('defer_commit'):
        model.repo.commit()

    log.debug('Created Vocabulary %s' % str(vocabulary.name))
  
    return vocabulary_dictize(vocabulary, context)
Ejemplo n.º 19
0
def vocabulary_create(context, data_dict):

    model = context["model"]
    schema = context.get("schema") or ckan.logic.schema.default_create_vocabulary_schema()

    model.Session.remove()
    model.Session()._context = context

    check_access("vocabulary_create", context, data_dict)

    data, errors = validate(data_dict, schema, context)

    if errors:
        model.Session.rollback()
        raise ValidationError(errors, error_summary(errors))

    vocabulary = model_save.vocabulary_dict_save(data, context)

    if not context.get("defer_commit"):
        model.repo.commit()

    log.debug("Created Vocabulary %s" % str(vocabulary.name))

    return model_dictize.vocabulary_dictize(vocabulary, context)