def delete_contact(contactId): session = Session() contact_obj = session.query(Contacts).filter_by(id=contactId).first() session.delete(contact_obj) session.commit() session.close() return '', 201
def delete_opp(oppId): session = Session() opp = session.query(Opp).filter_by(id=oppId).first() session.delete(opp) session.commit() session.close() return '', 201
def delete_exam(examId): session = Session() exam = session.query(Exam).filter_by(id=examId).first() session.delete(exam) session.commit() session.close() return '', 201
def get_ticket_id(ticketId): session = Session() ticket_objects = session.query(Tickets).filter_by(id=ticketId).first() schema = TicketSchema() tickets = schema.dump(ticket_objects) # serializing as JSON session.close() return jsonify(tickets)
def update_ticket(ticketId): session = Session() posted_ticket = TicketSchema().load(request.get_json()) session.query(Tickets).filter_by(id=ticketId).update( posted_ticket, synchronize_session=False) session.commit() session.close() return posted_ticket, 201
def authenticate(email, password): session = Session() user = session.query(User).filter_by(email=email).first() session.close() if user and pbkdf2_sha256.verify(password, user.password): return user else: return None
def toggle_complete_task(): id_object = request.get_json() session = Session() task = session.query(Task).filter(Task.id == id_object['id']).first() task.is_finished = not task.is_finished session.commit() session.close() return 'OK'
def remove_task(): id_object = request.get_json() session = Session() session.query(Task).filter(Task.id == id_object['id']).delete() session.commit() session.close() return 'OK'
def add_contact(): pc = request.get_json() session = Session() contact = Contacts(pc['name'], pc['email'], pc['phone'], pc['company_name']) session.add(contact) session.commit() session.close() return jsonify({'ok': True, 'message': 'Contact created!'}), 201
def update_contact(contactId): session = Session() pc = request.get_json() # contact_obj = pc['name'],pc['email'],pc['phone'],pc['company_name']) session.query(Contacts).filter_by(id=contactId).update( pc, synchronize_session=False) session.commit() session.close() return jsonify(pc), 201
def get_users(): session = Session() user_objects = session.query(User).all() result = [{ "id": user.id, "name": (user.fname + " " + user.lname) } for user in user_objects] # serializing as JSON session.close() return jsonify(result)
def log_time(): logged_time = LoggedTimeSchema(only=('application_name', 'logged_time_seconds', 'window_title'), many=True) \ .load(request.get_json()) logged_time_objects = list(map(lambda x: LoggedTime(**x), logged_time)) session = Session() session.bulk_save_objects(logged_time_objects) session.commit() session.close() return 'OK'
def create_task(): task = TaskSchema(only=('title', 'description', 'estimated_time_minutes', 'deadline')). \ load(request.get_json()) task_objects = Task(**task) session = Session() session.add(task_objects) session.commit() session.close() return 'OK'
def delete_ticket(ticketId): session = Session() ticket_obj = session.query(Tickets).filter_by(id=ticketId).first() session.delete(ticket_obj) session.commit() ticket_objects = session.query(Tickets).order_by( Tickets.status, Tickets.created_at.desc()).all() schema = TicketSchema(many=True) tickets = schema.dump(ticket_objects) session.close() return jsonify(tickets)
def get_tickets(): arg = request.args session = Session() # fetching from the database sort_arg = arg.get('sortedBy', default='created_at desc', type=str) builder = session.query(Tickets) ticket_objects = builder.order_by(Tickets.status, text(sort_arg)).all() schema = TicketSchema(many=True) tickets = schema.dump(ticket_objects) # serializing as JSON session.close() return jsonify(tickets)
def get_exams(): # fetching from the database session = Session() exam_objects = session.query(Exam).all() # transforming into JSON-serializable objects schema = ExamSchema(many=True) exams = schema.dump(exam_objects) # serializing as JSON session.close() return jsonify(exams.data)
def get_exams(): # Fetch from DB session = Session() exam_objects = session.query(Exam).all() # Transform into json-serialized objects schema = ExamSchema(many=True) exams = schema.dump(exam_objects) # serializing as JSON session.close() return jsonify(exams)
def get_tasks(): # fetching from the database session = Session() task_objects = session.query(Task).all() # transforming into JSON-serializable objects schema = TaskSchema(many=True) tasks = schema.dump(task_objects) # serializing as JSON session.close() return jsonify(tasks)
def get_opps(): # fetching from the database session = Session() opp_objects = session.query(Opp).all() # transforming into JSON-serializable objects schema = OppSchema(many=True) opps = schema.dump(opp_objects) # serializing as JSON session.close() return jsonify(opps.data)
def get_booked_time(): # fetching from the database session = Session() booked_time_objects = session.query(LoggedTime).filter(LoggedTime.task_id != NO_TASK).all() # transforming into JSON-serializable objects schema = LoggedTimeSchema(many=True) booked_time = schema.dump(booked_time_objects) # serializing as JSON session.close() return jsonify(booked_time)
def get_manufacturers(): # fetching from the database session = Session() manufacturer_objects = session.query(Manufacturer).all() # transforming into JSON-serializable objects schema = ManufacturerSchema(many=True) manufacturers = schema.dump(manufacturer_objects) # serializing as JSON session.close() return jsonify(manufacturers.data)
def get_contact_id(contactId): session = Session() contact_obj = session.query(Contacts).filter_by(id=contactId).first() result = { "id": contact_obj.id, "name": contact_obj.name, "email": contact_obj.email, "phone": contact_obj.phone, "company_name": contact_obj.company_name, } # serializing as JSON session.close() return jsonify(result)
def add_ticket(): posted_ticket = TicketSchema(only=('subject', 'description', 'status', 'source', 'requester_id', 'responder_id', 'category')).load(request.get_json()) ticket = Tickets(**posted_ticket) # persist exam session = Session() session.add(ticket) session.commit() # return created exam new_ticket = TicketSchema().dump(ticket) session.close() return jsonify(new_ticket), 201
def update_group(group_id, group_list): logger = logging.getLogger(__name__) lifx = LifxLAN() db = Session() group = db.query(Group_d).filter_by(id=group_id).first() is_new = group.id not in group_list is_updated = group.devices_updated if is_new or is_updated: status = [] if is_new: status.append("New") if is_updated: status.append("Updated") new_group = None try: new_group = GroupExt( lifx.get_devices_by_name( [device.name for device in group.devices] ).get_device_list() ) except WorkflowException: logger.warning( "Group failed - WorkflowException", exc_info=True ) if new_group is not None: status_str = ",".join(status) devices_str = ", ".join( [device.name for device in group.devices] ) logger.info( "{} - Group: {}\nDevices: {}" .format(status_str, group.name, devices_str) ) group_list[group.id] = new_group group.devices_updated = False if len(group.devices) != len(new_group.get_device_list()): # just using this as a flag to force it to try again group.devices_updated = True db.commit() db.close()
def add_exam(): # Mount exam object posted_exam = ExamSchema(only=('title', 'description')).load(request.get_json()) exam = Exam(**posted_exam.data, created_by = "HTTP post request") # Persist exam session = Session() session.add(exam) session.commit() # Return created exam new_exam = ExamSchema().dump(exam).data session.close() return jsonify(new_exam), 201
def book_time(): data=request.get_json() application_name = data.get('application_name') task_id = data.get('task_id') logging.info(f"Logging application {application_name} on task_id {task_id}") session = Session() booked_time_objects: List[LoggedTime] = session.query(LoggedTime).\ filter(LoggedTime.application_name==application_name).\ filter(LoggedTime.task_id==-1).all() for booked_time_object in booked_time_objects: booked_time_object.task_id = task_id session.commit() session.close() return 'OK'
def add_user(): # posted_data = UserSchema(only=('email','password','fname','lname')).load(json.loads(request.get_json())) # posted_data = request.get_json() # user = User(**posted_data) pd = request.get_json() user = User(pd['email'], pd['password'], pd['fname'], pd['lname']) session = Session() if session.query(User).filter_by(email=user.email).first(): return jsonify( {'message': 'User {} already exists'.format(user.email)}), 401 user.password = pbkdf2_sha256.hash(user.password) session.add(user) session.commit() session.close() return jsonify({'ok': True, 'message': 'User created!'}), 201
def get_manufacturers_factories(): id = request.args.get('id') # fetching from the database session = Session() factory_objects = session.query(Factory).filter( Factory.manufacturer_id == id) # transforming into JSON-serializable objects schema = FactorySchema(many=True) factories = schema.dump(factory_objects) # serializing as JSON session.close() return jsonify(factories.data)
def get_manufacturer_by_id(): id = request.args.get('id') # fetching from the database session = Session() manufacturer_object = session.query(Manufacturer).get(id) # transforming into JSON-serializable objects schema = ManufacturerSchema() manufacturer = schema.dump(manufacturer_object) # serializing as JSON session.close() return jsonify(manufacturer.data)
def get_factory_by_id(): id = request.args.get('id') # fetching from the database session = Session() factory_object = session.query(Factory).get(id) # transforming into JSON-serializable objects schema = FactorySchema() factory = schema.dump(factory_object) # serializing as JSON session.close() return jsonify(factory.data)