sqlfor grid uneditable lets edit once in form view

27 views
Skip to first unread message

Yebach

unread,
Oct 30, 2015, 10:12:03 PM10/30/15
to web2py-users
Hello

I have a view that shows two grids. One is editable one not. Everything ok.
The uneditable has an option view, so user can see all the parameters. Once in form view there is an edit button and he can edit the values. I want to prevent that from happening. How can I do that.


This is my code

grid_config200  is the grid that should not be editable in view form


@auth.requires_login()
def config():
user = auth.user_id
org = db(db.auth_user.id == user).select(db.auth_user.organization)[0]["organization"]
configSetting200 = ((db.config.co_organisation == org) & (db.config.co_access_level < 200) )
configSetting200Plus = ((db.config.co_organisation == org) & (db.config.co_access_level >= 200))
fields_config =(
db.config.co_code,
db.config.co_value,
db.config.co_note
)
db.config.co_organisation.readable = db.config.co_organisation.writable = False
db.config.co_access_level.readable = db.config.co_access_level.writable = False
db.config.co_area.writable = False
db.config.co_code.writable = False
# db.config.co_area.readable = db.config.co_area.writable = False
db.config.co_value.widget = SQLFORM.widgets.string.widget
db.config.co_area.widget = SQLFORM.widgets.string.widget
db.config.co_note.widget = SQLFORM.widgets.string.widget
#UNEDITABLE form and data
grid_config200 = SQLFORM.grid(query=configSetting200, 
fields=fields_config ,  searchable=False,create=False,
deletable=False, editable=False, paginate=25, buttons_placement = 'right',
user_signature=False,
maxtextlengths = {'config.co_note' : 256}, 
showbuttontext = False,formname = 'config200Table',
formargs=dict(message_onsuccess=T('Record updated'),
                                message_onfailure=T('Form has errors')),
#oncreate=myfunction,
ui = dict(widget='',
         header='',
         content='',
         default='',
         cornerall='',
         cornertop='',
         cornerbottom='',
         button='button btn btn-default',
         buttontext='buttontext button',
         buttonadd='icon plus icon-plus glyphicon glyphicon-plus',
         buttonback='icon leftarrow icon-arrow-left glyphicon glyphicon-arrow-left',
         buttonexport='icon downarrow icon-download glyphicon glyphicon-download',
         buttondelete='icon trash icon-trash glyphicon glyphicon-trash',
         buttonedit='icon pen icon-pencil glyphicon glyphicon-pencil',
         buttontable='icon rightarrow icon-arrow-right glyphicon glyphicon-arrow-right',
         buttonview='icon magnifier icon-zoom-in glyphicon glyphicon-eye-open',
         buttonvidov = 'icon glyphicon glyphicon-euro' 
         ),
exportclasses  = dict(csv_with_hidden_cols=False, html = False, tsv = False, tsv_with_hidden_cols=False, json = False))
grid_config200Plus = SQLFORM.grid(query=configSetting200Plus, 
fields=fields_config ,  searchable=False,create=False,
deletable=False, editable=True, paginate=25, buttons_placement = 'right',
user_signature=False,
maxtextlengths = {'config.co_note' : 256}, 
showbuttontext = False,formname = 'config200PlusTable',
formargs=dict(message_onsuccess=T('Record updated'),
                                message_onfailure=T('Form has errors')),
#oncreate=myfunction,
ui = dict(widget='',
         header='',
         content='',
         default='',
         cornerall='',
         cornertop='',
         cornerbottom='',
         button='button btn btn-default',
         buttontext='buttontext button',
         buttonadd='icon plus icon-plus glyphicon glyphicon-plus',
         buttonback='icon leftarrow icon-arrow-left glyphicon glyphicon-arrow-left',
         buttonexport='icon downarrow icon-download glyphicon glyphicon-download',
         buttondelete='icon trash icon-trash glyphicon glyphicon-trash',
         buttonedit='icon pen icon-pencil glyphicon glyphicon-pencil',
         buttontable='icon rightarrow icon-arrow-right glyphicon glyphicon-arrow-right',
         buttonview='icon magnifier icon-zoom-in glyphicon glyphicon-eye-open',
         buttonvidov = 'icon glyphicon glyphicon-euro' 
         ),
exportclasses  = dict(csv_with_hidden_cols=False, html = False, tsv = False, tsv_with_hidden_cols=False, json = False))

return dict(grid_config200 = grid_config200, grid_config200Plus = grid_config200Plus)

Vid Ogris

unread,
Oct 30, 2015, 10:59:31 PM10/30/15
to web...@googlegroups.com
Solved the problem using LOAD

created two new functions for eacg SQLFROM.grid, added two *. load files for each file and in my view used LOAD

my view setting.html


<title>{{ =response.title + " - " +T('Config')}} </title>
</head>
<div  class="flash">{{=session.flash or ''}}</div>
<div class="rowSettings row">
       <div class="col-md-4">
        <h2>{{=T('Edit system settings')}}</h2>
        </div>
       <div class="col-md-2  buttonBox">
        
            
        </button>
       </div>
</div> 

<div>
<div  style="margin-bottom: 200px;">
<div>
<h4><b>{{=T('Changeable settings')}}</b></h4>
<div class="col-md-12 " >
{{=LOAD(f="configEditable.load", ajax=True, ajax_trap=True)}} 
</div>
   </div>
</div>
<div>
<br>&nbsp</br>
<br>
</div>

        <div  style="margin-bottom: 200px;">
<div>
<h4><b>{{=T('Fixed settings')}}</b></h4>
<div class="col-md-12 " >
{{=LOAD(f="configUneditable.load", ajax=True, ajax_trap=True)}} 
</div>
   </div>
</div>

</div>





--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/aV8GYEhb8tQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lep pozdrav 

Vid Ogris


Reply all
Reply to author
Forward
0 new messages