import datetime
from django.shortcuts import render, redirect
from django.views import View
from web.config import upload, get_excel_c, read_excel
from web.models import *
class Index(View):
def get(self, request):
return render(request, 'login.html')
def post(self, request):
type_uuid = int(request.POST.get('type'))
account = request.POST.get('username')
password = request.POST.get('password')
users = User.objects.filter(types=type_uuid, account=account, password=password)
if users:
user = users[0]
request.session['user'] = {
"role": type_uuid,
'account': account,
'id': user.id,
}
if type_uuid == '1':
admin = True
return redirect("/home/")
if type_uuid == '2':
manage = True
return redirect("/home/")
if type_uuid == '3':
czy = True
return redirect("/kk/")
return redirect('/home/')
else:
error = '不存在该账户'
return render(request, 'login.html', locals())
import os
from django.db.models import Q
from django.core.paginator import Paginator
class Home(View):
def get(self, request):
delete_id = request.GET.get('delete_id')
page = request.GET.get('page', 1)
if delete_id:
u = User.objects.get(id=int(delete_id))
ms = Manage.objects.filter(user=u)
for i in ms:
i.delete()
u.delete()
return redirect('/home/?page=' + page)
users_list = User.objects.filter(Q(types=None))
paginator = Paginator(users_list, 5)
users = paginator.page(int(page))
return render(request, 'UserManagement.html', locals())
def post(self, request):
obj = request.FILES.get('file')
type = request.POST.get('type')
if type == 'upload':
if 'xlsx' != obj.name.split('.')[1]:
error = '文件类型错误'
return render(request, 'UserManagement.html', locals())
else:
f = open(os.path.join('media/3.xlsx'), 'wb')
for chunk in obj.chunks():
f.write(chunk)
f.close()
data = upload()
if not data:
error = "数据不完成,缺少用户图像"
else:
ne = 1
for i in data:
h = User.objects.filter(number=i[1])
if not h:
if os.path.isfile('static/media/image{0}.png'.format(str(ne))):
user = User(number=i[1], display_name=i[2], sex=i[3], class_name=i[4],
img='image{0}.png'.format(str(ne)))
user.save()
else:
user = User(number=i[1], display_name=i[2], sex=i[3], class_name=i[4],
img='image{0}.jpeg'.format(str(ne)))
user.save()
ne += 1
return redirect('/home/')
from django.http import FileResponse
class Cd(View):
def get(self, request):
delete_id = request.GET.get('delete_id')
page = request.GET.get('page', 1)
time = request.GET.get('date')
if time:
users_lists = Manage.objects.filter(types='cd').filter(time__contains=time)
sql = "select a.display_name,a.sex,a.class_name,b.time,b.total_hours FROM web_user a RIGHT JOIN web_manage b ON a.id=b.user_id WHERE b.time like '{0}' and b.types='cd'".format(
'%%' + time + '%%')
key = ()
lists = ["姓名", '性别', '班级', '迟到时间', '迟到时长']
get_excel_c(sql, key, lists)
file = open('media/ok.xls', 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}.xls"'.format(time)
return response
users_list = Manage.objects.filter(types='cd')
if delete_id:
u = User.objects.get(id=int(delete_id))
u.delete()
return redirect('/cd/?page=' + page)
paginator = Paginator(users_list, 5)
users = paginator.page(int(page))
return render(request, 'OrderManagement.html', locals())
def post(self, request):
search = request.POST.get('search')
time = request.POST.get('time')
if search:
sh_users = User.objects.filter(Q(display_name=search) | Q(number=search))
if sh_users:
sh_user = sh_users[0]
else:
error = "不存在此人信息"
users_list = Manage.objects.filter(types='cd')
paginator = Paginator(users_list, 5)
page = 1
users = paginator.page(int(page))
return render(request, 'OrderManagement.html', locals())
if time:
type = request.POST.get("type")
user = request.POST.get("user")
t = datetime.datetime.now().strftime('%Y-%m-%d %H:%M-%S')
m = Manage(total_hours=time, user=User.objects.get(id=int(user)), time=t, types='cd')
m.save()
sh_user = None
error = '成功'
return redirect('/cd/')
class Wg(View):
def get(self, request):
delete_id = request.GET.get('delete_id')
page = request.GET.get('page', 1)
time = request.GET.get('date')
if time:
users_lists = Manage.objects.filter(types='wg').filter(time__contains=time)
sql = "select a.number,a.display_name,a.sex,a.class_name,b.time,b.total_hours FROM web_user a RIGHT JOIN web_manage b ON a.id=b.user_id WHERE b.time like '{0}' and b.types='wg'".format(
'%%' + time + '%%')
key = ()
lists = ["学号", "姓名", '性别', '班级', '晚归时间', '晚归时长']
get_excel_c(sql, key, lists)
file = open('media/ok.xls', 'rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}.xls"'.format(time)
return response
users_list = Manage.objects.filter(types='wg')
if delete_id:
u = User.objects.get(id=int(delete_id))
u.delete()
return redirect('/wg/?page=' + page)
paginator = Paginator(users_list, 5)
users = paginator.page(int(page))
return render(request, 'classificationManagement.html', locals())
def post(self, request):
search = request.POST.get('search')
time = request.POST.get('time')
obj = request.FILES.get('file')
type = request.POST.get('type')
if type == 'upload':
if 'xlsx' != obj.name.split('.')[1] and 'xls' != obj.name.split('.')[1]:
error = '文件类型错误'
return render(request, 'classificationManagement.html', locals())
else:
f = open(os.path.join('media/3.xls'), 'wb')
for chunk in obj.chunks():
f.write(chunk)
f.close()
data, lens = read_excel('media/3.xls')
for i in data:
try:
m = Manage(user=User.objects.get(number=i[0]), total_hours=i[5], time=i[4], types='wg')
m.save()
except Exception as e:
print(e)
pass
os.remove('media/3.xls')
return redirect('/wg/')
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于python的Django做学生考勤管理系统.zip (88个子文件)
django+学生迟到-晚归记录操作excel
project
media
32.xlsx 76KB
ok.xls 6KB
web
__init__.py 0B
tests.py 63B
admin.py 0B
ok.xls 42KB
migrations
__init__.py 0B
0001_initial.py 2KB
__pycache__
0001_initial.cpython-39.pyc 1KB
__init__.cpython-39.pyc 153B
0001_initial.cpython-37.pyc 1KB
__init__.cpython-37.pyc 198B
apps.py 144B
models.py 957B
__pycache__
config.cpython-39.pyc 4KB
__init__.cpython-39.pyc 142B
views.cpython-37.pyc 11KB
admin.cpython-37.pyc 184B
models.cpython-39.pyc 1KB
views.cpython-39.pyc 10KB
models.cpython-37.pyc 1KB
__init__.cpython-37.pyc 187B
apps.cpython-37.pyc 454B
apps.cpython-39.pyc 413B
config.cpython-37.pyc 4KB
admin.cpython-39.pyc 139B
views.py 14KB
config.py 4KB
templates
admin_manage.html 8KB
ccy_manage.html 8KB
login.html 4KB
classificationManagement.html 11KB
OrderManagement.html 10KB
ProductManagement.html 7KB
UserManagement.html 7KB
.idea
workspace.xml 3KB
misc.xml 194B
project.iml 1KB
inspectionProfiles
Project_Default.xml 71KB
profiles_settings.xml 174B
modules.xml 273B
.gitignore 295B
manage.py 692B
static
media
image2.jpeg 30KB
image1.jpeg 22KB
image3.png 15KB
image3.jpeg 13KB
js
jQuery1.7.js 92KB
jquery-1.8.2.min.js 91KB
Validform_v5.3.2.js 44KB
jquery.SuperSlide.js 11KB
jquery-1.9.1.min.js 90KB
f.js 1KB
Validform_v5.3.2_min.js 20KB
jquery1.42.min.js 71KB
css
iconfont.css 5KB
reset.css 744B
login.css 3KB
index.css 14KB
images
copy_rignt_24.png 332B
2.jpg 202KB
logo.png 19KB
1.jpg 453KB
bg.jpg 258KB
0.jpg 88KB
productimg.jpg 5KB
11.jpg 258KB
logo.jpg 5KB
user.jpg 18KB
captcha.jpg 2KB
fonts
iconfont.ttf 5KB
iconfont.woff2 3KB
iconfont.svg 14KB
iconfont.eot 5KB
iconfont.woff 3KB
project
__init__.py 48B
wsgi.py 407B
urls.py 1KB
settings.py 3KB
__pycache__
urls.cpython-39.pyc 1KB
__init__.cpython-39.pyc 195B
settings.cpython-37.pyc 2KB
__init__.cpython-37.pyc 240B
settings.cpython-39.pyc 2KB
wsgi.cpython-37.pyc 594B
urls.cpython-37.pyc 1KB
wsgi.cpython-39.pyc 549B
asgi.py 407B
共 88 条
- 1
资源评论
- L26547383832024-04-24发现一个超赞的资源,赶紧学习起来,大家一起进步,支持!
等天晴i
- 粉丝: 3521
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功