Пример #1
0
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
Пример #2
0
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