python学习
This commit is contained in:
@@ -3,74 +3,78 @@ from flask import Blueprint,request,redirect,jsonify
|
||||
from common.libs.Helper import ops_render,iPagination,getCurrentDate
|
||||
from common.libs.UrlManager import UrlManager
|
||||
from common.libs.user.UserService import UserService
|
||||
from common.models.User import User
|
||||
from common.models.log.AppAccessLog import AppAccessLog
|
||||
from sqlalchemy import or_
|
||||
route_account = Blueprint( 'account_page',__name__ )
|
||||
from common.models.User import User
|
||||
from sqlalchemy import or_
|
||||
from application import app,db
|
||||
|
||||
route_account = Blueprint( 'account_page',__name__ )
|
||||
|
||||
@route_account.route( "/index" )
|
||||
def index():
|
||||
resp_data = {}
|
||||
req = request.values
|
||||
page = int(req['p']) if ('p' in req and req['p']) else 1
|
||||
page = int( req['p'] ) if ( 'p' in req and req['p'] ) else 1
|
||||
query = User.query
|
||||
|
||||
if 'mix_kw' in req:
|
||||
rule = or_( User.nickname.ilike( "%{0}%".format( req['mix_kw'] ) ),User.mobile.ilike( "%{0}%".format( req['mix_kw'] ) ))
|
||||
rule = or_( User.nickname.ilike( "%{0}%".format( req['mix_kw'] ) ),User.mobile.ilike( "%{0}%".format( req['mix_kw'] ) ) )
|
||||
query = query.filter( rule )
|
||||
|
||||
if 'status' in req and int( req['status'] ) > -1:
|
||||
query = query.filter( User.status == int( req['status']) )
|
||||
query = query.filter( User.status == int( req['status'] ) )
|
||||
|
||||
page_params = {
|
||||
'total': query.count(),
|
||||
'page_size': app.config['PAGE_SIZE'],
|
||||
'page_size':app.config['PAGE_SIZE'],
|
||||
'page': page,
|
||||
'display': app.config['PAGE_DISPLAY'],
|
||||
'url': request.full_path.replace( "&p={}".format(page),"")
|
||||
'display':app.config['PAGE_DISPLAY'],
|
||||
'url': request.full_path.replace( "&p={}".format(page),"" )
|
||||
}
|
||||
|
||||
pages = iPagination(page_params)
|
||||
offset = (page - 1) * app.config['PAGE_SIZE']
|
||||
pages = iPagination( page_params )
|
||||
offset = ( page - 1 ) * app.config['PAGE_SIZE']
|
||||
limit = app.config['PAGE_SIZE'] * page
|
||||
|
||||
list = query.order_by(User.uid.desc()).all()[offset:limit]
|
||||
list = query.order_by( User.uid.desc() ).all()[ offset:limit ]
|
||||
|
||||
resp_data['list'] = list
|
||||
resp_data['pages'] = pages
|
||||
resp_data['search_con'] = req
|
||||
resp_data['status_mapping'] = app.config['STATUS_MAPPING']
|
||||
return ops_render("account/index.html", resp_data)
|
||||
return ops_render( "account/index.html",resp_data )
|
||||
|
||||
@route_account.route( "/info" )
|
||||
def info():
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
uid = int(req.get('id', 0))
|
||||
uid = int( req.get('id',0 ))
|
||||
reback_url = UrlManager.buildUrl("/account/index")
|
||||
if uid < 1:
|
||||
return redirect(reback_url)
|
||||
return redirect( reback_url )
|
||||
|
||||
info = User.query.filter_by(uid=uid).first()
|
||||
info = User.query.filter_by( uid = uid ).first()
|
||||
if not info:
|
||||
return redirect(reback_url)
|
||||
return redirect( reback_url )
|
||||
|
||||
access_list = AppAccessLog.query.filter_by(uid=uid).order_by(AppAccessLog.id.desc()).limit(10).all()
|
||||
access_list = AppAccessLog.query.filter_by( uid = uid).order_by(AppAccessLog.id.desc() ).limit(10).all()
|
||||
resp_data['info'] = info
|
||||
resp_data['access_list'] = access_list
|
||||
return ops_render( "account/info.html",resp_data )
|
||||
|
||||
return ops_render("account/info.html", resp_data)
|
||||
|
||||
@route_account.route( "/set" ,methods=["GET", "POST"])
|
||||
@route_account.route( "/set",methods = [ "GET","POST" ] )
|
||||
def set():
|
||||
default_pwd = "******"
|
||||
if request.method == "GET":
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
uid = int( req.get( "id",0))
|
||||
uid = int( req.get( "id",0 ) )
|
||||
info = None
|
||||
if uid:
|
||||
if uid :
|
||||
info = User.query.filter_by( uid = uid ).first()
|
||||
resp_data['info'] = info
|
||||
return ops_render( "account/set.html",resp_data)
|
||||
return ops_render( "account/set.html",resp_data )
|
||||
|
||||
resp = { 'code':200,'msg':'操作成功~~','data':{} }
|
||||
req = request.values
|
||||
|
||||
@@ -106,13 +110,13 @@ def set():
|
||||
resp['msg'] = "请输入符合规范的登录密码~~"
|
||||
return jsonify( resp )
|
||||
|
||||
has_in = User.query.filter( User.login_name == login_name,User.uid!= id).first()
|
||||
has_in = User.query.filter( User.login_name == login_name,User.uid != id ).first()
|
||||
if has_in:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "该登录名已存在,请换一个试试~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info = User.query.filter_by(uid=id).first()
|
||||
user_info = User.query.filter_by( uid = id ).first()
|
||||
if user_info:
|
||||
model_user = user_info
|
||||
else:
|
||||
@@ -124,12 +128,15 @@ def set():
|
||||
model_user.mobile = mobile
|
||||
model_user.email = email
|
||||
model_user.login_name = login_name
|
||||
|
||||
if login_pwd != default_pwd:
|
||||
model_user.login_pwd = UserService.genePwd( login_pwd,model_user.login_salt )
|
||||
if user_info and user_info.uid == 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名~~"
|
||||
return jsonify(resp)
|
||||
|
||||
model_user.created_time = getCurrentDate()
|
||||
model_user.login_pwd = UserService.genePwd( login_pwd,model_user.login_salt )
|
||||
|
||||
model_user.updated_time = getCurrentDate()
|
||||
db.session.add( model_user )
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
@@ -162,8 +169,15 @@ def ops():
|
||||
elif act == "recover":
|
||||
user_info.status = 1
|
||||
|
||||
if user_info and user_info.uid == 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "该用户是演示账号,不准操作账号~~"
|
||||
return jsonify(resp)
|
||||
|
||||
user_info.update_time = getCurrentDate()
|
||||
db.session.add(user_info)
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Blueprint,redirect,request,jsonify
|
||||
from common.libs.Helper import ops_render,iPagination,getCurrentDate
|
||||
from flask import Blueprint,request,redirect,jsonify
|
||||
from common.libs.Helper import ops_render,iPagination,getCurrentDate,getDictFilterField,selectFilterObj
|
||||
from common.libs.UrlManager import UrlManager
|
||||
from common.models.member.Member import Member
|
||||
from common.models.member.MemberComments import MemberComments
|
||||
from common.models.food.Food import Food
|
||||
from common.models.pay.PayOrder import PayOrder
|
||||
from application import app,db
|
||||
route_member = Blueprint( 'member_page',__name__ )
|
||||
|
||||
@@ -12,55 +15,61 @@ def index():
|
||||
req = request.values
|
||||
page = int( req['p'] ) if ( 'p' in req and req['p'] ) else 1
|
||||
query = Member.query
|
||||
if 'mix_kw' in req:
|
||||
query = query.filter(Member.nickname.ilike("%{0}%".format(req['mix_kw'])))
|
||||
|
||||
if 'status' in req and int(req['status']) > -1:
|
||||
query = query.filter(Member.status == int(req['status']))
|
||||
if 'mix_kw' in req:
|
||||
query = query.filter( Member.nickname.ilike( "%{0}%".format( req['mix_kw'] ) ) )
|
||||
|
||||
if 'status' in req and int( req['status'] ) > -1 :
|
||||
query = query.filter( Member.status == int( req['status'] ) )
|
||||
|
||||
page_params = {
|
||||
'total': query.count(),
|
||||
'total':query.count(),
|
||||
'page_size': app.config['PAGE_SIZE'],
|
||||
'page': page,
|
||||
'display': app.config['PAGE_DISPLAY'],
|
||||
'url': request.full_path.replace("&p={}".format(page), "")
|
||||
'page':page,
|
||||
'display':app.config['PAGE_DISPLAY'],
|
||||
'url': request.full_path.replace("&p={}".format(page),"")
|
||||
}
|
||||
|
||||
pages = iPagination(page_params)
|
||||
offset = (page - 1) * app.config['PAGE_SIZE']
|
||||
list = query.order_by(Member.id.desc()).offset(offset).limit(app.config['PAGE_SIZE']).all()
|
||||
pages = iPagination( page_params )
|
||||
offset = ( page - 1 ) * app.config['PAGE_SIZE']
|
||||
list = query.order_by( Member.id.desc() ).offset( offset ).limit( app.config['PAGE_SIZE'] ).all()
|
||||
|
||||
resp_data['list'] = list
|
||||
resp_data['pages'] = pages
|
||||
resp_data['search_con'] = req
|
||||
resp_data['status_mapping'] = app.config['STATUS_MAPPING']
|
||||
resp_data['current'] = 'index'
|
||||
return ops_render("member/index.html", resp_data)
|
||||
return ops_render( "member/index.html",resp_data )
|
||||
|
||||
@route_member.route( "/info" )
|
||||
def info():
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
id = int(req.get("id", 0))
|
||||
reback_url = UrlManager.buildUrl("/member/index")
|
||||
id = int( req.get( "id",0 ) )
|
||||
reback_url = UrlManager.buildUrl( "/member/index" )
|
||||
if id < 1:
|
||||
return redirect(reback_url)
|
||||
return redirect( reback_url )
|
||||
|
||||
info = Member.query.filter_by(id=id).first()
|
||||
info = Member.query.filter_by( id =id ).first()
|
||||
if not info:
|
||||
return redirect(reback_url)
|
||||
return redirect( reback_url )
|
||||
|
||||
pay_order_list = PayOrder.query.filter_by( member_id = id ).filter( PayOrder.status.in_( [-8,1] ) )\
|
||||
.order_by( PayOrder.id.desc() ).all()
|
||||
comment_list = MemberComments.query.filter_by( member_id = id ).order_by( MemberComments.id.desc() ).all()
|
||||
|
||||
resp_data['info'] = info
|
||||
|
||||
resp_data['pay_order_list'] = pay_order_list
|
||||
resp_data['comment_list'] = comment_list
|
||||
resp_data['current'] = 'index'
|
||||
return ops_render("member/info.html", resp_data)
|
||||
return ops_render( "member/info.html",resp_data )
|
||||
|
||||
@route_member.route( "/set",methods = [ "GET","POST" ] )
|
||||
def set():
|
||||
if request.method == "GET":
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
id = int(req.get("id", 0))
|
||||
id = int( req.get( "id",0 ) )
|
||||
reback_url = UrlManager.buildUrl("/member/index")
|
||||
if id < 1:
|
||||
return redirect(reback_url)
|
||||
@@ -74,16 +83,16 @@ def set():
|
||||
|
||||
resp_data['info'] = info
|
||||
resp_data['current'] = 'index'
|
||||
return ops_render("member/set.html", resp_data)
|
||||
return ops_render( "member/set.html",resp_data )
|
||||
|
||||
resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
|
||||
resp = { 'code':200,'msg':'操作成功~~','data':{} }
|
||||
req = request.values
|
||||
id = req['id'] if 'id' in req else 0
|
||||
nickname = req['nickname'] if 'nickname' in req else ''
|
||||
if nickname is None or len(nickname) < 1:
|
||||
if nickname is None or len( nickname ) < 1:
|
||||
resp['code'] = -1
|
||||
resp['msg'] = "请输入符合规范的姓名~~"
|
||||
return jsonify(resp)
|
||||
return jsonify( resp )
|
||||
|
||||
member_info = Member.query.filter_by(id=id).first()
|
||||
if not member_info:
|
||||
@@ -93,14 +102,63 @@ def set():
|
||||
|
||||
member_info.nickname = nickname
|
||||
member_info.updated_time = getCurrentDate()
|
||||
db.session.add(member_info)
|
||||
db.session.add( member_info )
|
||||
db.session.commit()
|
||||
return jsonify(resp)
|
||||
return jsonify( resp )
|
||||
|
||||
|
||||
@route_member.route( "/comment" )
|
||||
def comment():
|
||||
return ops_render( "member/comment.html" )
|
||||
resp_data = {}
|
||||
req = request.args
|
||||
page = int(req['p']) if ('p' in req and req['p']) else 1
|
||||
query = MemberComments.query
|
||||
|
||||
page_params = {
|
||||
'total': query.count(),
|
||||
'page_size': app.config['PAGE_SIZE'],
|
||||
'page': page,
|
||||
'display': app.config['PAGE_DISPLAY'],
|
||||
'url': request.full_path.replace("&p={}".format(page), "")
|
||||
}
|
||||
|
||||
pages = iPagination(page_params)
|
||||
offset = (page - 1) * app.config['PAGE_SIZE']
|
||||
|
||||
comment_list = query.order_by(MemberComments.id.desc()).offset( offset ).limit( app.config['PAGE_SIZE'] ).all()
|
||||
data_list = []
|
||||
if comment_list:
|
||||
member_map = getDictFilterField( Member,Member.id,"id", selectFilterObj( comment_list ,"member_id" ) )
|
||||
food_ids = []
|
||||
for item in comment_list:
|
||||
tmp_food_ids = (item.food_ids[1:-1]).split("_")
|
||||
tmp_food_ids = {}.fromkeys( tmp_food_ids ).keys()
|
||||
food_ids = food_ids + list( tmp_food_ids )
|
||||
|
||||
food_map = getDictFilterField( Food,Food.id,"id", food_ids )
|
||||
|
||||
for item in comment_list:
|
||||
tmp_member_info = member_map[ item.member_id ]
|
||||
tmp_foods = []
|
||||
tmp_food_ids = (item.food_ids[1:-1]).split("_")
|
||||
for tmp_food_id in tmp_food_ids:
|
||||
tmp_food_info = food_map[ int( tmp_food_id ) ]
|
||||
tmp_foods.append({
|
||||
'name': tmp_food_info.name,
|
||||
})
|
||||
|
||||
tmp_data = {
|
||||
"content":item.content,
|
||||
"score":item.score,
|
||||
"member_info":tmp_member_info,
|
||||
"foods":tmp_foods
|
||||
}
|
||||
data_list.append( tmp_data )
|
||||
resp_data['list'] = data_list
|
||||
resp_data['pages'] = pages
|
||||
resp_data['current'] = 'comment'
|
||||
|
||||
return ops_render( "member/comment.html",resp_data )
|
||||
|
||||
|
||||
@route_member.route("/ops",methods=["POST"])
|
||||
@@ -135,4 +193,4 @@ def ops():
|
||||
member_info.updated_time = getCurrentDate()
|
||||
db.session.add(member_info)
|
||||
db.session.commit()
|
||||
return jsonify( resp )
|
||||
return jsonify( resp )
|
||||
|
||||
Reference in New Issue
Block a user