def SaveSize(request):
    aResponse = ResultResponse()
    received_json_data = json.loads(request.body.decode("utf-8"))
    theRequest = request.POST.copy()
    theRequest.__mutable = True
    theRequest.POST = received_json_data

    sizeName = received_json_data.get('ItemSizeName')

    active = received_json_data.get('IsActive')

    masterForm = ItemSizeForm(theRequest.POST)
    if masterForm.is_valid():

        size = ItemSize(ItemSizeName=sizeName,
                        IsActive=active,
                        CreateBy='Admin')
        size.save()
        if size.pk > 0:
            aResponse.IsSuccess = True
            aResponse.PK = size.pk
        return JsonResponse(json.dumps(aResponse.__dict__), safe=False)
    else:
        appError = AppError()
        template = render_to_string('BasicSettings/_sizeForm.html',
                                    {'masterForm': masterForm})
        appError.TheData = str(template)
        return JsonResponse(json.dumps(appError.__dict__), safe=False)
def SaveCategory(request):

    aResponse = ResultResponse()
    received_json_data = json.loads(request.body.decode("utf-8"))
    theRequest = request.POST.copy()
    theRequest.__mutable = True

    theRequest.POST = received_json_data

    group = received_json_data.get('ItemGroup')
    name = received_json_data.get('ItemCategory')
    shortName = received_json_data.get('CategoryShortName')
    active = received_json_data.get('IsActive')

    masterForm = ItemCategoryForm(theRequest.POST)
    if masterForm.is_valid():

        category = ItemCategory(ItemGroup=ItemGroup.objects.get(id=int(group)),
                                ItemCategory=name,
                                CategoryShortName=shortName,
                                IsActive=active,
                                CreateBy='Admin')
        category.save()
        if category.pk > 0:
            aResponse.IsSuccess = True
            aResponse.PK = category.pk
        return JsonResponse(json.dumps(aResponse.__dict__), safe=False)
    else:
        appError = AppError()

        template = render_to_string('BasicSettings/_itemCategoryForm.html',
                                    {'masterForm': masterForm})
        appError.TheData = str(template)
        return JsonResponse(json.dumps(appError.__dict__), safe=False)