thanks Anthony and Richard. I guess I didn't understand the SQLFORM.factory
and what it does. I get now my thumbnail and all dbentries as I like except
the main Image Itself. there is a value in the database and the image is
saved but I guess the Name already tells that there is something screwy:
no_table.Image.9721d2f2a2f77f4d.537461727472656b5f73315f636f766572312e6a7067.jpg
So I guess I have to tell web2py somehow what the right naming pattern
should be.
Oh man when I started the plan to add this feature I thought thats easy ^^
I'm really sorry for my lack off understanding.
Sry about the client in the previous code^^
My corrected code now:
def newImage():
dbtable = db.Images #uploads table name
if len(request.args):
records = db(dbtable.id==request.args[0]).select()
print "len(request.args)",records
if len(request.args) and len(records):
form = SQLFORM(dbtable, records[0], deletable=True)
else:
form = SQLFORM.factory(dbtable,db.image_references)
if form.process().accepted:
response.flash = 'Entry for Images Database accepted,start creating
thumb'
id = db.Images.insert(**db.Images._filter_fields(form.vars))
form.vars.image_id=id
id =
db.image_references.insert(**db.image_references._filter_fields(form.vars))
thisImage=db(dbtable.id==form.vars.image_id).select()
thisImage=thisImage[0]
makeThumbnail(dbtable,form.vars.image_id,(200,200))
here is my thumbnail funktion or should I say your funktion Anthony:)
def makeThumbnail(dbtable,ImageID,size=(200,200)):
""" This code is mostly from web2pyslices but the person who really
made it work was Anthony thanks for that """
try:
thisImage=db(dbtable.id==ImageID).select()[0]
import os, uuid
except:
print "Error while loading libraries"
return
try:
from PIL import Image
except:
print "Error while Importing PIL library"
return
im=Image.open(request.folder + 'uploads/' + thisImage.Image)
im.thumbnail(size,Image.ANTIALIAS)
""" Thanks to Anthony for this code he is the best :) """
from cStringIO import StringIO
tmp = StringIO()
im.save(tmp, 'jpeg')
tmp.seek(0)
""" the rest is of this function is taken from web2pyslices thank you
guys too you are a real help """
thisImage.update_record(thumb=db.Images.thumb.store(tmp,
filename='thumbnail.jpg'))
response.flash = 'Database entry Added. Image stored and Thumbnail
created'
return
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.