forked from zhaoyiCC/iCourse_Web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackInterface.py
More file actions
40 lines (37 loc) · 1.22 KB
/
backInterface.py
File metadata and controls
40 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'''
Created on 2017年10月28日
@author: 15061188
'''
# -*- coding: utf-8 -*-
from backend.models import Resource, User
import os
import time
'''
根据资源ID,返回资源链接
ID不存在则返回"no match"
无副作用
'''
def getLinkById(_id):
try:
ans = Resource.objects.get(id=_id)
except:
return "找不到链接"
return ans.link
#相较于其他属性,id是最适合互异的,所以每个资源的id都要不一样
def addResource(_id, userId, courseId, resName="name", resPath="", resIntroduction=""):
if (os.path.exists(resPath) == False):
return "找不到文件!"
fsize = round(os.path.getsize(resPath)/float(1024*1024), 2)
curTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
temp=Resource(id=_id, name=resName, link=resPath, introduce=resIntroduction, size=fsize, uploadTime=curTime, upload_user_id=userId, course_id=courseId)
temp.save()
return "添加成功!"
def checkUsernameAndPassword(_username, _password):
try:
ans = User.objects.get(username=_username)
except:
return "用户名不存在"
if (ans.password == _password):
return "登陆成功"
else:
return "账户名与密码不符"