Changes between Version 15 and Version 16 of DeveloperGuidelines/Tutorial/RESTCustomisation
- Timestamp:
- 03/03/14 20:48:04 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines/Tutorial/RESTCustomisation
v15 v16 104 104 # Similar, the ID of the requested record can be found in: 105 105 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 106 111 107 112 ... … … 131 136 }}} 132 137 133 == How to Authorize aMethod ==138 == How to Authorize the Method == 134 139 135 140 When we implement a method handler that returns information, we need to request permission to do so: … … 159 164 Note 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. 160 165 161 == = Configuring a Method Handler ===166 == Configuring the Method Handler == 162 167 163 168 Eventually, we need to tell the REST API which function/class to call for the ''available_shelters'' qualifier: … … 174 179 *s3_metafields()) 175 180 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 177 184 self.set_method("pr", "group", method="available_shelters", action=AvailableShelters) 178 185 … … 184 191 185 192 Note 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 196 Now we want to see the list of available shelters on a ''component tab''. 197 198 Component 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 220 That's it ;)