Question

I'm trying to use SQLFORM.grid to show a query of items and have a boolean field that will show up as a checkbox on the form. I want to be able to check the checkboxes of items i want to move. When submitted have it update on the database as well as perform a special function of copying the selected item's image files into a folder.

My SQLFORM.grid is show up properly with the check box but i can't select the checkbox at all. As well, i'm not sure how I will have it so that selected items will go through that two step process.

I even set editable = True on SQLFORM.grid Also set db.items.isMoved.writeable = True

The following is my code:

model:

db.define_table('items', 
    Field('itemNumber', 'id'), Field('numSold', 'integer'),                          
    Field('imageName', 'string'), Field('isMoved','boolean')
    Field('timeStamp', 'datetime'))

Controller:

class VirtualProfitField(object):
  def profit(self):
    return "$" + str(self.items.price * self.items.numSold)

db.items.virtualfields.append(VirtualProfitField())

def display_form():
  default_sort_order = [ebaydb.items.numSold]
  db.items.timeStamp.readable = False
  db.items.imageName.readable = False

  query = (db.items.numSold > 100) 
  default_sort_order = [db.items.numSold]
  form = SQLFORM.grid(query=query, orderby=default_sort_order, create=True, 
    deletable=True, editable=True, maxtextlength=64, paginate=25, csv=False,
    links=[dict(header=T('Profit'),body=lambda row: row.profit), 
    dict(header=T('Image'),
    body = lambda rowB: A(IMG(_src=URL('static', "images/images/"+ 
    rowB.imageName.replace('\\','/')), _width=50, _height=50), _href=URL('static', 
    "images/images/"+ rowB.imageName.replace('\\','/'))))]

   if len(request.args) > 1 and ('edit' in request.args):
     db.items.timeStamp.readable = False
     db.items.imageName.writeable = False

   return dict(form=form)

The "edit" or "update" button never shows up.

As well, where and how do I code to move the files selected to another folder? Will I be able to get the itemNumber and imageName of the items that was checked?

Thank you so much for your help!!

John

PS: I sense Anthony's presence...

Was it helpful?

Solution

By default user_signature=True, which means create, edit, and delete are disabled unless the user is logged in. If you want non-logged-in users to be able to complete those operations, do SQLFORM.grid(..., user_signature=False).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top