문제

I'm using SQLFORM.grid for my form. The view is showing up fine and i can hide fields. But when i go into the Edit page, i want to have certain fields not readable and not writeable. I have set it to be readable=False before the SQLFORM.grid call and also in the request.args == 'edit'. I can confirm it detects the edit page but for some reason, it doesn't run the read and write.

following is the controller:

def display_form():
  db.items.timeStamp.readable = False
  db.items.imageName.readable = False
  db.items.isCopied.writeable = True

  query = (db.items.numSold > 100)    

  default_sort_order = [db.items.numSold]


  if len(request.args) > 1 and ('edit' in request.args):        
      db.items.timeStamp.readable = False
      db.items.imageName.writeable = False
      form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False, 
        deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False, 
        user_signature=False,
        links=[dict(header=T('Profit'),body=lambda row: row.profit), 
        dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+ 
              rowB.imageName.replace('\\','/')), _width=50, _height=50), 
              _href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))], 
              selectable=get_chosenItems
              )
  else:        
      form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False, 
        deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False, 
        user_signature=False,
        links=[dict(header=T('Profit'),body=lambda row: row.profit), 
        dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+ 
              rowB.imageName.replace('\\','/')), _width=50, _height=50), 
              _href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))], 
              selectable=get_chosenItems
                            )

return dict(form=form)

I can tell that when on the edit page, it would go in the if statement, however, it totally ignores the readables i set there.

Should i be calling the form once again within the edit page? I feel that it's redundant.

도움이 되었습니까?

해결책

To prevent fields from being included on edit forms, set both the readable and writable attributes to False. If you set writable to False but leave readable as True, then you'll see a read-only value for the field on the form.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top