def open(self, user_id, title, description, handler_id=None): if handler_id is None: handler_id = user_id with transaction.manager: now = datetime.now() d = self.descriptions.new(description) t = Ticket() t.title = title t.description_id = d.id t.created = now self.session.add(t) ticket = self.session.merge(t) change = TicketStatusChange() change.ticket_id = ticket.id change.status = "opened" change.reason = "New Ticket" change.description_id = d.id change.changed = now change.changed_by_id = user_id change.handler_id = handler_id self.session.add(change) change = self.session.merge(change) current = TicketCurrentStatus() current.ticket_id = ticket.id current.last_change_id = change.id current.created = ticket.created current.last_change = change.changed current.status = change.status current.changed_by_id = user_id current.handler_id = handler_id self.session.add(current) return self.session.merge(ticket)
def update_ticket(self, ticket_id, user_id, status, reason, handler_id, description=None): now = datetime.now() with transaction.manager: ticket = self.get(ticket_id) change = TicketStatusChange() change.ticket_id = ticket_id change.status = status change.reason = reason change.changed = now change.changed_by_id = user_id change.handler_id = handler_id if description is None: change.description_id = ticket.description_id self.session.add(change) change = self.session.merge(change) current = self.session.query(TicketCurrentStatus).get(ticket_id) current.last_change = now current.last_change_id = change.id current.status = status current.changed_by_id = user_id current.handler_id = handler_id current = self.session.merge(current) return self.session.merge(change)