コード例 #1
0
def label_update(request,
                 project_id=None,
                 location_id=None,
                 ntype=None,
                 logged_in_user=None):
    labeled_as_relation = Relation.objects.get(project=project_id,
                                               relation_name='labeled_as')
    p = get_object_or_404(Project, pk=project_id)
    if ntype == 'treenode':
        TreenodeClassInstance.objects.filter(
            treenode__id=location_id,
            relation=labeled_as_relation,
            class_instance__class_column__class_name='label').delete()
    elif ntype == 'connector' or ntype == 'location':
        ConnectorClassInstance.objects.filter(
            connector__id=location_id,
            relation=labeled_as_relation,
            class_instance__class_column__class_name='label').delete()
    else:
        raise Http404('Unknown node type: "%s"' % (ntype, ))
    label_class = Class.objects.get(project=project_id, class_name='label')
    for tag_name in json.loads(request.POST['tags']):
        existing_tags = list(
            ClassInstance.objects.filter(project=p,
                                         name=tag_name,
                                         class_column=label_class))
        if len(existing_tags) < 1:
            tag = ClassInstance(project=p,
                                name=tag_name,
                                user=logged_in_user,
                                class_column=label_class)
            tag.save()
        else:
            tag = existing_tags[0]
        if ntype == 'treenode':
            tci = TreenodeClassInstance(user=logged_in_user,
                                        project=p,
                                        relation=labeled_as_relation,
                                        treenode=Treenode(id=location_id),
                                        class_instance=tag)
        else:
            tci = ConnectorClassInstance(user=logged_in_user,
                                         project=p,
                                         relation=labeled_as_relation,
                                         connector=Connector(id=location_id),
                                         class_instance=tag)
        tci.save()
    return HttpResponse(json.dumps({'message': 'success'}),
                        mimetype='text/json')
コード例 #2
0
ファイル: views.py プロジェクト: thatcher/CATMAID
def lines_add(request, project_id=None, logged_in_user=None):
    p = Project.objects.get(pk=project_id)
    # FIXME: for the moment, just hardcode the user ID:
    user = User.objects.get(pk=3)
    neuron = get_object_or_404(ClassInstance,
                               pk=request.POST['neuron_id'],
                               project=p)

    # There's a race condition here, if two people try to add a line
    # with the same name at the same time.  The normal way to deal
    # with this would be to make the `name` column unique in the
    # table, but since the class_instance table isn't just for driver
    # lines, we can't do that.  (FIXME)
    try:
        line = ClassInstance.objects.get(name=request.POST['line_name'])
    except ClassInstance.DoesNotExist:
        line = ClassInstance()
        line.name = request.POST['line_name']
        line.project = p
        line.user = user
        line.class_column = Class.objects.get(class_name='driver_line',
                                              project=p)
        line.save()

    r = Relation.objects.get(relation_name='expresses_in', project=p)

    cici = ClassInstanceClassInstance()
    cici.class_instance_a = line
    cici.class_instance_b = neuron
    cici.relation = r
    cici.user = user
    cici.project = p
    cici.save()

    return HttpResponseRedirect(
        reverse('vncbrowser.views.view',
                kwargs={
                    'neuron_id': neuron.id,
                    'project_id': p.id
                }))