Exemplo n.º 1
0
def delete_loyalty_lottery_info(key):
    ll_info_delete = SolutionLoyaltyLottery.get(key)
    if not ll_info_delete:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    sln_settings = get_solution_settings(service_user)

    try:
        ll_info = SolutionLoyaltyLottery.load_pending(service_user, service_identity)
        if ll_info_delete.key() == ll_info.key():
            raise RETURNSTATUS_TO_SUCCESS
        if ll_info_delete.schedule_loot_time > 0:
            ll_info_delete.delete()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)
        broadcast_updates_pending(sln_settings)

        send_message(service_user, u"solutions.common.loyalty.lottery.update", service_identity=service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Exemplo n.º 2
0
def edit_loyalty_lottery_info(key, winnings, date):
    ll_info_edit = SolutionLoyaltyLottery.get(key)
    if not ll_info_edit:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    sln_settings = get_solution_settings(service_user)

    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionLoyaltyLottery.load_pending(service_user, service_identity)
        if ll_info_edit.key() != ll_info.key() and end_timestamp <= ll_info.end_timestamp:
            raise BusinessException("lottery-time-bigger-first-upcoming")

        ll_info_edit.end_timestamp = end_timestamp
        ll_info_edit.schedule_loot_time = ll_info_edit.end_timestamp - 24 * 3600
        ll_info_edit.winnings = winnings
        ll_info_edit.put()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)
        broadcast_updates_pending(sln_settings)

        send_message(service_user, u"solutions.common.loyalty.lottery.update", service_identity=service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Exemplo n.º 3
0
def close_loyalty_lottery_info(key):
    service_user = users.get_current_user()
    try:
        ll_info = SolutionLoyaltyLottery.get(key)
        if ll_info and ll_info.redeemed and not ll_info.deleted:
            ll_info.deleted = True
            ll_info.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update",
                     service_identity=ll_info.service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
Exemplo n.º 4
0
def _qry():
    return SolutionLoyaltyLottery.all(keys_only=True).filter(
        "schedule_loot_time <", now()).filter("schedule_loot_time >", 0)
Exemplo n.º 5
0
def load_loyalty_lottery_info():
    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    return [LoyaltyLotteryInfoTO.fromModel(ll_info) for ll_info in SolutionLoyaltyLottery.load_all(service_user, service_identity)]
Exemplo n.º 6
0
def add_loyalty_lottery_info(winnings, date):
    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    sln_settings = get_solution_settings(service_user)
    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionLoyaltyLottery.load_pending(service_user, service_identity)
        if ll_info:
            if end_timestamp <= ll_info.end_timestamp:
                raise BusinessException("lottery-time-bigger-first-upcoming")

        service_identity_user = create_service_identity_user_wo_default(service_user, service_identity)
        ll_info = SolutionLoyaltyLottery(parent=parent_key_unsafe(service_identity_user, SOLUTION_COMMON))
        ll_info.timestamp = now_
        ll_info.end_timestamp = end_timestamp
        ll_info.schedule_loot_time = ll_info.end_timestamp - 24 * 3600
        ll_info.winnings = winnings
        ll_info.winner = None
        ll_info.winner_info = None
        ll_info.winner_timestamp = 0
        ll_info.skip_winners = []
        ll_info.pending = True
        ll_info.redeemed = False
        ll_info.claimed = False
        ll_info.put()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)
        broadcast_updates_pending(sln_settings)

        send_message(service_user, u"solutions.common.loyalty.lottery.update", service_identity=service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
def _qry():
    return SolutionLoyaltyLottery.all(keys_only=True)
Exemplo n.º 8
0
def put_all_lottery():
    lottery = SolutionLoyaltyLottery.all()
    to_put = list()
    for l in lottery:
        to_put.append(l)
    db.put(to_put)