<commit_before>import json
import string
from collections import deque

try:
    import networkx as nx
except ImportError:
    pass

from django.http import HttpResponse

from catmaid.control.object import get_annotation_graph

from catmaid.models import *
from catmaid.control.authentication import *
from catmaid.control.common import *


@requires_user_role(UserRole.Annotate)
def instance_operation(request, project_id=None):
    params = {}
    int_keys = ('id', 'src', 'ref', 'parentid', 'relationnr')
    str_keys = ('title', 'operation', 'title', 'rel', 'classname', 'relationname', 'objname', 'targetname')
    for k in int_keys:
        params[k] = int(request.POST.get(k, 0))
    for k in str_keys:
        # TODO sanitize
        params[k] = request.POST.get(k, 0)
 
    relation_map = get_relation_to_id_map(project_id)
    class_map = get_class_to_id_map(project_id)

    # We avoid many try/except clauses by setting this string to be the
    # response we return if an exception is thrown.
    instance_operation.res_on_err = ''

    def remove_skeletons(skeleton_id_list):
        if request.user.is_superuser:
            instance_operation.res_on_err = 'Failed to delete in treenode for skeletons #%s' % skeleton_id_list
            Treenode.objects.filter(
                    project=project_id,
                    skeleton__in=skeleton_id_list).delete()

            instance_operation.res_on_err = 'Failed to delete in treenode_connector for skeletons #%s' % skeleton_id_list
            TreenodeConnector.objects.filter(
                    project=project_id,
                    skeleton__in=skeleton_id_list).delete()

            instance_operation.res_on_err = 'Failed to delete in class_instance for skeletons #%s' % skeleton_id_list<commit_msg>Added TODO to tree.py remove_skeletons<commit_after>import json
import string
from collections import deque

try:
    import networkx as nx
except ImportError:
    pass

from django.http import HttpResponse

from catmaid.control.object import get_annotation_graph

from catmaid.models import *
from catmaid.control.authentication import *
from catmaid.control.common import *


@requires_user_role(UserRole.Annotate)
def instance_operation(request, project_id=None):
    params = {}
    int_keys = ('id', 'src', 'ref', 'parentid', 'relationnr')
    str_keys = ('title', 'operation', 'title', 'rel', 'classname', 'relationname', 'objname', 'targetname')
    for k in int_keys:
        params[k] = int(request.POST.get(k, 0))
    for k in str_keys:
        # TODO sanitize
        params[k] = request.POST.get(k, 0)
 
    relation_map = get_relation_to_id_map(project_id)
    class_map = get_class_to_id_map(project_id)

    # We avoid many try/except clauses by setting this string to be the
    # response we return if an exception is thrown.
    instance_operation.res_on_err = ''

    def remove_skeletons(skeleton_id_list):
        if request.user.is_superuser:
            instance_operation.res_on_err = 'Failed to delete in treenode for skeletons #%s' % skeleton_id_list
            # TODO this failed at least once, whereas direct deletion of a single skeleton by skeleton_id on the treenode table succeeded. Inspect!
            Treenode.objects.filter(
                    project=project_id,
                    skeleton__in=skeleton_id_list).delete()

            instance_operation.res_on_err = 'Failed to delete in treenode_connector for skeletons #%s' % skeleton_id_list
            TreenodeConnector.objects.filter(
                    project=project_id,
                    skeleton__in=skeleton_id_list).delete()

            instance_operation.res_on_err = 'Failed to delete in class_instance for skeletons #%s' % skeleton_id_list
{'fraction_non_alphanumeric': 0.08348993288590605, 'fraction_numerical': 0.0010738255033557046, 'mean_word_length': 3.2485746864310148, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3509585', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1091, 'n_words': 292}