def assign_dev_ticket(): userInfo = session.get('userProfile', 'not set') if userInfo['role'] != 'dev': abort(401) # Fetch the ticket that is to be assigned and assign the developer to it ticket = Ticket.query.get(request.form.get('ticket_id')) ticket.users_id = request.form.get('user_name') ticket.update() #insert Ticket History of assign the Devloper new_id = db.session.query(func.max(Ticket_history.id)) if new_id[0][0] == None: new_id[0][0] = 0 ticket_history = Ticket_history(new_id[0][0] + 1, ticket.t_id, ticket.users_id, ticket.t_status, DATE, ticket.t_priority) try: ticket_history.insert() except: print('error') #insert comment of which User assigned the Dev userInfo = session.get('userProfile', 'not set') user1 = userInfo['id'] user2 = Users.query.with_entities( Users.users_name).filter(Users.users_id == ticket.users_id).one() text = user2[0] + ' assigned to this ticket' new_id = db.session.query(func.max(Comment.c_id)) if new_id[0][0] == None: new_id[0][0] = 0 comment = Comment(new_id[0][0] + 1, ticket.t_id, user1, DATE, text) try: comment.insert() except: print(sys.exc_info()) #Insert notification for assignnig the Dev notify = Notification(ticket.t_id, ticket.users_id, 'assigned') try: notify.insert() except: print(sys.exc_info()) return redirect('/ticket-details/' + request.form.get('ticket_id'))