Changes between Version 15 and Version 16 of S3XRC/ResourceReport
- Timestamp:
- 08/28/10 19:37:54 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3XRC/ResourceReport
v15 v16 1 [[TOC]] 1 2 = S3XRC Mini-Tutorial = 2 3 3 4 - [wiki:S3XRC_Recipes S3XRC Recipes and Tutorials] 4 == Report Function for your Resource == 5 6 === The idea === 5 6 == A Report function for your resource == 7 8 === Use-case === 7 9 8 10 You have a module {{{xxx}}} and within it a resource {{{yyy}}}, which has a number of components. You're providing CRUD functions for the resource and its components using {{{shn_rest_controller()}}}. … … 10 12 Now you want to provide a reporting function for this resource, where the user can select records using a search form and then generate a summary report that can be exported in various formats, among others XLS, PDF and SVG. 11 13 14 Our example: Your resource contains a "timestmp" field (type datetime) and a field "cost" (type double), and now the user shall select a time interval in aform, and your report function shall provide the sum of all "cost" for those records with a timestmp within the selected time interval. 15 12 16 This tutorial shows you how this can be integrated in the REST interface of your resource. 13 17 14 === Techniques to use===15 16 ==== Creat inga custom method handler ====18 === Techniques === 19 20 ==== Create a custom method handler ==== 17 21 18 22 Reporting is a method of your resource, the reporting function will therefore be implemented as a custom method handler. … … 49 53 meaning, it already implements a RESTful API for your reporting function, e.g. does the parsing/validating of the URL for you, implements the full range of URL queries for your resource and so forth. Nothing you need to care about now. 50 54 51 ==== Provid ing different Report Formats ====55 ==== Provide different report formats ==== 52 56 53 57 You want to provide the report in various formats, hence you need to know what format the user has requested. The best way is to check for the format that has been specified in the URL. … … 99 103 }}} 100 104 101 ==== How to get at the data ====105 ==== Get at the data ==== 102 106 103 107 How can you find out which data have to be processed by your reporting function, and yet more important: how can you get at them? … … 149 153 150 154 151 === The concrete case: Total costs within a time interval ===155 === Step by step: total costs within a time interval === 152 156 153 157 Your resource contains a "timestmp" field (type datetime) and a field "cost" (type double), and now the user shall select a time interval in aform, and your report function shall provide the sum of all "cost" for those records with a timestmp within the selected time interval. 154 158 155 159 Let's go: 160 161 ==== 1. Create a method handler ==== 162 156 163 First of all, we implement our method handler as before: 157 164 … … 163 170 s3xrc.model.set_method("xxx", "yyy", method="report", action=s3_xxx_yyy_report) 164 171 }}} 172 173 174 ==== 2. Add representations ==== 165 175 166 176 Then we add the HTML representation: … … 175 185 s3xrc.model.set_method("xxx", "yyy", method="report", action=s3_xxx_yyy_report) 176 186 }}} 187 188 ==== 3. Add the form ==== 177 189 178 190 The next step would be to provide a form to select the first and the last date of the interval. This would look like that: … … 202 214 }}} 203 215 216 ==== 4. Process the form data ==== 217 204 218 From this, we need to process the form data into two dates. We use {{{datetime}}} for that: 205 219 … … 218 232 219 233 }}} 234 235 ==== 5. Extend the resource query ==== 220 236 221 237 To select the corresponding records, we need to extend our query: … … 252 268 }}} 253 269 270 ==== 6. Retrieve the sum of costs ==== 271 254 272 From there, it is easy to select the sum of the "cost" field: 255 273 … … 292 310 output.update(result=result) 293 311 }}} 312 313 ==== 7. Add a view ==== 294 314 295 315 Done with the method handler! Here at a glance: … … 375 395 }}} 376 396 377 ...and that's all. 378 379 ...to be continued... 380 ...to be continued... 397 ...and that's it.