Example #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()
Example #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()