| | 143 | |
| | 144 | === The sum of all values in a field... === |
| | 145 | |
| | 146 | The case: |
| | 147 | 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. |
| | 148 | |
| | 149 | Let's go: |
| | 150 | |
| | 151 | First of all, we implement our method handler as before: |
| | 152 | |
| | 153 | {{{ |
| | 154 | def shn_xxx_yyy_report(r, **attr): |
| | 155 | |
| | 156 | # Report generating code goes here |
| | 157 | |
| | 158 | s3xrc.model.set_method("xxx", "yyy", method="report", action=shn_xxx_yyy_report) |
| | 159 | }}} |
| | 160 | |
| | 161 | Now we add the HTML representation: |
| | 162 | |
| | 163 | {{{ |
| | 164 | def shn_xxx_yyy_report(r, **attr): |
| | 165 | |
| | 166 | if r.representation == "html": |
| | 167 | output = dict() |
| | 168 | return output |
| | 169 | |
| | 170 | s3xrc.model.set_method("xxx", "yyy", method="report", action=shn_xxx_yyy_report) |
| | 171 | }}} |
| | 172 | |