Esempio n. 1
0
def taxonomy_term_create(context, data_dict):
    """ Allows for the creation of a new taxonomy term.

    :returns: The newly updated term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_create', context, data_dict)
    model = context['model']

    taxonomy_id = logic.get_or_bust(data_dict, 'taxonomy_id')
    taxonomy = logic.get_action('taxonomy_show')(context, {'id': taxonomy_id})

    label = logic.get_or_bust(data_dict, 'label')
    uri = logic.get_or_bust(data_dict, 'uri')
    description = data_dict.get('description')

    if model.Session.query(TaxonomyTerm).\
            filter(TaxonomyTerm.uri == uri).\
            filter(TaxonomyTerm.taxonomy_id == taxonomy_id ).count() > 0:
        raise logic.ValidationError("Term uri already used in this taxonomy")

    term = TaxonomyTerm(**data_dict)
    model.Session.add(term)
    model.Session.commit()

    return term.as_dict()
Esempio n. 2
0
def taxonomy_term_create(context, data_dict):
    """ Allows for the creation of a new taxonomy term.

    :returns: The newly updated term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_create', context, data_dict)
    model = context['model']

    taxonomy_id = logic.get_or_bust(data_dict, 'taxonomy_id')
    taxonomy = logic.get_action('taxonomy_show')(context, {'id': taxonomy_id})

    label = logic.get_or_bust(data_dict, 'label')
    uri = logic.get_or_bust(data_dict, 'uri')
    description = data_dict.get('description')

    if model.Session.query(TaxonomyTerm).\
            filter(TaxonomyTerm.uri == uri).\
            filter(TaxonomyTerm.taxonomy_id == taxonomy_id ).count() > 0:
        raise logic.ValidationError("Term uri already used in this taxonomy")

    term = TaxonomyTerm(**data_dict)
    model.Session.add(term)
    model.Session.commit()

    return term.as_dict()
Esempio n. 3
0
def taxonomy_term_show_all(context, data_dict):
    """
    Shows a single taxonomy term and its children, the taxonomy id is not
    required, just a term_id.

    :returns: A single taxonomy term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_show', context, data_dict)

    label = data_dict.get('label')
    taxonomy_id = data_dict.get('taxonomy_id')

    if not label:
        raise logic.ValidationError("Either id, uri or label is required")

    if (taxonomy_id):
        term = TaxonomyTerm.get_from_taxonomy(label, taxonomy_id)
    else:
        term = TaxonomyTerm.get_all(label)

    if not term:
        raise logic.NotFound()

    return [u.as_dict() for u in term]
Esempio n. 4
0
def taxonomy_term_update(context, data_dict):
    """ Allows a taxonomy term to be updated.

    :returns: The newly updated term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_update', context, data_dict)
    model = context['model']

    id = logic.get_or_bust(data_dict, 'id')

    term = TaxonomyTerm.get(id)
    if not term:
        raise logic.NotFound()

    term.label = data_dict.get('label', term.label)
    term.parent_id = data_dict.get('parent_id', term.parent_id)
    term.uri = logic.get_or_bust(data_dict, 'uri')
    term.description = data_dict.get('description', '')
    term.extras = data_dict.get('extras', '')

    model.Session.add(term)
    model.Session.commit()

    return term.as_dict()
Esempio n. 5
0
def taxonomy_term_update(context, data_dict):
    """ Allows a taxonomy term to be updated.

    :returns: The newly updated term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_update', context, data_dict)
    model = context['model']

    id = logic.get_or_bust(data_dict, 'id')

    term = TaxonomyTerm.get(id)
    if not term:
        raise logic.NotFound()

    term.label = data_dict.get('label', term.label)
    term.parent_id = data_dict.get('parent_id', term.parent_id)
    term.uri = logic.get_or_bust(data_dict, 'uri')
    term.description = data_dict.get('description', '')
    term.extras = data_dict.get('extras', '')

    model.Session.add(term)
    model.Session.commit()

    return term.as_dict()
Esempio n. 6
0
def taxonomy_term_show(context, data_dict):
    """
    Shows a single taxonomy term and its children, the taxonomy id is not
    required, just a term_id.

    :returns: A single taxonomy term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_show', context, data_dict)
    model = context['model']

    id = data_dict.get('id')
    uri = data_dict.get('uri')

    if not id and not uri:
        raise logic.ValidationError("Either id or uri is required")

    term = TaxonomyTerm.get(id or uri)
    if not term:
        raise logic.NotFound()

    return term.as_dict()
Esempio n. 7
0
def taxonomy_term_show(context, data_dict):
    """
    Shows a single taxonomy term and its children, the taxonomy id is not
    required, just a term_id.

    :returns: A single taxonomy term
    :rtype: A dictionary
    """
    _check_access('taxonomy_term_show', context, data_dict)
    model = context['model']

    id = data_dict.get('id')
    uri = data_dict.get('uri')

    if not id and not uri:
        raise logic.ValidationError("Either id or uri is required")

    term = TaxonomyTerm.get(id or uri)
    if not term:
        raise logic.NotFound()

    return term.as_dict()