Example #1
0
    def update(self, request, user_name, concept_name):
        user = user_authentication(request, user_name)

        received_json = PUT_parameter(request, 'json')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("JSON parameter not specified")))

        try:
            received_data = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(
                get_xml_error(_("Expecting data in JSON format.")))

        for received_concept in received_data:
            concept = None
            try:
                concept = Concept.objects.get(concept=concept_name)
                concept.adaptor = received_concept['adaptor']
                concept.save()

            except Concept.DoesNotExist:
                return HttpResponseBadRequest(
                    get_xml_error(
                        _("Concept does not exist. You must use POST HTTP method in this case"
                          )))

            cname = ConceptName(name=received_concept['name'], concept=concept)
            cname.save()

        return HttpResponse('ok')
Example #2
0
    def create(self, request, user_name):
        user = user_authentication(request, user_name)
        
        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(get_xml_error(_("JSON parameter not specified")))

        try:
            received_data = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(get_xml_error(_("Expecting data in JSON format.")))

        for received_concept in received_data['concepts']:
            concept = None
            try:
                concept = Concept.objects.get(concept=received_concept['concept'])
                if not concept.adaptor == received_concept['adaptor']:
                    return HttpResponseBadRequest(get_xml_error(_(u'Attempted update. You must use PUT HTTP method in this case')))
            
            except Concept.DoesNotExist:
                concept = Concept (concept=received_concept['concept'], adaptor=received_concept['adaptor'])
                concept.save()
            
            try:
                #Checks if concept name exits in database
                ConceptName.objects.get (name=received_concept['name'], concept=concept)

            except ConceptName.DoesNotExist:
                cname = ConceptName (name=received_concept['name'], concept=concept)
                cname.save()
        
        return HttpResponse('ok') 
Example #3
0
    def create(self, request, user_name, concept_name):
        user = user_authentication(request, user_name)

        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(
                get_xml_error(_("JSON parameter not specified")))

        try:
            received_concept = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(
                get_xml_error(_("Expecting data in JSON format.")))

        concept = None
        try:
            concept = Concept.objects.get(concept=concept_name)
            if not concept.adaptor == received_concept['adaptor']:
                return HttpResponseBadRequest(
                    get_xml_error(
                        _(u'Attempted update. You must use PUT HTTP method in this case'
                          )))

        except Concept.DoesNotExist:
            concept = Concept(concept=concept_name,
                              adaptor=received_concept['adaptor'])
            concept.save()

        cname = ConceptName(name=received_concept['name'], concept=concept)
        cname.save()

        return HttpResponse('ok')
Example #4
0
    def update(self, request, user_name, concept_name):
        user = user_authentication(request, user_name)
        
        received_json = PUT_parameter(request, 'json') 

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("JSON parameter not specified")))

        try:
            received_data = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(get_xml_error(_("Expecting data in JSON format.")))

        for received_concept in received_data:
            concept = None
            try:
                concept = Concept.objects.get(concept=concept_name)
                concept.adaptor = received_concept['adaptor']
                concept.save()
                 
            except Concept.DoesNotExist:
                return HttpResponseBadRequest(get_xml_error(_("Concept does not exist. You must use POST HTTP method in this case")))

            cname = ConceptName (name=received_concept['name'], concept=concept)
            cname.save()

        return HttpResponse('ok')