Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 5119:748ba87e1aca
Added a new cgi action restore. The opposite of (and a clone of) the existing retire action.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 03 Jul 2016 10:38:47 -0400 |
| parents | 156cbc1d182c |
| children | 894aa07be6cb |
comparison
equal
deleted
inserted
replaced
| 5118:57452bc6d989 | 5119:748ba87e1aca |
|---|---|
| 7 from roundup.cgi import exceptions, templating | 7 from roundup.cgi import exceptions, templating |
| 8 from roundup.mailgw import uidFromAddress | 8 from roundup.mailgw import uidFromAddress |
| 9 from roundup.exceptions import Reject, RejectRaw | 9 from roundup.exceptions import Reject, RejectRaw |
| 10 from roundup.anypy import urllib_ | 10 from roundup.anypy import urllib_ |
| 11 | 11 |
| 12 __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction', | 12 # Also add action to client.py::Client.actions property |
| 13 __all__ = ['Action', 'ShowAction', 'RetireAction', 'RestoreAction', 'SearchAction', | |
| 13 'EditCSVAction', 'EditItemAction', 'PassResetAction', | 14 'EditCSVAction', 'EditItemAction', 'PassResetAction', |
| 14 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction', | 15 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction', |
| 15 'NewItemAction', 'ExportCSVAction'] | 16 'NewItemAction', 'ExportCSVAction'] |
| 16 | 17 |
| 17 # used by a couple of routines | 18 # used by a couple of routines |
| 132 self.db.getclass(self.classname).retire(itemid) | 133 self.db.getclass(self.classname).retire(itemid) |
| 133 self.db.commit() | 134 self.db.commit() |
| 134 | 135 |
| 135 self.client.add_ok_message( | 136 self.client.add_ok_message( |
| 136 self._('%(classname)s %(itemid)s has been retired')%{ | 137 self._('%(classname)s %(itemid)s has been retired')%{ |
| 138 'classname': self.classname.capitalize(), 'itemid': itemid}) | |
| 139 | |
| 140 | |
| 141 class RestoreAction(Action): | |
| 142 name = 'restore' | |
| 143 permissionType = 'Edit' | |
| 144 | |
| 145 def handle(self): | |
| 146 """Restore the context item.""" | |
| 147 # ensure modification comes via POST | |
| 148 if self.client.env['REQUEST_METHOD'] != 'POST': | |
| 149 raise Reject(self._('Invalid request')) | |
| 150 | |
| 151 # if we want to view the index template now, then unset the itemid | |
| 152 # context info (a special-case for retire actions on the index page) | |
| 153 itemid = self.nodeid | |
| 154 if self.template == 'index': | |
| 155 self.client.nodeid = None | |
| 156 | |
| 157 # check permission | |
| 158 if not self.hasPermission('Restore', classname=self.classname, | |
| 159 itemid=itemid): | |
| 160 raise exceptions.Unauthorised(self._( | |
| 161 'You do not have permission to restore %(class)s' | |
| 162 ) % {'class': self.classname}) | |
| 163 | |
| 164 # do the restore | |
| 165 self.db.getclass(self.classname).restore(itemid) | |
| 166 self.db.commit() | |
| 167 | |
| 168 self.client.add_ok_message( | |
| 169 self._('%(classname)s %(itemid)s has been restored')%{ | |
| 137 'classname': self.classname.capitalize(), 'itemid': itemid}) | 170 'classname': self.classname.capitalize(), 'itemid': itemid}) |
| 138 | 171 |
| 139 | 172 |
| 140 class SearchAction(Action): | 173 class SearchAction(Action): |
| 141 name = 'search' | 174 name = 'search' |
