sorry, I posted a new threat about it...
https://groups.google.com/forum/?fromgroups=#!topic/web2py/8RWkVAYVG1c
s.

Il giorno martedì 22 gennaio 2013 23:14:17 UTC+1, Massimo Di Pierro ha 
scritto:
>
> What web2py version? I cannot reproduce this.
>
> On Friday, 11 January 2013 14:13:04 UTC-6, palomar wrote:
>>
>> Sorry but I have the same problem; i tried with readable=true and 
>> writable=true and to comment the line in DAL.py, but nothing. 
>> I have this table:
>> db.define_table('magazzino',
>>     Field('id_tipo', 'integer',default=0),
>>     Field('p_p','double', default=0.0),
>>     Field('pp_tot','double', writable=True, readable=True, compute=lambda 
>> r: r['id_tipo']==0 and r['p_p']*1 or r['p_p']*r['id_tipo']*-1),
>> )
>> If I edit a row with a FORM the compute field works but if I edit it in a 
>> function with ajax don't...
>>
>> def modArtPrice():
>>     newPp = 100
>>     articolo = db.magazzino[request.vars.id]    
>>     articolo.update_record(p_p=newPp)  
>>
>> what's wrong?
>> s.
>>
>> Il giorno martedì 21 agosto 2012 18:35:05 UTC+2, Brandon Reynolds ha 
>> scritto:
>>>
>>> Thank you so much i got it working. I removed the readable=false and 
>>> writable=false and it works on update now.  Those are not needed anyway 
>>> because when the compute field is added on the model it hides it 
>>> automatically.
>>>
>>>
>>> Brandon
>>>
>>> On Thursday, August 9, 2012 2:14:42 PM UTC-6, Deidre wrote:
>>>>
>>>> If you look at issue 822 you will see an example of a thumb that works 
>>>> on update. As the comments say, you have to not set writeable to false for 
>>>> the thumb. If you do set writeable to false then compute only works on add 
>>>> not edit or update.
>>>> So my experience is that compute for images to create a thumb does work 
>>>> on update.
>>>> Peter
>>>>
>>>> On Thursday, August 9, 2012 5:04:28 PM UTC+1, Brandon Reynolds wrote:
>>>>>
>>>>> Has anyone found a way to fix this yet? Or is there a thumbnail module 
>>>>> out now? Like django's http://djangothumbnails.com/
>>>>>
>>>>> Brandon
>>>>>
>>>>>
>>>>> On Monday, June 18, 2012 10:24:05 AM UTC-6, Brandon Reynolds wrote:
>>>>>>
>>>>>> I have this problem when i try to generate thumbnails. If the field 
>>>>>> is empty it inserts the photo thumb into the thumbnail. But when i try 
>>>>>> to 
>>>>>> update that record the thumbnail doesn't change. 
>>>>>>
>>>>>> Here is my model:
>>>>>>
>>>>>> # coding: utf8
>>>>>> from image import THUMBER
>>>>>>
>>>>>> db.define_table('park', 
>>>>>> Field('park_name', requires=IS_NOT_EMPTY()),
>>>>>> Field('park_city', requires=IS_NOT_EMPTY()),
>>>>>> Field('park_state', requires=IS_NOT_EMPTY()),
>>>>>> Field('park_address', requires=IS_NOT_EMPTY()),
>>>>>> Field('park_zip', requires=IS_NOT_EMPTY()),
>>>>>> Field('country', default="USA", notnull=True, readable=False, 
>>>>>> writable=False),
>>>>>> Field('park_phone', requires=IS_MATCH('[\d\-\(\) ]+')),
>>>>>> Field('park_fax', requires=IS_EMPTY_OR(IS_MATCH('[\d\-\(\) ]+'))),
>>>>>> Field('park_phone_2', 'string', 
>>>>>> requires=IS_EMPTY_OR(IS_MATCH('[\d\-\(\) ]+'))),
>>>>>> Field('photo1', 'upload'),
>>>>>> Field('photo_thumb1', 'upload', readable=False, writable=False),
>>>>>> Field('photo2', 'upload'),
>>>>>> Field('photo_thumb2', 'upload', readable=False, writable=False),
>>>>>> Field('photo3', 'upload'),
>>>>>> Field('photo_thumb3', 'upload', readable=False, writable=False),
>>>>>> Field('photo4', 'upload'),
>>>>>> Field('photo_thumb4', 'upload', readable=False, writable=False),
>>>>>> Field('photo5', 'upload'),
>>>>>> Field('photo_thumb5', 'upload', readable=False, writable=False),
>>>>>> Field('manager', requires=IS_NOT_EMPTY()),
>>>>>> Field('manager_email', requires=IS_EMAIL()),
>>>>>> Field('spaces', 'integer', requires=IS_NOT_EMPTY()),
>>>>>> Field('vacant', 'integer'),
>>>>>> Field('lot_rent', 'integer', requires=IS_NOT_EMPTY()),
>>>>>> Field('water', 'boolean'),
>>>>>> Field('sewer', 'boolean'),
>>>>>> Field('trash', 'boolean'),
>>>>>> Field('pool', 'boolean'),
>>>>>> Field('playground', 'boolean'),
>>>>>> Field('clubhouse', 'boolean'),
>>>>>> Field('laundromat', 'boolean'),
>>>>>> Field('rv_spaces', 'boolean'),
>>>>>> Field('storage', 'boolean'),
>>>>>> Field('handicap_accessible', 'boolean'),
>>>>>> Field('community_description', 'text'),
>>>>>> format='%(park_name)s')
>>>>>>
>>>>>> db.define_table('home', 
>>>>>> Field('pid', notnull=True, readable=False, writable=False),
>>>>>> Field('lot'),
>>>>>> Field('year', length=4, requires=IS_NOT_EMPTY()),
>>>>>> Field('make'),
>>>>>> Field('model'),
>>>>>> Field('width', requires=IS_NOT_EMPTY()),
>>>>>> Field('length', requires=IS_NOT_EMPTY()),
>>>>>> Field('wide', requires=IS_NOT_EMPTY()),
>>>>>> Field('for_sale', 'boolean', default=True),
>>>>>> Field('beds', requires=IS_NOT_EMPTY()),
>>>>>> Field('baths', requires=IS_NOT_EMPTY()),
>>>>>> Field('fridge', 'boolean'),
>>>>>> Field('stove', 'boolean'),
>>>>>> Field('dishwasher', 'boolean'),
>>>>>> Field('microwave', 'boolean'),
>>>>>> Field('washer', 'boolean'),
>>>>>> Field('dryer', 'boolean'),
>>>>>> Field('photo1', 'upload'),
>>>>>> Field('photo1_text'),
>>>>>> Field('photo_thumb1', 'upload', readable=False, writable=False),
>>>>>> Field('photo2', 'upload'),
>>>>>> Field('photo2_text'),
>>>>>> Field('photo_thumb2', 'upload', readable=False, writable=False),
>>>>>> Field('photo3', 'upload'),
>>>>>> Field('photo3_text'),
>>>>>> Field('photo_thumb3', 'upload', readable=False, writable=False),
>>>>>> Field('photo4', 'upload'),
>>>>>> Field('photo4_text'),
>>>>>> Field('photo_thumb4', 'upload', readable=False, writable=False),
>>>>>> Field('photo5', 'upload'),
>>>>>> Field('photo5_text'),
>>>>>> Field('photo_thumb5', 'upload', readable=False, writable=False),
>>>>>> Field('price',requires=IS_NOT_EMPTY()),
>>>>>> Field('description', 'text', requires=IS_NOT_EMPTY()),
>>>>>> Field('posted_on', 'datetime', readable=False, writable=False))
>>>>>>
>>>>>> db.define_table('state',
>>>>>> Field('name'),
>>>>>> Field('full_name'))
>>>>>>
>>>>>> db.define_table('wide',
>>>>>> Field('type'),
>>>>>> format='%(type)s')
>>>>>>
>>>>>>
>>>>>> db.park.park_state.requires = IS_IN_DB(db, 'state.name', 
>>>>>> '%(full_name)s (%(name)s)', zero=T('Select State'))
>>>>>> db.home.wide.requires = IS_IN_DB(db, 'wide.type', '%(type)s', 
>>>>>> zero=T('Select Home Type'))
>>>>>>
>>>>>> db.park.photo_thumb1.compute = lambda row: THUMBER(row.photo1, 
>>>>>> "photo_thumb1", 144, 115)
>>>>>> db.park.photo_thumb2.compute = lambda row: THUMBER(row.photo2, 
>>>>>> "photo_thumb2", 144, 115)
>>>>>> db.park.photo_thumb3.compute = lambda row: THUMBER(row.photo3, 
>>>>>> "photo_thumb3", 144, 115)
>>>>>> db.park.photo_thumb4.compute = lambda row: THUMBER(row.photo4, 
>>>>>> "photo_thumb4", 144, 115)
>>>>>> db.park.photo_thumb5.compute = lambda row: THUMBER(row.photo5, 
>>>>>> "photo_thumb5", 144, 115)
>>>>>> db.home.photo_thumb1.compute = lambda row: THUMBER(row.photo1, 
>>>>>> "photo_thumb1", 144, 115)
>>>>>> db.home.photo_thumb2.compute = lambda row: THUMBER(row.photo2, 
>>>>>> "photo_thumb2", 144, 115)
>>>>>> db.home.photo_thumb3.compute = lambda row: THUMBER(row.photo3, 
>>>>>> "photo_thumb3", 144, 115)
>>>>>> db.home.photo_thumb4.compute = lambda row: THUMBER(row.photo4, 
>>>>>> "photo_thumb4", 144, 115)
>>>>>> db.home.photo_thumb5.compute = lambda row: THUMBER(row.photo5, 
>>>>>> "photo_thumb5", 144, 115)
>>>>>>
>>>>>>
>>>>>> Here is my controller:
>>>>>>
>>>>>> def index():
>>>>>>     return locals()
>>>>>>     
>>>>>> def parks():
>>>>>>     if request.args(0):
>>>>>>         parks = 
>>>>>> db(db.park.park_state==request.args(0)).select(orderby=db.park.park_city|db.park.park_name)
>>>>>>     else:
>>>>>>         parks = 
>>>>>> db(db.park).select(orderby=db.park.park_state|db.park.park_city|db.park.park_name)
>>>>>>     return locals()
>>>>>>     
>>>>>> def park():
>>>>>>     park = db.park(request.args(0)) or redirect(URL('parks'))
>>>>>>     homes = db(db.home.pid==(request.args(0))).select(orderby=
>>>>>> db.home.id)
>>>>>>     return locals()
>>>>>>     
>>>>>> def home():
>>>>>>     home = db.home(request.args(0)) or redirect(URL('parks'))
>>>>>>     park = db.park(home.pid)
>>>>>>     return locals()
>>>>>>     
>>>>>> def home_feed():
>>>>>>     home = db(db.home).select(orderby=db.home.id)
>>>>>>     return locals()
>>>>>>
>>>>>> @auth.requires_membership('Admin')
>>>>>> def new_park():
>>>>>>     form = crud.create(db.park, next='park/[id]')
>>>>>>     return locals()
>>>>>>     
>>>>>> @auth.requires_membership('Admin')
>>>>>> def new_home():
>>>>>>     db.home.pid.default = request.args(0) or redirect(URL('parks'))
>>>>>>     db.home.price.default = "$0000.00"
>>>>>>     db.home.posted_on.default = request.now
>>>>>>     form = crud.create(db.home, next='home/[id]')
>>>>>>     return locals()
>>>>>>     
>>>>>> @auth.requires_membership('Admin')
>>>>>> def edit_park():
>>>>>>     park = db.park(request.args(0)) or redirect(URL('parks'))
>>>>>>     form = crud.update(db.park, park, next='park/[id]')
>>>>>>     return locals()
>>>>>>     
>>>>>>     
>>>>>> @auth.requires_membership('Admin')
>>>>>> def edit_home():
>>>>>>     home = db.home(request.args(0)) or redirect(URL('parks'))
>>>>>>     form = crud.update(db.home, home, next='home/[id]')
>>>>>>     return locals()
>>>>>>     
>>>>>> def about_us():
>>>>>>     return locals()
>>>>>>     
>>>>>> def employment_opportunities():
>>>>>>     return locals()
>>>>>>
>>>>>> def park_management():
>>>>>>     return locals()
>>>>>>     
>>>>>> def make_park_thumbs():
>>>>>> from image import THUMBER
>>>>>> parks=db(db.park).select(orderby=db.park.park_state)
>>>>>> for park in parks:
>>>>>> park.update_record(photo_thumb1 = THUMBER(park.photo1, 
>>>>>> "photo_thumb1", 144, 115))
>>>>>> park.update_record(photo_thumb2 = THUMBER(park.photo2, 
>>>>>> "photo_thumb2", 144, 115))
>>>>>> park.update_record(photo_thumb3 = THUMBER(park.photo3, 
>>>>>> "photo_thumb3", 144, 115))
>>>>>> park.update_record(photo_thumb4 = THUMBER(park.photo4, 
>>>>>> "photo_thumb4", 144, 115))
>>>>>> park.update_record(photo_thumb5 = THUMBER(park.photo5, 
>>>>>> "photo_thumb5", 144, 115))
>>>>>> db.commit()
>>>>>>
>>>>>>
>>>>>> Here is the THUMBER function
>>>>>> from gluon import current
>>>>>>  
>>>>>> def THUMBER(image, db_photo_var, nx=120, ny=120, name='thumb'):
>>>>>>     if image:
>>>>>>         try:
>>>>>>             request = current.request
>>>>>>             from PIL import Image
>>>>>>             import os
>>>>>>             img = Image.open(request.folder + 'uploads/' + image)
>>>>>>             img.db_photo_var((nx, ny), Image.ANTIALIAS)
>>>>>>             root, ext = os.path.splitext(image)
>>>>>>             thumb = '%s_%s%s' % (root, name, ext)
>>>>>>             img.save(request.folder + 'uploads/' + thumb)
>>>>>>             return thumb
>>>>>>         except Exception:
>>>>>>             return image
>>>>>>        
>>>>>>
>>>>>> What should i do to get these working on update? At the bottom of the 
>>>>>> controller you will notice a the make_park_thumbs() function. That was 
>>>>>> one 
>>>>>> way of try to fix this and having it set to run on updates. However 
>>>>>> won't 
>>>>>> generate a thumbnail it just returns the original photo. This would work 
>>>>>> if 
>>>>>> you can tell why that function won't work. Let me know what to do.
>>>>>>
>>>>>> Braandon
>>>>>>
>>>>>

-- 



Reply via email to