Changes between Version 42 and Version 43 of RESTController
- Timestamp:
- 05/27/10 22:15:56 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
RESTController
v42 v43 5 5 Available since: [https://code.launchpad.net/sahana-eden Main Trunk] Revision 358+ 6 6 7 The so called '''REST Controller''' (function ''shn_rest_controller()'') is a wrapper function for [wiki:S3REST], which provides generic CRUD method handlers. These method handlers as well as the REST controller itself are implemented in models/01_crud.py.7 The so called '''REST Controller''' (function ''shn_rest_controller()'') is a wrapper function for [wiki:S3REST], which provides generic CRUD method handlers. These method handlers as well as the REST controller itself are implemented in {{{models/01_crud.py}}}. 8 8 9 9 '''[wiki:S3REST]''' provides a generic '''RESTful API''' ([http://en.wikipedia.org/wiki/Representational_State_Transfer Representational State Transfer]) for Sahana Eden database resources, i.e. it can map HTTP requests to data resources and function calls. In particular, it maps resource addresses (=URL's) and HTTP methods (=GET, PUT, DELETE etc.) to CRUD actions, and then invokes so called ''method handlers'' (provided by the calling controller via hooks) to execute those actions (important: S3REST itself does not manipulate any data!). … … 63 63 64 64 {{{ 65 resource = 'image'66 table = module + '_'+ resource65 resource = "image" 66 table = module + "_" + resource 67 67 db.define_table(table, timestamp, uuidstamp, deletion_status, 68 68 pr_pe_id, 69 69 opt_pr_image_type, 70 Field( 'title'),71 Field( 'image', 'upload', autodelete=True),72 Field( 'description'),73 Field( 'comment'),70 Field("title"), 71 Field("image", "upload", autodelete=True), 72 Field("description"), 73 Field("comment"), 74 74 migrate=migrate) 75 75 … … 77 77 s3xrc.model.add_component(module, resource, 78 78 multiple=True, 79 joinby= 'pr_pe_id',79 joinby="pr_pe_id", 80 80 deletable=True, 81 81 editable=True, 82 list_fields = [ 'id', 'opt_pr_image_type', 'image', 'title', 'description'])82 list_fields = ["id", "opt_pr_image_type", "image", "title", "description"]) 83 83 }}} 84 84 … … 93 93 - ''tablename'' is the name of the respective primary table 94 94 - ''fieldname'' the name of the foreign key in the component table that points to the ''id'' field in the primary table 95 - e.g. {{{joinby = dict(pr_person= 'person_id')}}}95 - e.g. {{{joinby = dict(pr_person="person_id")}}} 96 96 - '''fields''' is a list of the fields in the component that shall appear in list views: 97 97 - if omitted or set to None, all readable fields will be included … … 106 106 def person(): 107 107 crud.settings.delete_onvalidation = shn_pentity_ondelete 108 return shn_rest_controller(module, 'person', main='first_name', extra='last_name',108 return shn_rest_controller(module, "person", main="first_name", extra="last_name", 109 109 pheader=shn_pr_pheader, 110 onvalidation=lambda form: shn_pentity_onvalidation(form, table= 'pr_person', entity_class=1),110 onvalidation=lambda form: shn_pentity_onvalidation(form, table="pr_person", entity_class=1), 111 111 onaccept=None) 112 112 }}} … … 130 130 def kit(): 131 131 "REST CRUD controller" 132 response.s3.formats.pdf = URL(r=request, f= 'kit_export_pdf')133 response.s3.formats.xls = URL(r=request, f= 'kit_export_xls')132 response.s3.formats.pdf = URL(r=request, f="kit_export_pdf") 133 response.s3.formats.xls = URL(r=request, f="kit_export_xls") 134 134 if len(request.args) == 2: 135 crud.settings.update_next = URL(r=request, f= 'kit_item', args=request.args[1])136 return shn_rest_controller(module, 'kit', main='code', onaccept=lambda form: kit_total(form))135 crud.settings.update_next = URL(r=request, f="kit_item", args=request.args[1]) 136 return shn_rest_controller(module, "kit", main="code", onaccept=lambda form: kit_total(form)) 137 137 }}} 138 138 … … 142 142 def report_overdue(): 143 143 "Report on Overdue Invoices - those unpaid 30 days after receipt" 144 response.title = T( 'Overdue Invoices')144 response.title = T("Overdue Invoices") 145 145 overdue = datetime.date.today() - timedelta(days=30) 146 146 response.s3.filter = (db.fin_invoice.date_out==None) & (db.fin_invoice.date_in < overdue) 147 147 s3.crud_strings.fin_invoice.title_list = response.title 148 s3.crud_strings.fin_invoice.msg_list_empty = T( 'No Invoices currently overdue')149 return shn_rest_controller(module, 'invoice', deletable=False, listadd=False)148 s3.crud_strings.fin_invoice.msg_list_empty = T("No Invoices currently overdue") 149 return shn_rest_controller(module, "invoice", deletable=False, listadd=False) 150 150 }}} 151 151 … … 161 161 {{{ 162 162 # Plug into REST controller 163 s3xrc.model.set_method(module, 'person', method='search_simple', action=shn_pr_person_search_simple )163 s3xrc.model.set_method(module, "person", method="search_simple", action=shn_pr_person_search_simple ) 164 164 }}} 165 165 … … 175 175 def inbox(): 176 176 " RESTlike CRUD controller for inbox" 177 person = db(db.pr_person.uuid ==auth.user.person_uuid).select(db.pr_person.id)177 person = db(db.pr_person.uuid == auth.user.person_uuid).select(db.pr_person.id) 178 178 response.s3.filer = (db.msg_inbox.person_id == person[0].id) 179 s3xrc.model.set_method(module, 'inbox', method='create', action = restricted_method)180 return shn_rest_controller(module, 'inbox', listadd=False, editable = False)179 s3xrc.model.set_method(module, "inbox", method="create", action = restricted_method) 180 return shn_rest_controller(module, "inbox", listadd=False, editable = False) 181 181 182 182 }}}