Exemple #1
0
def update_idiograph(request):
    response = {}
    try:
        allograph_id = int(request.POST.get('allograph', ''))
        idiograph_id = int(request.POST.get('idiograph_id', ''))
        data = json.loads(request.POST.get('data', ''))
        allograph = Allograph.objects.get(id=allograph_id)
        idiograph = Idiograph.objects.get(id=idiograph_id)
        idiograph.allograph = allograph
        idiograph.save()
        for idiograph_component in data:
            if idiograph_component['idiograph_component'] != False:
                ic = IdiographComponent.objects.get(
                    id=idiograph_component['idiograph_component'])
                ic.features.clear()
            else:
                ic = IdiographComponent()
            component = Component.objects.get(id=idiograph_component['id'])
            ic.idiograph = idiograph
            ic.component = component
            ic.save()
            for features in idiograph_component['features']:
                feature = Feature.objects.get(id=features['id'])
                ic.features.add(feature)
        response['errors'] = False
    except Exception as e:
        response['errors'] = ['Internal error: %s' % e.message]
    return HttpResponse(json.dumps(response), content_type='application/json')
Exemple #2
0
def save_idiograph(request):
    response = {}
    try:
        scribe_id = int(request.POST.get('scribe', ''))
        allograph_id = int(request.POST.get('allograph', ''))
        data = json.loads(request.POST.get('data', ''))
        allograph = Allograph.objects.get(id=allograph_id)
        scribe = Scribe.objects.get(id=scribe_id)
        idiograph = Idiograph(allograph=allograph, scribe=scribe)
        idiograph.save()
        for component in data:
            idiograph_id = Idiograph.objects.get(id=idiograph.id)
            component_id = Component.objects.get(id=component['id'])
            idiograph_component = IdiographComponent(idiograph = idiograph_id, component = component_id)
            idiograph_component.save()
            for features in component['features']:
                feature = Feature.objects.get(id=features['id'])
                idiograph_component.features.add(feature)
        response['errors'] = False
    except Exception as e:
        response['errors'] = ['Internal error: %s' % e.message]
    return HttpResponse(json.dumps(response), content_type='application/json')
Exemple #3
0
def save_idiograph(request):
    response = {}
    try:
        scribe_id = int(request.POST.get('scribe', ''))
        allograph_id = int(request.POST.get('allograph', ''))
        data = json.loads(request.POST.get('data', ''))
        allograph = Allograph.objects.get(id=allograph_id)
        scribe = Scribe.objects.get(id=scribe_id)
        idiograph = Idiograph(allograph=allograph, scribe=scribe)
        idiograph.save()
        for component in data:
            idiograph_id = Idiograph.objects.get(id=idiograph.id)
            component_id = Component.objects.get(id=component['id'])
            idiograph_component = IdiographComponent(
                idiograph=idiograph_id, component=component_id)
            idiograph_component.save()
            for features in component['features']:
                feature = Feature.objects.get(id=features['id'])
                idiograph_component.features.add(feature)
        response['errors'] = False
    except Exception as e:
        response['errors'] = ['Internal error: %s' % e.message]
    return HttpResponse(json.dumps(response), content_type='application/json')