Beispiel #1
0
def detail (request, factory_id):
  factory_id = factory_id.encode('ascii', 'ignore')
  try:
    if request.method == 'GET':
      factory = factory_service.getOne(factory_id)
      json_data = serializers.serialize("json", [factory])
      status = 200
    elif request.method == 'PUT':
      request_put = None

      if request.body != 'None':
        request_put = json.loads(request.body.decode())
      factory = factory_service.update(factory_id, request_put)

      json_data = serializers.serialize("json", [factory])
      status = 202
    elif request.method == 'DELETE':
      factory_service.delete(factory_id)
      json_data = json.dumps({"success": "Factory: " + factory_id + " has been deleted."})
      status = 204
      return HttpResponse(json_data, content_type='application/json', status=status)

  except ObjectDoesNotExist:
    raise Http404('Factory with id ' + factory_id + ' does not exist')

  struct = json.loads(json_data)
  json_data = json.dumps(struct[0]) # unwrap from array
  return HttpResponse(json_data, content_type='application/json', status=status)
Beispiel #2
0
def detail(request, factory_id):
    factory_id = factory_id.encode('ascii', 'ignore')
    try:
        if request.method == 'GET':
            factory = factory_service.getOne(factory_id)
            json_data = serializers.serialize("json", [factory])
            status = 200
        elif request.method == 'PUT':
            request_put = None

            if request.body != 'None':
                request_put = json.loads(request.body.decode())
            factory = factory_service.update(factory_id, request_put)

            json_data = serializers.serialize("json", [factory])
            status = 202
        elif request.method == 'DELETE':
            factory_service.delete(factory_id)
            json_data = json.dumps(
                {"success": "Factory: " + factory_id + " has been deleted."})
            status = 204
            return HttpResponse(json_data,
                                content_type='application/json',
                                status=status)

    except ObjectDoesNotExist:
        raise Http404('Factory with id ' + factory_id + ' does not exist')

    struct = json.loads(json_data)
    json_data = json.dumps(struct[0])  # unwrap from array
    return HttpResponse(json_data,
                        content_type='application/json',
                        status=status)
Beispiel #3
0
def delete (request, factory_id):
  try:
    factory_service.delete(factory_id)
    return HttpResponseRedirect(reverse('webapp:factory.showAll'))
  except ObjectDoesNotExist:
    raise Http404('Factory with id ' + factory_id + ' does not exist')
Beispiel #4
0
def delete(request, factory_id):
    try:
        factory_service.delete(factory_id)
        return HttpResponseRedirect(reverse('webapp:factory.showAll'))
    except ObjectDoesNotExist:
        raise Http404('Factory with id ' + factory_id + ' does not exist')