Basically the function _listify is called by both inser and update. It
figures out which fields are missing and gets their default, update or
computed value. Looks like it is not calling compute. It has three loops:
for name in fields:
...
for ofield in self:
...
for ofield in self:
if not ofield.name in new_fields_names and ofield.compute:
...
Can you figure out why the "if not ofield.name in new_fields_names and
ofield.compute" is false for your field?
On Tuesday, 19 June 2012 10:43:59 UTC-5, Brandon Reynolds wrote:
>
> Peter,
>
> I tried your fix with no luck. It did not work unfortunately.
>
> Massimo,
>
> I replaced the lines you specified with no luck. It never printed out
> computing. What should we try to next to debug this?
>
> Brandon
>
> On Tuesday, June 19, 2012 8:28:20 AM UTC-6, Massimo Di Pierro wrote:
>>
>> I need your help debugging this. In dal.py there are these lines:
>>
>> def _listify(self,fields,update=False):
>> for ofield in self:
>> if not ofield.name in new_fields_names and ofield.compute:
>> try:
>>
>> new_fields.append((ofield,ofield.compute(Row(fields))))
>> except KeyError:
>> pass
>>
>> The line new_fields.append((ofield,ofield.compute(Row(fields)))) should
>> always be called (insert and update). Can you try remove the try...
>> except..
>>
>> def _listify(self,fields,update=False):
>> for ofield in self:
>> if not ofield.name in new_fields_names and ofield.compute:
>> #try:
>> print 'computing',ofield.name
>>
>> new_fields.append((ofield,ofield.compute(Row(fields))))
>> #except KeyError:
>> # pass
>>
>> and see what you get?
>>
>>
>> On Tuesday, 19 June 2012 08:35:19 UTC-5, LightDot wrote:
>>>
>>> I think this is closely connected to an existing Issue 687 (Compute=
>>> should work always, not once):
>>>
>>> http://code.google.com/p/web2py/issues/detail?id=687
>>>
>>> Regards
>>>
>>> On Monday, June 18, 2012 11:21:57 PM UTC+2, peter wrote:
>>>>
>>>> I would try removing the readable and writeable false for the compute
>>>> fields. It seems that it does automatically not show them. I found that
>>>> setting readable and writeable to False means the thumbs only get computed
>>>> on insert, not update. I reported this a while back.
>>>> Peter
>>>>
>>>> On Monday, 18 June 2012 22:14:09 UTC+1, Massimo Di Pierro wrote:
>>>>>
>>>>> Will look into this asap. Please open a ticket about it so that it is
>>>>> tracked.
>>>>>
>>>>>
>>>>> On Monday, 18 June 2012 14:40:30 UTC-5, Brandon Reynolds wrote:
>>>>>>
>>>>>> In a new record a thumbnail is correctly generated from photo. But if
>>>>>> I didn't upload a photo or want to change the photo the thumbnail
>>>>>> doesn't
>>>>>> generate. So basically a new record works properly but when updating
>>>>>> nothing in the thumbnail changes at all whether or not is currently has
>>>>>> a
>>>>>> photo in it.
>>>>>>
>>>>>> ____________________________________________________
>>>>>> model:
>>>>>>
>>>>>> from image import THUMBER
>>>>>> db.define_table('park',
>>>>>> Field('photo1', 'upload'),
>>>>>> Field('photo_thumb1', 'upload', readable=False, writable=False))
>>>>>>
>>>>>> db.park.photo_thumb1.compute = lambda row: THUMBER(row.photo1,
>>>>>> "photo_thumb1", 144, 115)
>>>>>>
>>>>>> ____________________________________________________
>>>>>> image.py:
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Monday, June 18, 2012 1:17:07 PM UTC-6, Massimo Di Pierro wrote:
>>>>>>>
>>>>>>> Let me understand this better.
>>>>>>>
>>>>>>> on insert, the thumbnails are created.
>>>>>>> on update, if you upload a new photo1 is photo_thing1 generated?
>>>>>>>
>>>>>>> Can you provide a simpler code to reproduce the problem with a just
>>>>>>> one upload field and one thumbnail field?
>>>>>>>
>>>>>>> massimo
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Monday, 18 June 2012 11:24:05 UTC-5, 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
>>>>>>>>
>>>>>>>