Пример #1
0
def Create(cond):
    createClients = Timelines(**cond, create_time=datetime.now())
    
    try:
        db_session.add(createClients)
        db_session.commit()
        return 200
    except InvalidRequestError:
        log().error("Unable to create data")
        return 400
    except IntegrityError:
        log().error("Foreign key not found")
        return 400
Пример #2
0
def Create(cond):
    querydict = {}
    querydict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400

    createRocket = Rockets(**querydict)

    try:
        db_session.add(createRocket)
        db_session.commit()
        return 200
    except InvalidRequestError:
        log().error("Unable to create data")
        return 400
    except IntegrityError:
        log().error("Foreign key not found")
        return 400
Пример #3
0
def Create(cond):
    passwd = encrypt_password(cond['passwd'])
    cond.pop('passwd')
    queryDict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400
    createClients = Clients(**queryDict, passwd=passwd)

    try:
        db_session.add(createClients)
        db_session.commit()
        return 200
    except InvalidRequestError:
        log().error("Unable to create data")
        return 400
    except IntegrityError:
        log().error("Foreign key not found")
        return 400
Пример #4
0
def Patch(content):
    try:
        if 'id' not in content:
            return None, 400
        cid = content.pop('id')
        querydict, isMatch = checkDictKeyMatchArray(modelKey, content)
        if not isMatch:
            return None, 400
        query = Missions.query.filter_by(id=cid).one_or_none()
        if query is not None:
            if "pair_order" in querydict:
                pair = list(map(int, querydict["pair_order"].split(',')))
                relate = MissionClientOrderRelate.query.filter_by(
                    mission_id=query.id).all()
                qPair = []
                for data in relate:
                    qPair.append(data.clientOrder_id)

                for toDel in list(set(qPair) - set(pair)):
                    m = MissionClientOrderRelate.query.filter_by(
                        mission_id=query.id, clientOrder_id=toDel).one()
                    db_session.delete(m)

                for toAdd in list(set(pair) - set(qPair)):
                    createRelate = MissionClientOrderRelate(
                        mission_id=query.id, clientOrder_id=toAdd)
                    db_session.add(createRelate)

                try:
                    db_session.commit()
                except:
                    log().error("Unable to patch mission client order relate ")
                    return 400

            for key in querydict:
                setattr(query, key, querydict[key])

            db_session.commit()
            return querydict, 200
        else:
            return None, 404
    except InvalidRequestError:
        log().error("Unable to patch data")
        return None, 400
Пример #5
0
def Create(cond):
    log().debug(cond)
    querydict = {}
    querydict, isMatch = checkDictKeyMatchArray(modelKey, cond)
    if not isMatch:
        return None, 400

    if "pair_order" in querydict:
        pair = querydict.pop('pair_order')
        pair = list(map(int, pair.split(',')))
        createMission = Missions(**querydict)
        try:
            db_session.add(createMission)
            db_session.commit()
        except:
            log().error("Unable to add mission")
            return 400
        for values in pair:
            createRelation = MissionClientOrderRelate(
                mission_id=createMission.id, clientOrder_id=values)
            try:
                db_session.add(createRelation)
                db_session.commit()
            except:
                log().error(
                    "Unable to add mission clientOrder relation with id: " +
                    str(values))
                return 400

        return 200

    else:
        createMission = Missions(**querydict)
        try:
            db_session.add(createMission)
            db_session.commit()
            return 200
        except InvalidRequestError:
            log().error("Unable to create mission data")
            return 400
        except IntegrityError:
            log().error("Foreign key not found")
            return 400