Esempio n. 1
0
def _get_code_list(code_text):
    l = []
    try:
        code = Code.get(text=code_text)
        code_log = code.clean_up_if_expired()  # new CodeLog instance if code is expired
        l.append(code if code_log is None else code_log)
    except Code.DoesNotExist:
        pass
    l.extend(list(CodeLog.select().where(CodeLog.text == code_text).order_by(CodeLog.id.desc())))
    return l
Esempio n. 2
0
def _try_redeem_code(code_text, redeem_info, user_id):
    # return None if failed, else return CodeLog instance
    try:
        code = Code.get(text=code_text)
    except Code.DoesNotExist:
        return

    if code.is_redeemable():
        return code.redeem(redeem_info, user_id)  # return CodeLog
    else:
        code.clean_up_if_expired()
        return