def _create_recommendation(user, offer, mediation=None): recommendation = Recommendation() recommendation.user = user if offer: recommendation.offer = offer else: offer = offer_queries.find_offer_by_id(mediation.offerId) recommendation.offer = offer if mediation: recommendation.mediation = mediation else: mediation = Mediation.query \ .filter(Mediation.offer == offer) \ .filter(Mediation.isActive) \ .order_by(func.random()) \ .first() recommendation.mediation = mediation if recommendation.mediation: recommendation.validUntilDate = datetime.utcnow() + timedelta(days=3) else: recommendation.validUntilDate = datetime.utcnow() + timedelta(days=1) if offer.lastStock and offer.lastStock.bookingLimitDatetime: recommendation.validUntilDate = min( recommendation.validUntilDate, offer.lastStock.bookingLimitDatetime - timedelta(minutes=1)) PcObject.save(recommendation) return recommendation
def create_recommendation(offer=None, user=None, mediation=None, idx=None, date_read=None, valid_until_date=datetime.utcnow() + timedelta(days=7), search=None, is_clicked=False): recommendation = Recommendation() recommendation.id = idx recommendation.offer = offer recommendation.user = user recommendation.mediation = mediation recommendation.dateRead = date_read recommendation.validUntilDate = valid_until_date recommendation.search = search recommendation.isClicked = is_clicked return recommendation
def create_tuto_mediation_if_non_existent_for_user(user, tuto_mediation): already_existing_tuto_recommendation = Recommendation.query\ .filter_by(mediation=tuto_mediation, user=user)\ .first() if already_existing_tuto_recommendation: return recommendation = Recommendation() recommendation.user = user recommendation.mediation = tuto_mediation recommendation.validUntilDate = datetime.utcnow() + timedelta(weeks=2) PcObject.save(recommendation)