Changes between Version 3 and Version 4 of JoinedResourceController


Ignore:
Timestamp:
09/09/09 23:19:17 (13 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • JoinedResourceController

    v3 v4  
    33= Joined Resource Controller =
    44
    5   * Code: [https://code.launchpad.net/~flavour/sahana/sahanapy-trunk Main Trunk] Revision 275+
     5  * Code: [https://code.launchpad.net/~flavour/sahana/sahanapy-trunk Main Trunk] Revision 280+
    66
    7 The '''Joined Resource Controller''' provides a RESTful API for joined resources analogous to the generic [wiki:BluePrintRESTImplementation shn_rest_controller].
     7This extends the single-table [wiki:BluePrintRESTImplementation REST Implementation] for requests for joined resources.
    88
    9 A joined resource request is a request on a resource ("joined resource") in dependency of a join to another table ("primary resource").
     9A joined resource request is a request for a resource ("joined resource") in dependency of a join to another table ("primary resource").
    1010
    1111In 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.
     
    1313The controller function for this is:
    1414
    15     * '''shn_jr_rest_controller''' (defined in models/01_jr_controller.py)
     15    * '''shn_rest_controller''' (defined in models/01_RESTlike_controller.py)
    1616
    1717== Model ==
     
    5353No definitions are required at the primary resource, just define the table as usual.
    5454
    55   - Of course, shn_jr_rest_controller is deletion status aware.
    56 
    5755== Controller ==
    5856
    59 shn_jr_rest_controller takes (almost) the same settings and arguments as shn_rest_controller:
     57As usual:
    6058
    6159{{{
    6260def person():
    6361    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',
    6563        pheader=shn_pr_pheader,
    6664        onvalidation=lambda form: shn_pentity_onvalidation(form, table='pr_person', entity_class=1),
     
    6866}}}
    6967
    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.
     68New: 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.
    7169
    7270If you pass a function or lambda, it has to take 5 arguments:
     
    102100You 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.
    103101
     102The 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
    104110== Plug-In Resource Actions ==
    105111
    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.
     112You may plug in custom resource actions to shn_rest_controller, e.g. if you have a custom search function for a resource.
    107113
    108114Example: