Ejemplo n.º 1
0
    def POST(self, name = None):
        xinput = web.input()
        ifile = web.input(avatar={})
        filePath_a = goods_image_name()
        filePath = filePath_a[0]
        if 'avatar' in ifile:
            ifile['avatar'].file.seek(0, os.SEEK_END)
            if ifile.avatar.file.tell() > 0:
                fout = open(filePath % '_o','w') # creates the file where the uploaded file should be stored
                ifile.avatar.file.seek(0)
                fout.write(ifile.avatar.file.read()) # writes the uploaded file to the newly created file.
                fout.close() # closes the file, upload complete.

                resize_image(filePath % '_o', filePath % '_256',  256, refMode = 'both')
                resize_image(filePath % '_o', filePath % '_512',  512, refMode = 'both')
                resize_image(filePath % '_o', filePath % '_800',  800, refMode = 'both')



        thegoods = goods()
        thegoods.bind(xinput)
        thegoods.avatar_path.zval = filePath_a[1]
        thegoods.update_date.zval = datetime.datetime.now()
        #return thegoods.dump()
        if name is None:
            thegoods.create_date.zval = datetime.datetime.now()
            insert(thegoods)
        else:
            thegoods._id.val(name)
            update(thegoods)
        raise web.seeother("/admin/goods/")
Ejemplo n.º 2
0
    def POST(self, name = None):
        xinput = web.input()
        if xinput.has_key('act') and xinput.act == 'del':
            imgid = xinput.id
            mgoodsImg = find_one(goods_picture, _id=imgid)
            xpath = mgoodsImg.path.zval
            try:
                del_goods_images(xpath)
            except OSError:
                pass
            remove(goods_picture, _id=imgid)
            return 1
        elif xinput.has_key('act') and xinput.act == 'avatar':
            imgid = xinput.id
            mgoodsImg = find_one(goods_picture, _id=imgid)
            xpath = mgoodsImg.path.zval
            xgoods_id = mgoodsImg.goods_id.zval
            mGoods = goods()
            mGoods._id.zval = xgoods_id
            mGoods.avatar_path.zval = xpath
            update(mGoods)
            return 1

        ifile = web.input(avatar={})
        filePath_a = goods_image_name()
        filePath = filePath_a[0]

        if 'avatar' in ifile:
            ifile.avatar.file.seek(0, os.SEEK_END)
            if ifile.avatar.file.tell() > 0:
                fout = open(filePath % '_o','w') # creates the file where the uploaded file should be stored
                ifile.avatar.file.seek(0)
                fout.write(ifile.avatar.file.read()) # writes the uploaded file to the newly created file.
                fout.close() # closes the file, upload complete.

                resize_image(filePath % '_o', filePath % '_256',  256, refMode = 'both')
                resize_image(filePath % '_o', filePath % '_512',  512, refMode = 'both')
                resize_image(filePath % '_o', filePath % '_800',  800, refMode = 'both')

                thepic = goods_picture()
                thepic.bind(xinput)
                thepic.path.zval = filePath_a[1]
                thepic.goods_id.zval = name
                thepic.create_date.zval = datetime.datetime.now()
                insert(thepic)
        raise web.seeother("/admin/goods/images/" + name)