| | 200 | class TicketWorkflowOpStatusPrevious(TicketWorkflowOpBase): |
|---|
| | 201 | """Sets the status to the previous status |
|---|
| | 202 | |
|---|
| | 203 | Don't forget to add the `TicketWorkflowOpStatusPrevious` to the workflow |
|---|
| | 204 | option in [ticket]. |
|---|
| | 205 | If there is no workflow option, the line will look like this: |
|---|
| | 206 | |
|---|
| | 207 | workflow = ConfigurableTicketWorkflow,TicketWorkflowOpStatusPrevious |
|---|
| | 208 | """ |
|---|
| | 209 | |
|---|
| | 210 | _op_name = 'set_status_to_previous' |
|---|
| | 211 | |
|---|
| | 212 | # ITicketActionController methods |
|---|
| | 213 | |
|---|
| | 214 | def render_ticket_action_control(self, req, ticket, action): |
|---|
| | 215 | """Returns the action control""" |
|---|
| | 216 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 217 | label = actions[action]['name'] |
|---|
| | 218 | new_status = self._new_status(ticket) |
|---|
| | 219 | if new_status != ticket['status']: |
|---|
| | 220 | hint = 'The status will change to %s' % new_status |
|---|
| | 221 | else: |
|---|
| | 222 | hint = '' |
|---|
| | 223 | control = tag('') |
|---|
| | 224 | return (label, control, hint) |
|---|
| | 225 | |
|---|
| | 226 | def get_ticket_changes(self, req, ticket, action): |
|---|
| | 227 | """Returns the change of status.""" |
|---|
| | 228 | return {'status': self._new_status(ticket)} |
|---|
| | 229 | |
|---|
| | 230 | def _new_status(self, ticket): |
|---|
| | 231 | """Determines the new status""" |
|---|
| | 232 | db = self.env.get_db_cnx() |
|---|
| | 233 | cursor = db.cursor() |
|---|
| | 234 | cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " \ |
|---|
| | 235 | "AND field='status' ORDER BY -time", (ticket.id, )) |
|---|
| | 236 | row = cursor.fetchone() |
|---|
| | 237 | if row: |
|---|
| | 238 | status = row[0] |
|---|
| | 239 | else: # The status has never changed. |
|---|
| | 240 | status = 'new' |
|---|
| | 241 | return status |
|---|
| | 242 | |
|---|
| | 243 | |
|---|