Example #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)
Example #2
0
def showOne (request, factory_id):
  try:
    if request.method == 'GET':
      factory = factory_service.getOne(factory_id)
      return render(request, 'factory/showOne.html', {'factory': factory})
  except ObjectDoesNotExist:
    raise Http404('Factory with id ' + factory_id + ' does not exist')
Example #3
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)
Example #4
0
def showOne(request, factory_id):
    try:
        if request.method == 'GET':
            factory = factory_service.getOne(factory_id)
            return render(request, 'factory/showOne.html',
                          {'factory': factory})
    except ObjectDoesNotExist:
        raise Http404('Factory with id ' + factory_id + ' does not exist')
Example #5
0
def update (request, factory_id):
  try:
    if request.method == 'GET':
      factory = factory_service.getOne(factory_id)
      return render(request, 'factory/update.html', {'factory': factory})
    elif request.method == 'POST':
      factory = factory_service.update(factory_id, request.POST.dict())
      return HttpResponseRedirect(reverse('webapp:factory.showOne', args=(factory.id,)))
  except ObjectDoesNotExist:
    raise Http404('Factory with id ' + factory_id + ' does not exist')
Example #6
0
def update(request, factory_id):
    try:
        if request.method == 'GET':
            factory = factory_service.getOne(factory_id)
            return render(request, 'factory/update.html', {'factory': factory})
        elif request.method == 'POST':
            factory = factory_service.update(factory_id, request.POST.dict())
            return HttpResponseRedirect(
                reverse('webapp:factory.showOne', args=(factory.id, )))
    except ObjectDoesNotExist:
        raise Http404('Factory with id ' + factory_id + ' does not exist')