Exemplo n.º 1
0
def set_predictions(user, predictions):
    for prediction in predictions:
        try:
            db_prediction = Prediction.query.filter_by(
                user_id=user.id,
                matchday=prediction["matchday"],
                home_team=prediction["home_team"],
                away_team=prediction["away_team"]
            ).first()

            if db_prediction is None:
                db_prediction = Prediction(
                    matchday=prediction["matchday"],
                    home_team=prediction["home_team"],
                    home_score=prediction["home_score"],
                    away_team=prediction["away_team"],
                    away_score=prediction["away_score"]
                )
                db.session.add(db_prediction)
                user.predictions.append(db_prediction)
            else:
                db_prediction.home_score = prediction["home_score"]
                db_prediction.away_score = prediction["away_score"]
        except:
            db.session.rollback()
            raise
    db.session.commit()
    return True
Exemplo n.º 2
0
def set_predictions(user, predictions):
    for prediction in predictions:
        try:
            db_prediction = Prediction.query.filter_by(
                user_id=user.id,
                matchday=prediction["matchday"],
                home_team=prediction["home_team"],
                away_team=prediction["away_team"]).first()

            if db_prediction is None:
                db_prediction = Prediction(matchday=prediction["matchday"],
                                           home_team=prediction["home_team"],
                                           home_score=prediction["home_score"],
                                           away_team=prediction["away_team"],
                                           away_score=prediction["away_score"])
                db.session.add(db_prediction)
                user.predictions.append(db_prediction)
            else:
                db_prediction.home_score = prediction["home_score"]
                db_prediction.away_score = prediction["away_score"]
        except:
            db.session.rollback()
            raise
    db.session.commit()
    return True
Exemplo n.º 3
0
    def add_predictions(self, user, predictions):
        for prediction in predictions:
            try:
                db_prediction = Prediction.query.filter_by(
                    user_id=user.id,
                    matchday=prediction['matchday'],
                    home_team=prediction['home_team'],
                    away_team=prediction['away_team']).first()

                if db_prediction is None:
                    db_prediction = Prediction(
                        matchday=prediction['matchday'],
                        home_team=prediction['home_team'],
                        home_score=prediction['home_score'],
                        away_team=prediction['away_team'],
                        away_score=prediction['away_score'])
                    db.session.add(db_prediction)
                    user.predictions.append(db_prediction)
                else:
                    db_prediction.home_score = prediction['home_score']
                    db_prediction.away_score = prediction['away_score']
            except Exception:
                db.session.rollback()
                raise
        db.session.commit()
        return True