def db_delete(): isLogin = login_check() if isLogin: if request.method == 'GET': return render_template('admin/sthwrong.html') elif request.method == 'POST': if session['level'] > 0: # 레벨 1부터 가능 if request.form.get('confirm') == 'True': logs_model = Logs('logs') try: db_data = logs_model.delete_all_excepting_a_week() if db_data['success']: return '<script>alert("성공적으로 삭제했습니다.");\n location.href="./backup";</script>' else: return render_template('admin/sthwrong.html') except Exception as e: return '<script>alert("오류가 발생했습니다.\n ' + str( e) + '");\n location.href="./backup";</script>' else: return '<script>alert("확인란에 체크하셔야 작업을 수행할 수 있습니다.");\n history.go(-1);</script>' else: return '<script>alert("권한이 없습니다.");\n history.go(-1);</script>' else: return redirect(url_for('admin.login'))
def patch(self, log_id): current_user = get_jwt_identity() parser = reqparse.RequestParser() parser.add_argument('cnt', type=str, location='json') parser.add_argument('time', type=str, location='json') parser.add_argument('inner_opened', type=int, location='json') parser.add_argument('inner_new', type=int, location='json') parser.add_argument('outer_opened', type=int, location='json') parser.add_argument('outer_new', type=int, location='json') parser.add_argument('comment', type=str, location='json') args = parser.parse_args() cnt, time, inner_opened, inner_new, outer_opened, outer_new, comment = args.values( ) if time is not None: time_parsed = datetime.strptime(time + " +0900", '%Y-%m-%d %H:%M %z') else: time_parsed = None logs_model = Logs('logs', id=log_id, cnt=cnt, time=time_parsed, inner_opened=inner_opened, inner_new=inner_new, outer_opened=outer_opened, outer_new=outer_new, comment=comment, modified_by=current_user) return logs_model.update()
def general_history(): isLogin = login_check() if isLogin: page = int(request.args.get('page', '1')) logs_model = Logs('logs') try: db_data = logs_model.read_recent_data_page((int(page) - 1) * 10, 10) if db_data['success']: result = db_data['result'] msg = '' else: result = '' msg = db_data[0]['msg'] except Exception as e: result = '' msg = str(e) return render_template('admin/general/history.html', isLogin=True, username=session['username'], realname=session['realname'], description=session['description'], level=session['level'], result=result, msg=msg, page=page) else: return redirect(url_for('admin.login'))
def dubug_init_db(): isLogin = login_check() if isLogin: if session['level'] > 2: # 레벨 3부터 가능 () logs_model = Logs('logs') try: db_data = logs_model.delete_all() if db_data['success']: return '<script>alert("성공적으로 삭제했습니다.");\n location.href="/debug";</script>' else: return render_template('admin/sthwrong.html') except Exception as e: return '<script>alert("오류가 발생했습니다.\n ' + str( e) + '");\n location.href="/debug";</script>' else: return '<script>alert("권한이 없습니다.");\n history.go(-1);</script>'
def post(self): current_user = get_jwt_identity() parser = reqparse.RequestParser() parser.add_argument('cnt', type=str, required=True, location='json') parser.add_argument('time', type=str, required=True, location='json') parser.add_argument('inner_opened', type=int, required=True, location='json') parser.add_argument('inner_new', type=int, required=True, location='json') parser.add_argument('outer_opened', type=int, required=True, location='json') parser.add_argument('outer_new', type=int, required=True, location='json') parser.add_argument('comment', type=str, required=True, location='json') args = parser.parse_args() cnt, time, inner_opened, inner_new, outer_opened, outer_new, comment = args.values( ) time_parsed = datetime.strptime(time + " +0900", '%Y-%m-%d %H:%M %z') logs_model = Logs('logs', cnt=cnt, time=time_parsed, inner_opened=inner_opened, inner_new=inner_new, outer_opened=outer_opened, outer_new=outer_new, comment=comment, created_by=current_user, modified_by='') return logs_model.create()
def get(self, cnt_id): parser = reqparse.RequestParser() parser.add_argument('page', type=int, location='args') parser.add_argument('size', type=int, location='args') parser.add_argument('start', type=str, location='args') parser.add_argument('end', type=str, location='args') parser.add_argument('oneperday', type=bool, location='args') args = parser.parse_args() page, size, start, end, oneperday = args.values() if start is not None: start_parsed = datetime.strptime(start + " +0900", '%Y-%m-%d %H:%M %z') else: start_parsed = None if end is not None: end_parsed = datetime.strptime(end + " +0900", '%Y-%m-%d %H:%M %z') else: end_parsed = None logs_model = Logs('logs') if page is not None: # 페이지네이션 if size is None: # size가 넘어오지 않았으면 10으로 지정함 size = 10 if start_parsed is not None and end_parsed is not None: # 기간 조회 if oneperday: return { 'success': False, 'msg': 'The system cannot do pagination when turned on "oneperday" option.' }, 500 else: return logs_model.read_page_where_cnt_period( cnt_id, page * size, size, start_parsed, end_parsed) else: return logs_model.read_page_where_cnt(cnt_id, page * size, size) else: # 전체 조회 (page is None) if start_parsed is not None and end_parsed is not None: # 기간 조회 if oneperday: return logs_model.read_all_where_cnt_period_one_per_day( cnt_id, start_parsed, end_parsed) else: return logs_model.read_all_where_cnt_period( cnt_id, start_parsed, end_parsed) else: return logs_model.read_all_where_cnt(cnt_id)
def db_backup(): isLogin = login_check() if isLogin: if request.method == 'GET': return render_template('admin/db/backup.html', isLogin=True, username=session['username'], realname=session['realname'], description=session['description'], level=session['level']) elif request.method == 'POST': if session['level'] > 0: # 레벨 1부터 가능 if request.form.get('confirm') == 'True': logs_model = Logs('logs') try: db_data = logs_model.read_all() if db_data['success']: today = time.strftime('%Y-%m-%d', time.localtime(time.time())) response = make_response(jsonify( db_data['result'])) response.headers[ 'Content-Disposition'] = f'attachment; filename="{today}-diapers.json"' return response else: return render_template('admin/sthwrong.html') except Exception as e: return '<script>alert("오류가 발생했습니다.\n ' + str( e) + '");\n location.href="./edit";</script>' else: return '<script>alert("확인란에 체크하셔야 작업을 수행할 수 있습니다.");\n history.go(-1);</script>' else: return '<script>alert("권한이 없습니다.");\n history.go(-1);</script>' else: return redirect(url_for('admin.login'))
def get(self, log_id): logs_model = Logs('logs', id=log_id) return logs_model.read_one()
def delete(self, log_id): logs_model = Logs('logs', id=log_id) return logs_model.delete()