Changes between Version 15 and Version 16 of DeveloperGuidelines/Tutorial/RESTCustomisation


Ignore:
Timestamp:
03/03/14 20:48:04 (8 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Tutorial/RESTCustomisation

    v15 v16  
    104104            # Similar, the ID of the requested record can be found in:
    105105            record_id = r.id
     106
     107            # Being a S3Request instance, r contains a number of other important details
     108            # to introspect the request, the requested resource, as well as useful helper
     109            # functions for processing it
     110            # Check: http://eden.sahanafoundation.org/wiki/S3/S3Request
    106111
    107112            ...
     
    131136}}}
    132137
    133 == How to Authorize a Method ==
     138== How to Authorize the Method ==
    134139
    135140When we implement a method handler that returns information, we need to request permission to do so:
     
    159164Note that "read" permission for the ''requested'' record (pr_group 5) is already checked ''before'' the method handler is called, so it does not need to be checked again. But for any other record from which we return information to the user, or any other method we intend to perform, we must first check permissions in the method handler.
    160165
    161 === Configuring a Method Handler ===
     166== Configuring the Method Handler ==
    162167
    163168Eventually, we need to tell the REST API which function/class to call for the ''available_shelters'' qualifier:
     
    174179                                  *s3_metafields())
    175180
    176         # Configure a custom method
     181        # Configure the custom method:
     182        # the "method" parameter defines the URL parameter needed to request this method (the method "name")
     183
    177184        self.set_method("pr", "group", method="available_shelters", action=AvailableShelters)
    178185
     
    184191
    185192Note that if the method handler is implemented as S3Method subclass, we do ''not'' need to instantiate it. It will be instantiated only when it is needed to process the request.
     193
     194== Put it on a Tab ==
     195
     196Now we want to see the list of available shelters on a ''component tab''.
     197
     198Component tabs are typically defined in the '''rheader''' function for the target table, so we check our ''rheader'' for ''pr_group'':
     199
     200{{{#!python
     201
     202    ...
     203    elif resourcename == "group":
     204
     205        rheader_fields = [["name"],
     206                          ["description"],
     207                         ]
     208
     209        tabs = [("Group Details", None),
     210                (T("Contact Data"), "contact"),
     211                (T("Members"), "group_membership"),
     212
     213                # We add our custom method here:
     214                (T("Find Shelter"), "available_shelters"),
     215
     216                ]
     217    ...
     218}}}
     219
     220That's it ;)