Changes between Version 3 and Version 4 of JoinedResourceController
- Timestamp:
- 09/09/09 23:19:17 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
JoinedResourceController
v3 v4 3 3 = Joined Resource Controller = 4 4 5 * Code: [https://code.launchpad.net/~flavour/sahana/sahanapy-trunk Main Trunk] Revision 2 75+5 * Code: [https://code.launchpad.net/~flavour/sahana/sahanapy-trunk Main Trunk] Revision 280+ 6 6 7 Th e '''Joined Resource Controller''' provides a RESTful API for joined resources analogous to the generic [wiki:BluePrintRESTImplementation shn_rest_controller].7 This extends the single-table [wiki:BluePrintRESTImplementation REST Implementation] for requests for joined resources. 8 8 9 A joined resource request is a request ona resource ("joined resource") in dependency of a join to another table ("primary resource").9 A joined resource request is a request for a resource ("joined resource") in dependency of a join to another table ("primary resource"). 10 10 11 11 In this implementation, these joins can be 1:1 or 1:N, and they can be natural joins (same key field in both tables) or primary/foreign key matches, where the primary key is always the 'id' field in the primary table. … … 13 13 The controller function for this is: 14 14 15 * '''shn_ jr_rest_controller''' (defined in models/01_jr_controller.py)15 * '''shn_rest_controller''' (defined in models/01_RESTlike_controller.py) 16 16 17 17 == Model == … … 53 53 No definitions are required at the primary resource, just define the table as usual. 54 54 55 - Of course, shn_jr_rest_controller is deletion status aware.56 57 55 == Controller == 58 56 59 shn_jr_rest_controller takes (almost) the same settings and arguments as shn_rest_controller:57 As usual: 60 58 61 59 {{{ 62 60 def person(): 63 61 crud.settings.delete_onvalidation=shn_pentity_ondelete 64 return shn_ jr_rest_controller(module, 'person', main='first_name', extra='last_name',62 return shn_rest_controller(module, 'person', main='first_name', extra='last_name', 65 63 pheader=shn_pr_pheader, 66 64 onvalidation=lambda form: shn_pentity_onvalidation(form, table='pr_person', entity_class=1), … … 68 66 }}} 69 67 70 "Almost" means with exception of the optional '''pheader''' argument:This helps you to display some information about the primary resource record in the view while operating on a joined resource (e.g. the person's name and ID, when displaying a list of available images for this person). You may pass static content, or a function or lambda to produce content, which is to be forwarded as ''pheader'' variable to the view.68 New: the optional '''pheader''' argument. This helps you to display some information about the primary resource record in the view while operating on a joined resource (e.g. the person's name and ID, when displaying a list of available images for this person). You may pass static content, or a function or lambda to produce content, which is to be forwarded as ''pheader'' variable to the view. 71 69 72 70 If you pass a function or lambda, it has to take 5 arguments: … … 102 100 You may even pass the record ID of the joined resource at the end of the arguments list to access a particular record - which would produce an error message if these two records do not belong together. 103 101 102 The data format of the request can be passed: 103 104 * as extension to the primary resource, e.g. http://localhost:8000/sahana/pr/person.xml/1 105 * as extension to the joined resource, e.g. http://localhost:8000/sahana/pr/person/1/address.xml 106 * as variable "format", e.g. http://localhost:8000/sahana/pr/person/1/address?format=xml 107 108 '''Policy:''' ''"?format="'' overrides ''joined resource extension'' overrides ''resource extension'' 109 104 110 == Plug-In Resource Actions == 105 111 106 You may plug in custom resource actions to shn_ jr_rest_controller, e.g. if you have a custom search function for a resource.112 You may plug in custom resource actions to shn_rest_controller, e.g. if you have a custom search function for a resource. 107 113 108 114 Example: