import json
from django.core import serializers
from django.forms import model_to_dict
from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from rest_framework.decorators import api_view, parser_classes
from rest_framework.parsers import FormParser
from app import models
import datetime
from datetime import date
# Create your views here.
def get(response):
return JsonResponse({'name': 'pyt'})
def test(request):
hello = ('test', 'nice to meet you')
# print(request)
return JsonResponse({'header': hello})
@csrf_exempt
def searchUser(request):
global password
# print("=======================")
# print(request.POST)
# print("=======================")
print(str(request.POST.get('account')) + " 正在登录......")
user = models.Users.objects.filter(account=request.POST.get('account'))
# print(user)
if user.exists():
for item in user:
password = model_to_dict(item).get('password')
getToday()
if int(request.POST.get('password')) == password:
print("登录成功")
for i in models.Users.objects.filter(account=request.POST.get('account')):
if i.__getattribute__('type') == '0':
return HttpResponse(0)
elif i.__getattribute__('type') == '2':
return HttpResponse(3)
else:
return HttpResponse(2)
else:
return HttpResponse(1)
else:
return HttpResponse(-1)
def getToday():
# 获取当前日期
current_date = datetime.date.today()
# 输出当前日期
# print("当前日期为:", current_date)
# print("第" + str(get_week_num(str(current_date))) + "周")
return str(get_week_num(str(current_date)))
def get_week_num(date):
date = datetime.datetime.strptime(date, '%Y-%m-%d')
first_day_of_week = datetime.datetime(2023, 4, 24)
week_number = ((date - first_day_of_week).days // 7) + 1
return week_number
# 获取今天是第几周
@csrf_exempt
def getWeekToday(request):
date = ''
# print(request.POST)
for item in request.POST:
date = item
# print(getWhatWeek(date))
result = get_week_num(date)
# print(result)
return HttpResponse(result)
@csrf_exempt
def userSearchByApartment(request):
all = []
# print(request.POST)
result = []
for item in request.POST.values():
# print(item)
result.append(models.Users.objects.filter(apartment=item))
# print(result)
if not request.POST:
result.append(models.Users.objects.all())
# print('this is the result:'+str(result))
peoples = []
j = 0
for i in result:
# print(i.count())
for j in range(0, i.count()):
leader = ''
if i.values_list()[j][6] != '':
for item in models.Users.objects.filter(id=i.values_list()[j][6]):
leader = item.__getattribute__('name')
people = {'id': i.values_list()[j][0],
'name': i.values_list()[j][2],
'department': i.values_list()[j][3],
'account': i.values_list()[j][4],
'password': i.values_list()[j][5],
'leader': leader}
# print(people)
peoples.append(people)
leaders = []
for item in models.Users.objects.filter(type=1):
leader = {
'label': item.__getattribute__('name'),
'value': item.__getattribute__('name')
}
leaders.append(leader)
all.append(peoples)
all.append(leaders)
json_data = json.dumps(all)
return JsonResponse(json_data, safe=False)
@csrf_exempt
def getMemoryByAccount(request):
all = []
duration = ''
status = ''
data = json.loads(request.body)
# print(data)
# print(data.get('account'))
weekToday = getToday()
# print("weekToday is " + weekToday)
account = data.get('account')
projectId = []
userId = ''
for item in models.Users.objects.filter(account=account):
userId = item.__getattribute__('id')
for item in models.UserToProject.objects.filter(userId=userId):
projectId.append(item.__getattribute__('projectId'))
for perProjectId in projectId:
for i in models.Project.objects.filter(id=perProjectId):
if models.Memory.objects.filter(userAccount=account, projectName=i.__getattribute__('name'),
weekNumber=getToday()).exists():
for j in models.Memory.objects.filter(userAccount=account, projectName=i.__getattribute__('name'),
weekNumber=getToday()):
duration = j.__getattribute__('timeLength')
status = j.__getattribute__('status')
else:
duration = 0
status = '未审核'
message = {
'name': i.__getattribute__('name'),
'duration': duration,
'type': i.__getattribute__('type'),
'status': status
}
all.append(message)
for i in models.Memory.objects.filter(userAccount=account, type='其他项目'):
message = {
'name': i.__getattribute__('projectName'),
'duration': i.__getattribute__('timeLength'),
'type': i.__getattribute__('type'),
'status': i.__getattribute__('status')
}
all.append(message)
json_data = json.dumps(all)
return JsonResponse(json_data, safe=False)
@csrf_exempt
def newMemory(request):
# print('hello')
memory = json.loads(request.body)
week = getToday()
# print(memory)
leaderId = ''
for i in models.Users.objects.filter(account=memory.get('account')):
leaderId = i.__getattribute__('leader')
memoryNew = models.Memory(userAccount=memory.get('account'), type=memory.get('type'),
timeLength=memory.get('duration'),
projectName=memory.get('name'),
status=memory.get('status'), weekNumber=week,
submitTime=date.today(), leaderId=leaderId)
print(memoryNew.save())
return HttpResponse(1)
@csrf_exempt
def changeMemory(request):
change = json.loads(request.body)
week = getToday()
# print("====================================================================", change)
# print(week)
if models.Memory.objects.filter(userAccount=change.get('account'), projectName=change.get('name'),
weekNumber=week).exists():
models.Memory.objects.filter(userAccount=change.get('account'), projectName=change.get('name'),
weekNumber=week).update(timeLength=change.get('duration'), submitTime=date.today(),
status='未审核')
else:
if change.get('type') == '其他项目':
leaderId = ''
for i in models.Users.objects.filter(account=change.get('account')):
leaderId = i.__getattribute__('leader')
models.Memory(userAccount=change.get('account'), projectName=change.get('name'), weekNumber=week,
submitTime=date.today(),
timeLength=change.get('duration'), type=change.get('type'), status=change.get('status'),
leaderId=leaderId).save()
else:
leaderId = ''
for i in models.Project.objects.filter(name=change.get('name')):
l
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于django开发的工时管理系统后端源码+sql数据库.zip基于django开发的工时管理系统后端源码+sql数据库.zip基于django开发的工时管理系统后端源码+sql数据库.zip基于django开发的工时管理系统后端源码+sql数据库.zip基于django开发的工时管理系统后端源码+sql数据库.zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于django开发的工时管理系统后端源码+sql数据库.zip (84个子文件)
timecontroller.sql 28KB
timecontrollerback
db.sqlite3 0B
app
__init__.py 0B
tests.py 63B
admin.py 66B
migrations
__init__.py 0B
0006_memory_weeknumber.py 387B
0011_project_leadername.py 411B
0013_memory_savetime.py 391B
0008_rename_submittimt_users_submittime.py 380B
0003_users_workaccount.py 422B
0001_initial.py 682B
0009_remove_users_submittime_memory_submittime.py 522B
0012_memory_leaderid.py 397B
0007_users_submittimt.py 394B
0004_project_usertoproject_users_type_alter_users_id.py 1KB
0005_memory.py 849B
0002_users_leader_alter_users_account_and_more.py 1KB
__pycache__
0005_memory.cpython-311.pyc 1KB
__init__.cpython-311.pyc 194B
0010_project_numbering.cpython-311.pyc 868B
0007_users_submittimt.cpython-311.pyc 820B
0009_remove_users_submittime_memory_submittime.cpython-311.pyc 960B
0003_users_workaccount.cpython-311.pyc 850B
0008_rename_submittimt_users_submittime.cpython-311.pyc 765B
0012_memory_leaderid.cpython-311.pyc 822B
0004_project_usertoproject_users_type_alter_users_id.cpython-311.pyc 2KB
0001_initial.cpython-311.pyc 1KB
0002_users_leader_alter_users_account_and_more.cpython-311.pyc 2KB
0011_project_leadername.cpython-311.pyc 845B
0006_memory_weeknumber.cpython-311.pyc 814B
0013_memory_savetime.cpython-311.pyc 816B
0010_project_numbering.py 434B
apps.py 86B
models.py 2KB
urls.py 1KB
__pycache__
models.cpython-311.pyc 3KB
__init__.cpython-311.pyc 183B
admin.cpython-311.pyc 238B
views.cpython-311.pyc 41KB
__init__.cpython-39.pyc 165B
apps.cpython-39.pyc 368B
urls.cpython-311.pyc 2KB
apps.cpython-311.pyc 476B
views.py 29KB
timecontrollerback
__init__.py 0B
cors.py 267B
wsgi.py 429B
urls.py 939B
settings.py 4KB
__pycache__
__init__.cpython-311.pyc 198B
urls.cpython-39.pyc 1016B
__init__.cpython-39.pyc 180B
settings.cpython-311.pyc 4KB
wsgi.cpython-311.pyc 742B
settings.cpython-39.pyc 2KB
urls.cpython-311.pyc 1KB
dist
index.html 0B
static
js
app.06ec7923a33e722be175.js 47KB
app.ee9de76d16e23b1cfa91.js 46KB
app.62bef96bfb33085277f1.js.map 187KB
app.be49477852a5ca20e02a.js.map 187KB
app.be49477852a5ca20e02a.js 47KB
app.ee9de76d16e23b1cfa91.js.map 186KB
app.bcf1b269cfeeab635d47.js 46KB
manifest.2ae2e69a05c33dfc65f8.js.map 5KB
vendor.2617e61fd43703f797b8.js.map 0B
app.c10da937918f3feaf760.js.map 187KB
app.62bef96bfb33085277f1.js 46KB
app.153756c528d60c0586c9.js.map 186KB
app.06ec7923a33e722be175.js.map 187KB
app.c10da937918f3feaf760.js 47KB
vendor.2617e61fd43703f797b8.js 970KB
app.bcf1b269cfeeab635d47.js.map 186KB
manifest.2ae2e69a05c33dfc65f8.js 857B
app.153756c528d60c0586c9.js 46KB
img
th.e55d0cf.jpg 0B
css
app.a8281b976caaa8206a444ac63245e30e.css.map 340KB
app.a8281b976caaa8206a444ac63245e30e.css 237KB
app.4f9cc48f189961a42d0b497b64e5d961.css.map 340KB
app.4f9cc48f189961a42d0b497b64e5d961.css 237KB
fonts
element-icons.535877f.woff 0B
element-icons.732389d.ttf 0B
manage.py 659B
共 84 条
- 1
资源评论
- kaiha12024-05-13资源不错,对我启发很大,获得了新的灵感,受益匪浅。
- 2301_773078222024-04-25发现一个宝藏资源,赶紧冲冲冲!支持大佬~
onnx
- 粉丝: 9634
- 资源: 5598
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功