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 }))