Changes between Version 34 and Version 35 of BluePrintRESTImplementation
- Timestamp:
- 01/17/09 18:16:59 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BluePrintRESTImplementation
v34 v35 8 8 db.define_table(table,timestamp,uuidstamp, 9 9 SQLField('name')) 10 exec("s3.crud_fields.%s=['name']" % table) 11 db[ '%s' % table].exposes=s3.crud_fields['%s' %table]10 s3.crud_fields[table]=['name'] 11 db[table].exposes=s3.crud_fields[table] 12 12 # Moved to Controller - allows us to redefine for different scenarios (& also better MVC separation) 13 #db[ '%s' % table].displays=s3.crud_fields['%s' %table]13 #db[table].displays=s3.crud_fields[table] 14 14 # NB Beware of lambdas & %s substitution as they get evaluated when called, not when defined! 15 #db[ '%s' %table].represent=lambda table:shn_list_item(table,resource='shelter',action='display')15 #db[table].represent=lambda table:shn_list_item(table,resource='shelter',action='display') 16 16 db[table].uuid.requires=IS_NOT_IN_DB(db,'%s.uuid' % table) 17 17 title_create=T('Add Shelter') … … 27 27 msg_record_deleted=T('Shelter deleted') 28 28 msg_list_empty=T('No Shelters currently registered') 29 exec('s3.crud_strings.%s=Storage(title_create=title_create, title_display=title_display, title_list=title_list, title_update=title_update, subtitle_create=subtitle_create, subtitle_list=subtitle_list, label_list_button=label_list_button, label_create_button=label_create_button, msg_record_created=msg_record_created, msg_record_modified=msg_record_modified, msg_record_deleted=msg_record_deleted, msg_list_empty=msg_list_empty)' % table)29 s3.crud_strings[table]=Storage(title_create=title_create, title_display=title_display, title_list=title_list, title_update=title_update, subtitle_create=subtitle_create, subtitle_list=subtitle_list, label_list_button=label_list_button, label_create_button=label_create_button, msg_record_created=msg_record_created, msg_record_modified=msg_record_modified, msg_record_deleted=msg_record_deleted, msg_list_empty=msg_list_empty) 30 30 }}} 31 31 These optional settings can also be set, if-desired: 32 32 {{{ 33 exec('s3.listonly.%s=1' % table)# Don't allow resources to be creatable from List view34 exec('s3.undeletable.%s=1' % table)# Don't allow resources to be deletable from List/Display views33 s3.listonly[table]=1 # Don't allow resources to be creatable from List view 34 s3.undeletable[table]=1 # Don't allow resources to be deletable from List/Display views 35 35 }}} 36 36 … … 111 111 if representation=="html": 112 112 if t2.logged_in and s3.deletable: 113 db[ '%s' %table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display',extra="INPUT(_type='checkbox',_class='delete_row',_name='%s' % resource,_id='%i' % table.id)")113 db[table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display',extra="INPUT(_type='checkbox',_class='delete_row',_name='%s' % resource,_id='%i' % table.id)") 114 114 else: 115 db[ '%s' %table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display')115 db[table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display') 116 116 list=t2.itemize(table) 117 if list=="No data":117 if list=="None": 118 118 list=s3.crud_strings.msg_list_empty 119 119 title=s3.crud_strings.title_list … … 151 151 elif representation=="ajax": 152 152 if t2.logged_in and s3.deletable: 153 db[ '%s' %table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display',extra="INPUT(_type='checkbox',_class='delete_row',_name='%s' % resource,_id='%i' % table.id)")153 db[table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display',extra="INPUT(_type='checkbox',_class='delete_row',_name='%s' % resource,_id='%i' % table.id)") 154 154 else: 155 db[ '%s' %table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display')155 db[table].represent=lambda table:shn_list_item(table,resource='%s' % resource,action='display') 156 156 list=t2.itemize(table) 157 157 if list=="No data": … … 174 174 import gluon.contenttype 175 175 response.headers['Content-Type']=gluon.contenttype.contenttype('.csv') 176 query=db[ '%s' %table].id>0176 query=db[table].id>0 177 177 response.headers['Content-disposition']="attachment; filename=%s_%s_list.csv" % (request.env.server_name,resource) 178 178 return str(db(query).select()) … … 197 197 if representation=="html": 198 198 try: 199 db[ '%s' % table].displays=s3.crud_fields['%s' %table]199 db[table].displays=s3.crud_fields[table] 200 200 except: 201 201 pass … … 227 227 import gluon.contenttype 228 228 response.headers['Content-Type']=gluon.contenttype.contenttype('.csv') 229 query=db[ '%s' %table].id==t2.id229 query=db[table].id==t2.id 230 230 response.headers['Content-disposition']="attachment; filename=%s_%s_%d.csv" % (request.env.server_name,resource,t2.id) 231 231 return str(db(query).select()) … … 302 302 if session.s3.audit_write: 303 303 old_value = [] 304 _old_value=db(db[ '%s' %table].id==t2.id).select()[0]304 _old_value=db(db[table].id==t2.id).select()[0] 305 305 for field in _old_value: 306 306 old_value.append(field+':'+str(_old_value[field])) … … 346 346 if session.s3.audit_write: 347 347 old_value = [] 348 _old_value=db(db[ '%s' %table].id==t2.id).select()[0]348 _old_value=db(db[table].id==t2.id).select()[0] 349 349 for field in _old_value: 350 350 old_value.append(field+':'+str(_old_value[field]))