Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	demo02/db.sqlite3
  • Loading branch information
cjb0721 committed Jun 22, 2019
2 parents cd1e578 + 90fdd8d commit 025b9a0
Show file tree
Hide file tree
Showing 416 changed files with 67,054 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Library/BookLibrary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@
# 发送邮件
url('mail/$', views.mail, name="mail"),
url('active/(.*?)/$', views.active, name="active"),
# Ajax异步刷新
url('ajax/$', views.ajax, name="ajax"),
url('ajaxs/$', views.ajaxs, name="ajaxs"),
url('^ajaxlogin/$', views.ajaxlogin, name="ajaxlogin"),
url('^checkuser/$', views.checkuser, name="checkuser"),
url('^verifycode/$', views.verifycode, name="verifycode"),

url('^echarts/$', views.echarts, name="echarts"),
]

87 changes: 86 additions & 1 deletion Library/BookLibrary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
from django.core.mail import send_mail, send_mass_mail
from django.conf import settings

import random, io
from PIL import Image,ImageDraw,ImageFont

from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, SignatureExpired

# Create your views here.
from django.views.decorators.cache import cache_page

# Create your views here.

@cache_page(60*15)
def index(request):
# return HttpResponse("你好,世界!")
messinfo = MessInfo.objects.all()
Expand Down Expand Up @@ -288,6 +293,86 @@ def active(request, id):
return HttpResponse("连接失败")


def ajax(request):
return render(request, 'BookLibrary/ajax.html')

def ajaxs(request):
if request.method == 'GET':
return HttpResponse("GET成功")
elif request.method == 'POST':
return HttpResponse("POST成功")


def ajaxlogin(request):
if request.method == 'GET':
return render(request, 'BookLibrary/ajaxlogin.html')
elif request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
verifycode = request.POST['verifycode']
user = Users.objects.filter(name=username).filter(pwd=password).first()
if user is None:
return HttpResponse("用户名或密码错误")
else:
if verifycode == request.session.get("verifycode"):
return HttpResponse("登陆成功")
else:
return HttpResponse("验证码错误")


def checkuser(request):
if request.method == 'POST':
username = request.POST['username']
user = Users.objects.filter(name=username).first()
if user is None:
return HttpResponse("false")
else:
return HttpResponse("accept")


def verifycode(request):
# 生成一张验证码图片
# 定义变量,用于画面的背景色、宽、高
bgcolor = (random.randrange(20, 100),random.randrange(20, 100),random.randrange(20, 100))
width = 100
heigth = 25
# 创建画面对象
im = Image.new('RGB', (width, heigth), bgcolor)
# 创建画笔对象
draw = ImageDraw.Draw(im)
# 调用画笔的point()函数绘制噪点
for i in range(0, 100):
xy = (random.randrange(0, width), random.randrange(0, heigth))
fill = (random.randrange(0, 255), 255, random.randrange(0, 255))
draw.point(xy, fill=fill)
# 定义验证码的备选值
str1 = 'ABCD123EFGHIJK456LMNOPQRS789TUVWXYZ0'
# 随机选取4个值作为验证码
rand_str = ''
for i in range(0, 4):
rand_str += str1[random.randrange(0, len(str1))]
# 构造字体对象
# font = ImageFont.truetype('SCRIPTBL.TTF', 23)
font = ImageFont.truetype('/static/fonts/MAGNETOB.TTF', 23)
fontcolor = (255, random.randrange(0, 255), random.randrange(0, 255))
# 绘制4个字
draw.text((5, 2), rand_str[0], font=font, fill=fontcolor)
draw.text((25, 2), rand_str[1], font=font, fill=fontcolor)
draw.text((50, 2), rand_str[2], font=font, fill=fontcolor)
draw.text((75, 2), rand_str[3], font=font, fill=fontcolor)


# 释放画笔
del draw
# 将生成的验证码存入session
request.session['verifycode'] = rand_str
print(rand_str)
f = io.BytesIO()
im.save(f, 'png')
# 将内存中的图片数据返回给客户端,MIME类型为图片png
return HttpResponse(f.getvalue(), 'image/png')


def echarts(request):
return render(request, 'BookLibrary/echarts.html')

8 changes: 8 additions & 0 deletions Library/Library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
EMAIL_HOST_PASSWORD = 'qikuedu'
DEFAULT_FROM_EMAIL = 'zzy0371 <[email protected]>'

# 缓存
CACHES = {
"default": {
"BACKEND": "redis_cache.cache.RedisCache",
"LOCATION": "localhost:6379",
'TIMEOUT': 60,
},
}



Binary file modified Library/db.sqlite3
Binary file not shown.
20 changes: 20 additions & 0 deletions Library/list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Click==7.0
Django==2.2
django-haystack==2.8.1
django-redis-cache==2.0.0
django-redis-sessions==0.6.1
django-tinymce==2.8.0
Flask==1.0.2
itsdangerous==1.1.0
jieba==0.39
Jinja2==2.10.1
Markdown==3.1
MarkupSafe==1.1.1
mysqlclient==1.4.2.post1
Pillow==6.0.0
PyMySQL==0.9.3
pytz==2019.1
redis==3.2.1
sqlparse==0.3.0
Werkzeug==0.15.2
Whoosh==2.7.4
Binary file added Library/static/fonts/MAGNETOB.TTF
Binary file not shown.
38 changes: 38 additions & 0 deletions Library/templates/BookLibrary/ajax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajax</title>

<script src="/static/js/jquery-2.1.4.js"></script>
<!--Load方法可以将服务器资源加载到制定元素-->
<script>
$(function () {
$("#load").click(function () {
$(".info").load("/static/css/style.css");
})

$("#ajax").click(function () {
$.ajax({
url: '/booklibrary/ajaxs/',
type: 'get',
data: {'csrfmiddlewaretoken': $("input[name='csrfmiddlewaretoken']").val()},
success: function (data) {
console.log(data)
}
})
})

})
</script>

</head>
<body>
{% csrf_token %}
<button id="load">点我load方法</button>
<div class="info"></div>
<button id="ajax">点我ajax方法</button>
<div class="info2"></div>

</body>
</html>
44 changes: 44 additions & 0 deletions Library/templates/BookLibrary/ajaxlogin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% extends 'BookLibrary/base.html' %}
{% block title %}登录{% endblock %}
{% block linkjs %}
<script>

$(function () {
$('#username').blur(function () {
// console.log("+++")
$.ajax({
url: '/booklibrary/checkuser/',
type: 'post',
data: {
"csrfmiddlewaretoken": $("input[name=csrfmiddlewaretoken]").val(),
"username": $("#username").val()
},
success: function (data) {
console.log("+++")
console.log(data)
$('#userinfo').text(data);
}
})
})
$('#verifycode').click(function () {
t = new Date()
this.src = '/booklibrary/verifycode/?t='+t.getTime()
})
})

</script>
{% endblock %}

{% block body %}

<h2>登录</h2>
<form action="{% url 'booklibrary:ajaxlogin' %}" method="post">
{% csrf_token %}
用户: <input type="text" name="username" id="username"> <span id="userinfo"></span><br>
密码: <input type="password" name="password" id="password"><br>
验证码: <input type="text" name="verifycode"><img src="{% url 'booklibrary:verifycode' %}" alt="验证码加载失败" id="verifycode"><br>
<input type="submit" value="登录">

</form>

{% endblock %}
3 changes: 2 additions & 1 deletion Library/templates/BookLibrary/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
{% load static from staticfiles %}
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% block linkjs %}{% endblock %}

<script src="{% static 'js/jquery-2.1.4.js' %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static 'js/bootstrap.js' %}" type="text/javascript" charset="utf-8"></script>
{% block linkjs %}{% endblock %}

</head>
<body>
Expand Down
141 changes: 141 additions & 0 deletions Library/templates/BookLibrary/echarts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图表显示</title>
<style>
div{
float: left;
}
</style>
<script src="https://echarts.baidu.com/examples/vendors/echarts/echarts.min.js"></script>
</head>
<body>

<div id="main" style="width: 600px;height:400px;"></div>
<div id="main2" style="width: 600px;height:400px;"></div>
<div id="main3" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart1 = echarts.init(document.getElementById('main'));
var myChart2 = echarts.init(document.getElementById('main2'));

// 指定图表的配置项和数据
var option1 = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};

// 使用刚指定的配置项和数据显示图表。
myChart1.setOption(option1);




var dataCount = 5e5;
var data = generateData(dataCount);

var option2 = {
title: {
text: echarts.format.addCommas(dataCount) + ' Data',
left: 10
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false
},
saveAsImage: {
pixelRatio: 2
}
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
bottom: 90
},
dataZoom: [{
type: 'inside'
}, {
type: 'slider'
}],
xAxis: {
data: data.categoryData,
silent: false,
splitLine: {
show: false
},
splitArea: {
show: false
}
},
yAxis: {
splitArea: {
show: false
}
},
series: [{
type: 'bar',
data: data.valueData,
// Set `large` for large data amount
large: true
}]
};

function generateData(count) {
var baseValue = Math.random() * 1000;
var time = +new Date(2011, 0, 1);
var smallBaseValue;

function next(idx) {
smallBaseValue = idx % 30 === 0
? Math.random() * 700
: (smallBaseValue + Math.random() * 500 - 250);
baseValue += Math.random() * 20 - 10;
return Math.max(
0,
Math.round(baseValue + smallBaseValue) + 3000
);
}

var categoryData = [];
var valueData = [];

for (var i = 0; i < count; i++) {
categoryData.push(echarts.format.formatTime('yyyy-MM-dd\nhh:mm:ss', time));
valueData.push(next(i).toFixed(2));
time += 1000;
}

return {
categoryData: categoryData,
valueData: valueData
};
}
myChart2.setOption(option2);
</script>




</body>
</html>
Loading

0 comments on commit 025b9a0

Please sign in to comment.