| | 221 | |
|---|
| | 222 | def _do_delete(self, req, db, id): |
|---|
| | 223 | req.perm.assert_permission('REPORT_DELETE') |
|---|
| | 224 | |
|---|
| | 225 | if req.args.has_key('cancel'): |
|---|
| | 226 | req.redirect(req.href.preport(id)) |
|---|
| | 227 | |
|---|
| | 228 | cursor = db.cursor() |
|---|
| | 229 | cursor.execute("DELETE FROM personal_reports WHERE id=%s AND user=%s", (id,req.authname)) |
|---|
| | 230 | db.commit() |
|---|
| | 231 | req.redirect(req.href.preport()) |
|---|
| | 232 | |
|---|
| | 233 | def _do_save(self, req, db, id): |
|---|
| | 234 | req.perm.assert_permission('REPORT_MODIFY') |
|---|
| | 235 | |
|---|
| | 236 | self.log.debug('Executing preport:_do_save %s for %s', id, req.authname) |
|---|
| | 237 | if not req.args.has_key('cancel'): |
|---|
| | 238 | self.log.debug(' keys: ' + '|'.join(req.args.keys())) |
|---|
| | 239 | self.log.debug(' values: ' + '|'.join(req.args.values())) |
|---|
| | 240 | title = req.args.get('title', '') |
|---|
| | 241 | query = req.args.get('query', '') |
|---|
| | 242 | description = req.args.get('description', '') |
|---|
| | 243 | cursor = db.cursor() |
|---|
| | 244 | cursor.execute("UPDATE personal_reports SET title=%s,query=%s,description=%s " |
|---|
| | 245 | "WHERE id=%s AND user=%s", (title, query, description, id, req.authname)) |
|---|
| | 246 | db.commit() |
|---|
| | 247 | req.redirect(req.href.preport(id)) |
|---|
| | 248 | |
|---|
| | 249 | def _render_confirm_delete(self, req, db, id): |
|---|
| | 250 | req.perm.assert_permission('REPORT_DELETE') |
|---|
| | 251 | |
|---|
| | 252 | cursor = db.cursor() |
|---|
| | 253 | cursor.execute("SELECT title FROM personal_reports WHERE id = %s AND user=%s", (id,req.authname)) |
|---|
| | 254 | row = cursor.fetchone() |
|---|
| | 255 | if not row: |
|---|
| | 256 | raise TracError('Personal report %s does not exist for user %s.' % (id, req.authname), |
|---|
| | 257 | 'Invalid Personal Report Number') |
|---|
| | 258 | req.hdf['title'] = 'Delete Personal Report {%s} %s' % (id, row[0]) |
|---|
| | 259 | req.hdf['report'] = { |
|---|
| | 260 | 'id': id, |
|---|
| | 261 | 'mode': 'delete', |
|---|
| | 262 | 'title': row[0], |
|---|
| | 263 | 'href': req.href.preport(id) |
|---|
| | 264 | } |
|---|
| | 265 | |
|---|
| | 266 | def _render_editor(self, req, db, id, copy=False): |
|---|
| | 267 | self.log.debug('Executing preport:_render_editor %s for %s', id, req.authname) |
|---|
| | 268 | |
|---|
| | 269 | if id == -1: |
|---|
| | 270 | self.log.debug(' Creating new personal report') |
|---|
| | 271 | req.perm.assert_permission('REPORT_CREATE') |
|---|
| | 272 | title = query = description = '' |
|---|
| | 273 | else: |
|---|
| | 274 | self.log.debug(' Editing personal report') |
|---|
| | 275 | req.perm.assert_permission('REPORT_MODIFY') |
|---|
| | 276 | cursor = db.cursor() |
|---|
| | 277 | cursor.execute("SELECT title,description,query FROM personal_reports " |
|---|
| | 278 | "WHERE id=%s AND user=%s", (id,req.authname)) |
|---|
| | 279 | row = cursor.fetchone() |
|---|
| | 280 | if not row: |
|---|
| | 281 | raise TracError('Report %s does not exist.' % id, |
|---|
| | 282 | 'Invalid Report Number') |
|---|
| | 283 | title = row[0] or '' |
|---|
| | 284 | description = row[1] or '' |
|---|
| | 285 | query = row[2] or '' |
|---|
| | 286 | |
|---|
| | 287 | if copy: |
|---|
| | 288 | title += ' (copy)' |
|---|
| | 289 | |
|---|
| | 290 | if copy or id == -1: |
|---|
| | 291 | req.hdf['title'] = 'Create New Personal Report' |
|---|
| | 292 | req.hdf['report.href'] = req.href.preport() |
|---|
| | 293 | req.hdf['report.action'] = 'new' |
|---|
| | 294 | else: |
|---|
| | 295 | req.hdf['title'] = 'Edit Personal Report {%d} %s' % (id, title) |
|---|
| | 296 | req.hdf['report.href'] = req.href.preport(id) |
|---|
| | 297 | req.hdf['report.action'] = 'edit' |
|---|
| | 298 | |
|---|
| | 299 | req.hdf['report.id'] = id |
|---|
| | 300 | req.hdf['report.mode'] = 'edit' |
|---|
| | 301 | req.hdf['report.title'] = title |
|---|
| | 302 | req.hdf['report.sql'] = query |
|---|
| | 303 | req.hdf['report.description'] = description |
|---|
| | 304 | self.log.debug('%s', req.hdf['report.href']) |
|---|