Example #1
0
    def testProcessInTemp(self):

        ImageRW.Process("test1.jpg", False, "hats")
        ImageRW.Process("test2.jpg", False, "headphones")
        ImageRW.Process("test3.jpg", False, "headphones")
        ImageRW.Process("test4.jpg", False, "hats")
        ImageRW.Process("test5.jpg", False, "glasses")
Example #2
0
def editCustomItem(request, id, token):
    db = dataBaseModel()

    if not (request.user.is_authenticated() and request.method == 'POST'
            and db.checkIfOwnCustomProduct(request.user.id, id) == True):
        return HttpResponse(json.dumps(
            {'errCode': dataBaseModel.ERR_BAD_REQUEST}),
                            content_type='application/json')

    overlayfilename = ""
    imagefilename = ""

    config = db.findPositionalConfig(token)  # find before clear temp

    if 'overlay' in request.FILES:
        temppath = db.removeTempProduct(
            request.user.id)  # try remove temp product

        # remove temp image
        if temppath != []:
            for path in temppath:
                ImageRW.removeImage(path, False)
                ImageRW.removeImage(path.replace('.png', '.jpg'), False)

        try:
            filename = token_generator()
            filename += str(request.user.id)
            filename += '.jpg'
            overlayfilename = filename.replace('.jpg', 'ol.jpg')
            imagefilename = ImageRW.writeImage(request.FILES['overlay'], True,
                                               filename)  # write image
            ImageRW.writeImage(request.FILES['overlay'], True,
                               overlayfilename)  # write image
            #check here
            overlayfilename = ImageRW.Process(
                overlayfilename, True, request.POST["category"]
            )  # convert it to transparent, return the new ol file name
            #check here
            ImageRW.removeImage(overlayfilename.replace('.png', '.jpg'), True)
        except:
            return HttpResponse(json.dumps(
                {'errCode': dataBaseModel.ERR_UNABLE_TO_EDIT_CUSTOM_PRODUCT}),
                                content_type='application/json')

    form = CustomProductForm(request.POST)

    if form.is_valid():
        pcategory = form.cleaned_data['category'].lower()
        pname = form.cleaned_data['itemname'].lower()
        pbrand = form.cleaned_data['brand']
        purl = form.cleaned_data['url']
        pprice = float(form.cleaned_data['price'])
        pdescription = form.cleaned_data['description']

        result = ""
        if config != None:
            result = db.editProduct(request.user.id, imagefilename,
                                    overlayfilename, pcategory, pbrand, pname,
                                    purl, pprice, pdescription, id, config[0],
                                    config[1], config[2], config[3], True)
        else:
            result = db.editProduct(request.user.id, imagefilename,
                                    overlayfilename, pcategory, pbrand, pname,
                                    purl, pprice, pdescription, id)
        if result != dataBaseModel.SUCCESS:
            return HttpResponse(json.dumps(
                {'errCode': dataBaseModel.ERR_UNABLE_TO_EDIT_CUSTOM_PRODUCT}),
                                content_type='application/json')
        data = {'errCode': dataBaseModel.SUCCESS}
        return HttpResponse(json.dumps(data), content_type='application/json')
    else:
        return HttpResponse(json.dumps(
            {'errCode': dataBaseModel.ERR_UNABLE_TO_EDIT_CUSTOM_PRODUCT}),
                            content_type='application/json')
Example #3
0
 def testProcessInPerm(self):
     ImageRW.Process("sample.jpg", True, "headphones")
     #ImageRW.convertToTransparent("apple.jpg", True)
     self.assertTrue(os.path.isfile(ImageRW.IMAGE_DIR + "sample.png"),
                     'Image not converted to PNG')