flask_taxonomies/views/taxonomy_term.py
def taxonomy_move_term(code=None, slug=None, prefer=None, page=None, size=None, destination='',
                       rename='', q=None):
    """Move term into a new parent or rename it."""
    if q:
        json_abort(422, {
            'message': 'Query not appropriate when moving term',
            'reason': 'search-query-not-allowed'
        })

    try:
        taxonomy = current_flask_taxonomies.get_taxonomy(code)
        ti = TermIdentification(taxonomy=taxonomy, slug=slug)
        term = current_flask_taxonomies.filter_term(ti).one()

        current_flask_taxonomies.permissions.taxonomy_term_move.enforce(
            request=request, taxonomy=taxonomy, term=term,
            destination=destination, rename=rename)
    except NoResultFound as e:
        return json_abort(404, {})

    if destination:
        if destination.startswith('http'):
            destination_path = urlparse(destination).path
            url_prefix = current_app.config['FLASK_TAXONOMIES_URL_PREFIX']
            if not destination_path.startswith(url_prefix):
                abort(400,
                      'Destination not part of this server as it '
                      'does not start with config.FLASK_TAXONOMIES_URL_PREFIX')
            destination_path = destination_path[len(url_prefix):]
            destination_path = destination_path.split('/', maxsplit=1)
            if len(destination_path) > 1:
                destination_taxonomy, destination_slug = destination_path
            else:
                destination_taxonomy = destination_path[0]
                destination_slug = None
        else:
            destination_taxonomy = code
            destination_slug = destination
            if destination_slug.startswith('/'):
                destination_slug = destination_slug[1:]
        if not current_flask_taxonomies.filter_term(
                TermIdentification(taxonomy=code, slug=slug)).count():
            abort(404, 'Term %s/%s does not exist' % (code, slug))

        try:
            old_term, new_term = current_flask_taxonomies.move_term(
                TermIdentification(taxonomy=code, slug=slug),
                new_parent=TermIdentification(taxonomy=destination_taxonomy,
                                              slug=destination_slug) if destination_slug else '',
                remove_after_delete=False)  # do not remove the original node from the database,
            # just mark it as deleted
        except TaxonomyTermBusyError as e:
            return json_abort(412, {
                'message': str(e),
                'reason': 'term-busy'
            })
    elif rename:
        new_slug = slug
        if new_slug.endswith('/'):
            new_slug = new_slug[:-1]
        if '/' in new_slug:
            new_slug = new_slug.rsplit('/')[0]
            new_slug = new_slug + '/' + rename
        else:
            new_slug = rename
        try:
            old_term, new_term = current_flask_taxonomies.rename_term(
                TermIdentification(taxonomy=code, slug=slug),
                new_slug=new_slug,
                remove_after_delete=False)  # do not remove the original node from the database, just mark it as deleted
        except TaxonomyTermBusyError as e:
            return json_abort(412, {
                'message': str(e),
                'reason': 'term-busy'
            })
        destination_taxonomy = code
    else:
        abort(400, 'Pass either `destination` or `rename` parameters ')
        return  # just to make pycharm happy

    current_flask_taxonomies.commit()

    return get_taxonomy_term(code=destination_taxonomy, slug=new_term.slug,
                             prefer=prefer, page=page, size=size)
Move term into a new parent or rename it.
Move term into a new parent or rename it.
Move term into a new parent or rename it .
def taxonomy_move_term(code=None, slug=None, prefer=None, page=None, size=None, destination='',
                       rename='', q=None):
    if q:
        json_abort(422, {
            'message': 'Query not appropriate when moving term',
            'reason': 'search-query-not-allowed'
        })
    try:
        taxonomy = current_flask_taxonomies.get_taxonomy(code)
        ti = TermIdentification(taxonomy=taxonomy, slug=slug)
        term = current_flask_taxonomies.filter_term(ti).one()
        current_flask_taxonomies.permissions.taxonomy_term_move.enforce(
            request=request, taxonomy=taxonomy, term=term,
            destination=destination, rename=rename)
    except NoResultFound as e:
        return json_abort(404, {})
    if destination:
        if destination.startswith('http'):
            destination_path = urlparse(destination).path
            url_prefix = current_app.config['FLASK_TAXONOMIES_URL_PREFIX']
            if not destination_path.startswith(url_prefix):
                abort(400,
                      'Destination not part of this server as it '
                      'does not start with config.FLASK_TAXONOMIES_URL_PREFIX')
            destination_path = destination_path[len(url_prefix):]
            destination_path = destination_path.split('/', maxsplit=1)
            if len(destination_path) > 1:
                destination_taxonomy, destination_slug = destination_path
            else:
                destination_taxonomy = destination_path[0]
                destination_slug = None
        else:
            destination_taxonomy = code
            destination_slug = destination
            if destination_slug.startswith('/'):
                destination_slug = destination_slug[1:]
        if not current_flask_taxonomies.filter_term(
                TermIdentification(taxonomy=code, slug=slug)).count():
            abort(404, 'Term %s/%s does not exist' % (code, slug))
        try:
            old_term, new_term = current_flask_taxonomies.move_term(
                TermIdentification(taxonomy=code, slug=slug),
                new_parent=TermIdentification(taxonomy=destination_taxonomy,
                                              slug=destination_slug) if destination_slug else '',
                remove_after_delete=False)  
        except TaxonomyTermBusyError as e:
            return json_abort(412, {
                'message': str(e),
                'reason': 'term-busy'
            })
    elif rename:
        new_slug = slug
        if new_slug.endswith('/'):
            new_slug = new_slug[:-1]
        if '/' in new_slug:
            new_slug = new_slug.rsplit('/')[0]
            new_slug = new_slug + '/' + rename
        else:
            new_slug = rename
        try:
            old_term, new_term = current_flask_taxonomies.rename_term(
                TermIdentification(taxonomy=code, slug=slug),
                new_slug=new_slug,
                remove_after_delete=False)   just mark it as deleted
        except TaxonomyTermBusyError as e:
            return json_abort(412, {
                'message': str(e),
                'reason': 'term-busy'
            })
        destination_taxonomy = code
    else:
        abort(400, 'Pass either `destination` or `rename` parameters ')
        return  
    current_flask_taxonomies.commit()
    return get_taxonomy_term(code=destination_taxonomy, slug=new_term.slug,
                             prefer=prefer, page=page, size=size)
def taxonomy_move_term ( code = None , slug = None , prefer = None , page = None , size = None , destination = '' , rename = '' , q = None ) : if q : json_abort ( 422 , { 'message' : 'Query not appropriate when moving term' , 'reason' : 'search-query-not-allowed' } ) try : taxonomy = current_flask_taxonomies . get_taxonomy ( code ) ti = TermIdentification ( taxonomy = taxonomy , slug = slug ) term = current_flask_taxonomies . filter_term ( ti ) . one ( ) current_flask_taxonomies . permissions . taxonomy_term_move . enforce ( request = request , taxonomy = taxonomy , term = term , destination = destination , rename = rename ) except NoResultFound as e : return json_abort ( 404 , { } ) if destination : if destination . startswith ( 'http' ) : destination_path = urlparse ( destination ) . path url_prefix = current_app . config [ 'FLASK_TAXONOMIES_URL_PREFIX' ] if not destination_path . startswith ( url_prefix ) : abort ( 400 , 'Destination not part of this server as it ' 'does not start with config.FLASK_TAXONOMIES_URL_PREFIX' ) destination_path = destination_path [ len ( url_prefix ) : ] destination_path = destination_path . split ( '/' , maxsplit = 1 ) if len ( destination_path ) > 1 : destination_taxonomy , destination_slug = destination_path else : destination_taxonomy = destination_path [ 0 ] destination_slug = None else : destination_taxonomy = code destination_slug = destination if destination_slug . startswith ( '/' ) : destination_slug = destination_slug [ 1 : ] if not current_flask_taxonomies . filter_term ( TermIdentification ( taxonomy = code , slug = slug ) ) . count ( ) : abort ( 404 , 'Term %s/%s does not exist' % ( code , slug ) ) try : old_term , new_term = current_flask_taxonomies . move_term ( TermIdentification ( taxonomy = code , slug = slug ) , new_parent = TermIdentification ( taxonomy = destination_taxonomy , slug = destination_slug ) if destination_slug else '' , remove_after_delete = False ) except TaxonomyTermBusyError as e : return json_abort ( 412 , { 'message' : str ( e ) , 'reason' : 'term-busy' } ) elif rename : new_slug = slug if new_slug . endswith ( '/' ) : new_slug = new_slug [ : - 1 ] if '/' in new_slug : new_slug = new_slug . rsplit ( '/' ) [ 0 ] new_slug = new_slug + '/' + rename else : new_slug = rename try : old_term , new_term = current_flask_taxonomies . rename_term ( TermIdentification ( taxonomy = code , slug = slug ) , new_slug = new_slug , remove_after_delete = False ) except TaxonomyTermBusyError as e : return json_abort ( 412 , { 'message' : str ( e ) , 'reason' : 'term-busy' } ) destination_taxonomy = code else : abort ( 400 , 'Pass either `destination` or `rename` parameters ' ) return current_flask_taxonomies . commit ( ) return get_taxonomy_term ( code = destination_taxonomy , slug = new_term . slug , prefer = prefer , page = page , size = size )
Move term into a new parent or rename it.
Move term into a new parent or rename it .
"""Move term into a new parent or rename it.""" # do not remove the original node from the database, # just mark it as deleted # do not remove the original node from the database, just mark it as deleted # just to make pycharm happy
code
slug
prefer
page
size
destination
rename
q