python学习

This commit is contained in:
2019-08-01 11:03:41 +08:00
parent 165f4f3ecb
commit 1548060c7f
6 changed files with 366 additions and 199 deletions

View File

@@ -1,15 +1,59 @@
# -*- coding: utf-8 -*-
from flask import Blueprint
from common.libs.Helper import ops_render
from flask import Blueprint,redirect,request
from common.libs.Helper import ops_render,iPagination
from common.libs.UrlManager import UrlManager
from common.models.member.Member import Member
from application import app,db
route_member = Blueprint( 'member_page',__name__ )
@route_member.route( "/index" )
def index():
return ops_render( "member/index.html" )
resp_data = {}
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']))
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']
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)
@route_member.route( "/info" )
def info():
return ops_render( "member/info.html" )
resp_data = {}
req = request.args
id = int(req.get("id", 0))
reback_url = UrlManager.buildUrl("/member/index")
if id < 1:
return redirect(reback_url)
info = Member.query.filter_by(id=id).first()
if not info:
return redirect(reback_url)
resp_data['info'] = info
resp_data['current'] = 'index'
return ops_render("member/info.html", resp_data)
@route_member.route( "/set" )
def set():

View File

@@ -0,0 +1,51 @@
;
var member_index_ops = {
init:function(){
this.eventBind();
},
eventBind:function(){
var that = this;
$(".wrap_search .search").click(function(){
$(".wrap_search").submit();
});
$(".remove").click( function(){
that.ops( "remove",$(this).attr("data") );
} );
$(".recover").click( function(){
that.ops( "recover",$(this).attr("data") );
} );
},
ops:function( act,id ){
var callback = {
'ok':function(){
$.ajax({
url:common_ops.buildUrl( "/account/ops" ),
type:'POST',
data:{
act:act,
id:id
},
dataType:'json',
success:function( res ){
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = window.location.href;
}
}
common_ops.alert( res.msg,callback );
}
});
},
'cancel':null
};
common_ops.confirm( ( act == "remove" ? "确定删除?":"确定恢复?" ), callback );
}
};
$(document).ready( function(){
member_index_ops.init();
} );

View File

@@ -21,13 +21,15 @@
<div class="form-group">
<select name="status" class="form-control inline">
<option value="-1">请选择状态</option>
<option value="1">正常</option>
<option value="0">已删除</option>
{% for tmp_key in status_mapping %}
<option value="{{ tmp_key }}"{% if tmp_key == search_con['status'] %} selected {% endif %}>{{ status_mapping[ tmp_key ] }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" name="mix_kw" placeholder="请输入关键字" class="form-control" value="">
<input type="text" name="mix_kw" placeholder="请输入关键字" class="form-control" value="{{search_con['mix_kw']}}">
<input type="hidden" name="p" value="{{ search_con['p'] }}">
<span class="input-group-btn">
<button type="button" class="btn btn-primary search">
<i class="fa fa-search"></i>搜索
@@ -49,13 +51,15 @@
</tr>
</thead>
<tbody>
{% if list %}
{% for item in list %}
<tr>
<td><img alt="image" class="img-circle" src="{{ buildStaticUrl('/images/common/avatar.png') }}" style="width: 40px;height: 40px;"></td>
<td>编程浪子</td>
<td>未填写</td>
<td>正常</td>
<td><img alt="image" class="img-circle" src="{{ item.avatar }}" style="width: 40px;height: 40px;"></td>
<td>{{ item.nickname }}</td>
<td>{{ item.sex_desc }}</td>
<td>{{ item.status_desc }}</td>
<td>
<a href="{{ buildUrl('/member/info') }}">
<a href="{{ buildUrl('/member/info') }}?id={{ item.id}}">
<i class="fa fa-eye fa-lg"></i>
</a>
<a class="m-l" href="{{ buildUrl('/member/set') }}">
@@ -67,17 +71,17 @@
</a>
</td>
</tr>
{% endfor %}
{% else %}
<tr><td colspan="5">暂无数据</td></tr>
{% endif %}
</tbody>
</table>
<!--分页代码已被封装到统一模板文件中-->
<div class="row">
<div class="col-lg-12">
<span class="pagination_count" style="line-height: 40px;">共1条记录 | 每页50条</span>
<ul class="pagination pagination-lg pull-right" style="margin: 0 0 ;">
<li class="active"><a href="javascript:void(0);">1</a></li>
</ul>
</div>
</div>
{% include 'common/pagenation.html'%}
</div>
</div>
{% endblock %}
{% block js %}
<script src="{{ buildStaticUrl('/js/member/index.js') }}"></script>
{% endblock %}

View File

@@ -19,7 +19,7 @@
<div class="row">
<div class="col-lg-12">
<div class="m-b-md">
<a class="btn btn-outline btn-primary pull-right" href="{{ buildUrl('/member/set') }}">
<a class="btn btn-outline btn-primary pull-right" href="{{ buildUrl('/member/set') }}?id={{ info.id }}">
<i class="fa fa-pencil"></i>编辑
</a>
<h2>会员信息</h2>
@@ -28,12 +28,12 @@
</div>
<div class="row">
<div class="col-lg-2 text-center">
<img class="img-circle circle-border" src="{{ buildStaticUrl('/images/common/avatar.png') }}"
<img class="img-circle circle-border" src="{{ info.avatar }}"
width="100px" height="100px">
</div>
<div class="col-lg-10">
<p class="m-t">姓名:编程浪子</p>
<p>性别:未填写</p>
<p class="m-t">姓名:{{ info.nickname }}</p>
<p>性别:{{ info.sex_desc }}</p>
</div>
</div>
<div class="row m-t">