def reflectReq(): adminInfo = admin.query.filter_by(username='******').first() wakeupEventInfo = wakeupEvent.query.filter_by(id=1).first() if not adminInfo or not wakeupEventInfo: db.session.close() return redirect('/init') _event = request.args.get('event') if _event: if _event == 'wakeup': try: _id = int(request.args.get('id')) except Exception, e: db.session.close() return abort(404) userInfo = user.query.filter_by(id=_id).first() if not userInfo: userInfo = user(_id, '') db.session.add(userInfo) db.session.commit() _date = time.strftime("%Y-%m-%d", time.localtime()) _time = time.strftime('%H:%M',time.localtime()) # Return transed off_ret if switch is off if not wakeupEventInfo.switch: _ret = str_misc.trans_str(wakeupEventInfo.off_ret, _time) db.session.close() return _ret wakeupRecInfo = wakeupRec.query.filter_by(user_id=_id, create_date=_date).first() if not wakeupRecInfo: # Return early_ret if user hasn't checked and time is earlier than the begin time if time_misc.check_double_time(_time, wakeupEventInfo.begin_time): _ret = str_misc.trans_str(wakeupEventInfo.early_ret, _time) db.session.close() return _ret # Return late_ret if user hasn't checked and time is later than the begin time if time_misc.check_double_time(wakeupEventInfo.end_time, _time): _ret = str_misc.trans_str(wakeupEventInfo.late_ret, _time) db.session.close() return _ret # Return acc_ret if all thing is right db.engine.execute('UPDATE wakeup_event SET last_total = total, last_update_time = %s WHERE last_update_time != %s', (_date, _date)) db.engine.execute('UPDATE wakeup_event SET total = total + 1') wakeupRecInfo = wakeupRec(_id, _date, _time) db.session.add(wakeupRecInfo) db.session.commit() wakeupRecInfo = wakeupRec.query.filter_by(user_id=_id, create_date=_date).first() _rank = wakeupRecInfo._id - wakeupEvent.query.filter_by(id=1).first().last_total wakeupRecInfo.rank = _rank db.session.commit() _ret = str_misc.trans_str(wakeupEventInfo.acc_ret, _time, _time, str(_rank)) db.session.close() return _ret else: # Return done_ret if user has checked in wakeupEvent _ret = str_misc.trans_str(wakeupEventInfo.done_ret, _time, wakeupRecInfo.create_time, str(wakeupRecInfo.rank)) db.session.close() return _ret if _event == 'normal': try: event_id = int(request.args.get('event_id')) except Exception, e: db.session.close() return abort(404) try: _id = int(request.args.get('id')) except Exception, e: db.session.close() return abort(404)
db.session.close() return abort(404) normalEventInfo = normalEvent.query.filter_by(id=event_id).first() userInfo = user.query.filter_by(id=_id).first() if not userInfo: userInfo = user(_id, '') db.session.add(userInfo) db.session.commit() if not normalEventInfo: db.session.close() return abort(404) _time = time.strftime('%H:%M',time.localtime()) normalRecInfo = normalRec.query.filter_by(user_id=_id, event_id=event_id).first() if normalRecInfo: _ret = str_misc.trans_str(normalEventInfo.done_ret, _time, normalRecInfo.create_time.strftime('%H:%M'), str(normalRecInfo.rank)) db.session.close() return _ret now_datetime = datetime.datetime.now() if now_datetime < normalEventInfo.begin_time: _ret = str_misc.trans_str(normalEventInfo.early_ret, _time) db.session.close() return _ret if now_datetime > normalEventInfo.end_time: _ret = str_misc.trans_str(normalEventInfo.early_ret, _time) db.session.close() return _ret db.engine.execute('UPDATE normal_event SET total = total + 1 WHERE id = %s', (event_id)) normalEventRulesInfoList = normalEventRules.query.order_by(normalEventRules.id).all()