def mutate(root, info, data, id_from_token): degree = DegreeEnum.NOTSTATED a_level = AccessLevelEnum(data.access_level) if data.degree is not None: degree = DegreeEnum(data.degree) new_item = Item(title=data.title, owner_id=id_from_token, about=data.about, access_level=a_level, list_id=data.list_id, degree=degree, status='FREE', date_for_status=datetime.utcnow(), date_creation=datetime.utcnow()) try: db.add(new_item) commit_with_check(db) except: db.rollback() db.refresh(new_item) try: db.add( ItemPicture(item_id=new_item.id, path_to_picture='items/item_0.png')) commit_with_check(db) except: db.rollback() return AddItem(ok=True, message="Item added!", ID=new_item.id)
def mutate(self, info, data, id_from_token): a_level = GroupAccessEnum(data.access_level) role = RoleEnum(data.admin_role) new_group = Group(title=data.title, about=data.about, access_level=a_level, date_creation=datetime.utcnow(), date=data.date, admin_id=id_from_token) try: db.add(new_group) commit_with_check(db) except: db.rollback() db.refresh(new_group) try: db.add( GroupUser(group_id=new_group.id, user_id=id_from_token, role_in_group=role)) commit_with_check(db) except: db.rollback() return AddGroup(ok=True, message="Group has been added!", ID=new_group.id)
def get_by_task_code(task_code): try: prediction_task_entity = PredictionTaskEntity.query.filter( PredictionTaskEntity.task_code == task_code).one() db_session.refresh(prediction_task_entity) return prediction_task_entity except NoResultFound: return None
def get_for_task_code(task_code): try: detection_result_entity = DetectionResultEntity.query.filter( DetectionResultEntity.task_code == task_code).one() db_session.refresh(detection_result_entity) return detection_result_entity except NoResultFound: return None
def verify_auth_token(token): s = Serializer(SECRET_KEY) try: data = s.loads(token) except SignatureExpired: return None except BadSignature: return None user = db_session.query(UserEntity).get(data['id']) db_session.refresh(user) db_session.commit() return user
def mutate(root, info, data, id_from_token): a_level = AccessLevelEnum(data.access_level) new_list = Wishlist(title=data.title, user_id=id_from_token, about=data.about, access_level=a_level) try: db.add(new_list) commit_with_check(db) except: db.rollback() db.refresh(new_list) lists = db.query(Wishlist).filter_by(user_id=id_from_token) return AddList(ok=True, message="Wishlist added!", user_lists=lists)
def mutate(root, info, user_data): if db.query(User).filter_by(email=user_data.email).first(): return ClassicRegisterUser( ok=False, message="An account is already registered for this mailbox") code = random.randint(100000, 999999) e_host.send_email(user_data.email, "Confirm actions", user_data.user_name, "other/fast_registration.txt", code) new_user = User(email=user_data.email, user_name=user_data.user_name, password_hash=au.get_password_hash(code)) try: db.add(new_user) commit_with_check(db) except: db.rollback() db.refresh(new_user) return ClassicRegisterUser(ok=True, message="Registration done!", ID=new_user.id)
def mutate(root, info, user_data): if db.query(User).filter_by(email=user_data.email).first(): return ClassicRegisterUser( ok=False, message="An account is already registered for this mailbox") if db.query(User).filter_by(nickname=user_data.nickname).first(): return ClassicRegisterUser( ok=False, message="An account is already registered for this nickname") new_user = User(email=user_data.email, password_hash=au.get_password_hash(user_data.password), user_name=user_data.user_name, nickname=user_data.nickname, userpic="users/user_0.png") try: db.add(new_user) commit_with_check(db) except: db.rollback() db.refresh(new_user) return ClassicRegisterUser(ok=True, message="Registration done!", ID=new_user.id)