def before_request(): # 当用户未登录时,在列表中的请求将被重定向到登录界面 filter_list = [ "/", "/commodity/add", "/commodity/del", "/commodity/buy", "/commodity/send", "/commodity/trans", "/commodity/warehouse", "/commodity/distribution", "/commodity/sale" ] app.logger.info("--------before_request:%s--------" % (request.path)) user_info = check_login() g.current_user = None app.logger.info("user_info:%s" % user_info) if user_info: g.current_user = user_info app.logger.info("current_user:%s" % g.current_user) if g.current_user is None: # 用户未登录 app.logger.info("current_user is null,进行重定向") if request.path in filter_list: # 拦截普通请求 response = make_response( redirect(UrlManager.build_url("/member/login"))) response.delete_cookie(app.config["AUTH_COOKIE_NAME"]) return response return
def info(): resp_data = {} req = request.args id = int(req.get("id", 0)) reback_url = UrlManager.buildUrl("/books_lib/index") if id < 1: return redirect(reback_url) book_info = Books.query.filter_by(id=id).first() if not book_info: return redirect(reback_url) # 转换book_type books_type = app.config['BOOK_TYPES'] type_int = book_info.book_type type = str(type_int) type_str = books_type[type] book_info.book_type = type_str resp_data['book_info'] = book_info # resp_data['news_info'] = news_info return ops_render("books_lib/info.html",resp_data)
def new_set(): if request.method == "GET": resp_data = {} req = request.args id = int( req.get('id',0) ) info = Books.query.filter_by( id = id ).first() if info and info.status != 1: return redirect( UrlManager.buildUrl("/books_lib/index") ) resp_data['info'] = info resp_data['lib_location'] = app.config['LIB_LOCATION'] resp_data['book_types'] = app.config['BOOK_TYPES'] return ops_render("books_lib/new_set.html", resp_data) resp = {'code': 200, 'msg': '操作成功~~', 'data': {}} req = request.values id = int(req['id']) if 'id' in req and req['id'] else 0 cat_id = int(req['cat_id']) if 'cat_id' in req and req['cat_id'] else 0 title = req['title'] if 'title' in req else '' author = req['author'] if 'author' in req else '' press = req['press'] if 'press' in req else '' intro = req['intro'] if 'intro' in req else '' location = req['location'] if 'location' in req else '' amount = int(req['amount']) if 'amount' in req and req['amount'] else 0 image = req['image'] if 'image' in req else '' if image is None or len(image) < 3: resp['code'] = -1 resp['msg'] = "请上传封面图~~" return jsonify(resp) book_info = Books.query.filter_by(id=id).first() if book_info: model_info = book_info model_info.current_amount = amount # 现在的数量,只有修改已有书籍的时候的才能修改 else: #这里铁定的是第一次上新才能修改 model_info = Books() model_info.status = 1 model_info.current_amount = amount #第一次上新在馆数量和上新数量是一样的 model_info.update_amount = amount #上新数量,只能 第一次 上新书才能更改,不允许出错,因为涉及到新书推荐的地方 model_info.update_time = getCurrentDate() #上新时间,只能第一次上新才能更改 # 这6个均可修改的原因是有可能第一次上新的时候输错了书籍信息 model_info.book_type = cat_id model_info.title = title model_info.author = author model_info.image = image model_info.press = press model_info.intro = intro model_info.location = location db.session.add(model_info) db.session.commit() return jsonify(resp)
def info(): resp_data ={} req = request.args uid = int(req.get('id',0)) reback_url = UrlManager.buildUrl("/account/index") if uid < 1: return redirect(reback_url) info = User.query.filter_by(uid=uid).first() if not info : return redirect(reback_url) resp_data['info'] = info return ops_render("account/info.html",resp_data)
def info(): req = request.values id = int(req['id']) if ('id' in req and req['id']) else 0 if id < 1: return redirect(UrlManager.buildUrl("/")) info = Movie.query.filter_by(id=id).first() if not info: return redirect(UrlManager.buildUrl("/")) ''' 更新阅读数量 ''' info.view_counter += 1 db.session.add(info) db.session.commit() ''' 获取推荐 ''' recommend_list = Movie.query.order_by(func.rand()).limit(4) return ops_render("info.html", {"info": info, "recommend_list": recommend_list})
def info(): resp_data = {} req = request.args id = int(req.get("id", 0)) reback_url = UrlManager.buildUrl("/member/index") if id < 1: return redirect(reback_url) lending_info = Lending.query.filter_by(id=id).first() if not lending_info: return redirect(reback_url) resp_data['lending_info'] = lending_info return ops_render("member/info.html", resp_data)
def uploadImage(): resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''} file_target = request.files upfile = file_target['upfile'] if 'upfile' in file_target else None if upfile is None: resp['state'] = "上传失败" return jsonify(resp) ret = UploadService.uploadByFile(upfile) if ret['code'] != 200: #根据UploadService.uploadByFile方法里面返回的code值进行判断,如果不是200就说明这个文件类型不合格 resp['state'] = "上传失败:" + ret['msg'] return jsonify(resp) #如果没有出现失败的情况,就说明 成功了,然后点返回一个图片上传存放的地址回去 resp['url'] = UrlManager.buildImageUrl( ret['data']['file_key']) #这里在UrlManager.buildImageUrl进行了图片展示地址的拼接 return jsonify(resp)
def info(): if request.method=='GET': resp_data = {} req = request.args id = int(req.get("id", 0)) reback_url = UrlManager.buildUrl("/feedback/feedback") if id < 1: return redirect(reback_url) feed_info = Feedback.query.filter_by(id=id).first() if not feed_info: return redirect(reback_url) resp_data['feed_info'] = feed_info # resp_data['news_info'] = news_info return ops_render("feedback/feed_info.html",resp_data) resp = {'code': 200, 'msg': '操作成功~~', 'data': {}} req = request.values id = int(req['id']) if 'id' in req and req['id'] else 0 feedback_lib = req['feedback'] if 'feedback' in req else '' app.logger.info(feedback_lib) if id ==0: resp['code'] = -1 resp['msg'] = "数据的id获取失败~~" return jsonify(resp) if feedback_lib is None or len(feedback_lib) < 2: resp['code'] = -1 resp['msg'] = "请填写规范的回复~~" return jsonify(resp) model_info = Feedback.query.filter_by(id=id).first() model_info.feedback_lib = feedback_lib db.session.add(model_info) db.session.commit() return jsonify(resp)
def set(): if request.method == "GET": resp_data = {} req = request.args id = req['id'] if 'id' in req else '' reback_url = UrlManager.buildUrl("/") info = News.query.filter_by(id=id).first() if not info: return redirect(reback_url) # news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all() resp_data['info'] = info resp_data['lib_location'] = app.config['LIB_LOCATION'] return ops_render("index/set.html", resp_data) resp = {'code': 200, 'msg': '操作成功', 'data': {}} req = request.values id = int(req['id']) if 'id' in req else 0 title = req['title'] if 'title' in req else '' location = req['location'] if 'location' in req else '' content = req['content'] if 'content' in req else '' # 参数有效性的再次判断的 之前判断了title字数不能小于2,地点名不能少于5个字和content不能为空,这里就暂时鸡肋地随便判断下 if title is None or len(title) > 20: resp['code'] = -1 resp['msg'] = "请输入规范的标题名~~" return jsonify(resp) if location is None or len(location) > 15: resp['code'] = -1 resp['msg'] = "请输入规范的校区图书馆名~~" return jsonify(resp) bulletin_info = News.query.filter_by(id=id).first() bulletin_info.title = title bulletin_info.content = content bulletin_info.location = location bulletin_info.created_time = getCurrentDate() # 数据库提交 db.session.add(bulletin_info) db.session.commit() return jsonify(resp)
def lost_info(): resp_data = {} req = request.args id = int(req.get("id", 0)) reback_url = UrlManager.buildUrl("/lost") if id < 1: return redirect(reback_url) info = Lost.query.filter_by(id=id).first() if not info: return redirect(reback_url) # news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all() resp_data['info'] = info #resp_data['news_info'] = news_info return ops_render("index/lost_info.html", resp_data)
def before_request(): ignore_urls = app.config['IGNORE_URLS'] ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS'] path = request.path pattern = re.compile('%s' % "|".join(ignore_check_login_urls)) if pattern.match(path): return user_info = check_login() g.current_user = None if user_info: g.current_user = user_info pattern = re.compile('%s' % "|".join(ignore_urls)) if pattern.match(path): return if not user_info: return redirect(UrlManager.buildUrl("/user/login")) return
def speech_info(): resp_data = {} req = request.args id = int(req.get("id", 0)) reback_url = UrlManager.buildUrl("/dong_tai/speeches") if id < 1: return redirect(reback_url) speeches_info = Speeches.query.filter_by(id=id).first() if not speeches_info: return redirect(reback_url) # news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all() title = speeches_info.title amount = SpeechReservation.query.filter( SpeechReservation.title == title).count() speeches_info.amount = amount resp_data['speeches_info'] = speeches_info # resp_data['news_info'] = news_info return ops_render("dong_tai/speech_info.html", resp_data)
def listImage(): #从数据库里面取数据进行 展示,服务于在线管理那个里面,里面的start和id的结合是为了进行图片页面分类 resp = {'state': 'SUCCESS', 'list': [], 'start': 0, 'total': 0} req = request.values start = int(req['start']) if 'start' in req else 0 page_size = int(req['size']) if 'size' in req else 20 query = Image.query if start > 0: query = query.filter(Image.id < start) list = query.order_by(Image.id.desc()).limit(page_size).all() images = [] if list: for item in list: #取出数据,是将数据库中的地址挨个放进一个列表里面 images.append({'url': UrlManager.buildImageUrl(item.file_key)}) start = item.id resp['list'] = images resp['start'] = start resp['total'] = len(images) return jsonify(resp)
def logOut(): response = make_response(redirect(UrlManager.buildUrl("/"))) response.delete_cookie(app.config['AUTH_COOKIE_NAME']) return response
def logout(): response = make_response(redirect(UrlManager.build_url("/member/login"))) response.delete_cookie(app.config["AUTH_COOKIE_NAME"]) return response
def speech_edit(): if request.method == "GET": resp_data = {} req = request.args id = req['id'] if 'id' in req else '' reback_url = UrlManager.buildUrl("/dong_tai/speeches") speech_info = Speeches.query.filter_by(id=id).first() if not speech_info: return redirect(reback_url) # news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all() resp_data['info'] = speech_info return ops_render("dong_tai/speech_edit.html", resp_data) resp = {'code': 200, 'msg': '操作成功', 'data': {}} req = request.values sid = int(req['id']) if 'id' in req else 0 title = req['title'] if 'title' in req else '' address = req['address'] if 'address' in req else '' teacher = req['teacher'] if 'teacher' in req else '' email = req['email'] if 'email' in req else '' teacher_intro = req['teacher_intro'] if 'teacher_intro' in req else '' speech_intro = req['speech_intro'] if 'speech_intro' in req else '' time = req['time'] if 'time' in req else getCurrentDate() app.logger.info(time) #注意: #input datetime-local控件获取的日期格式是****-**-**T**:**:**,中间有个很奇怪的T,下面的这个函数已经的证明可以将其赋给数据库 def deleteT(time): time1 = time[:10] time2 = time[11:] time = time1 + ' ' + time2 + ':00' return time time = deleteT(time) app.logger.info(time) # 假吧意思判断两个,重点是判断时间到底对没对 if title is None or len(title) > 20: resp['code'] = -1 resp['msg'] = "请输入规范的标题名~~" return jsonify(resp) if address is None: resp['code'] = -1 resp['msg'] = "请输入规范的讲座地址~~" return jsonify(resp) speech_info = Speeches.query.filter_by(id=sid).first() speech_info.title = title speech_info.address = address speech_info.teacher = teacher speech_info.teacher_conn = email speech_info.speech_time = time speech_info.teacher_intro = teacher_intro speech_info.speech_intro = speech_intro # 数据库提交 db.session.add(speech_info) db.session.commit() return jsonify(resp)