mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Merge branch 'development' of github.com:Rushilwiz/SkoolOS into development
Conflicts: CLI/student.py CLI/teacher.py skoolos.py
This commit is contained in:
commit
11c0c03bae
|
@ -13,15 +13,15 @@ import datetime
|
||||||
# git clone student directory ==> <student-id>/classes/assignments
|
# git clone student directory ==> <student-id>/classes/assignments
|
||||||
|
|
||||||
# get teacher info from api
|
# get teacher info from api
|
||||||
def getStudent(ion_user):
|
def getStudent(ion_user, password):
|
||||||
"""
|
"""
|
||||||
Get's student information from the api
|
Get's student information from the api
|
||||||
:param ion_user: a student
|
:param ion_user: a student
|
||||||
:return: student information or error
|
:return: student information or error
|
||||||
"""
|
"""
|
||||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||||
r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.get(url=URL, auth=(ion_user, password))
|
||||||
if r.status_code == 200:
|
if (r.status_code == 200):
|
||||||
data = r.json()
|
data = r.json()
|
||||||
return data
|
return data
|
||||||
elif r.status_code == 404:
|
elif r.status_code == 404:
|
||||||
|
@ -36,60 +36,61 @@ def getStudent(ion_user):
|
||||||
|
|
||||||
|
|
||||||
# makes a GET request to given url, returns dict
|
# makes a GET request to given url, returns dict
|
||||||
def getDB(url):
|
def getDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a GET request to the URL
|
Sends a GET request to the URL
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.get(url=url, auth=(user, pwd))
|
||||||
print("GET:" + str(r.status_code))
|
print("GET:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# makes a PATCH (updates instance) request to given url, returns dict
|
# makes a PATCH (updates instance) request to given url, returns dict
|
||||||
def patchDB(data, url):
|
def patchDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PATCH request to the URL
|
Sends a PATCH request to the URL
|
||||||
:param data:
|
:param data:
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||||
print("PATCH:" + str(r.status_code))
|
print("PATCH:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# makes a POST (makes new instance) request to given url, returns dict
|
# makes a POST (makes new instance) request to given url, returns dict
|
||||||
def postDB(data, url):
|
def postDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a POST request to the URL
|
Sends a POST request to the URL
|
||||||
:param data:
|
:param data:
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||||
print("POST:" + str(r.status_code))
|
print("POST:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# makes a PUT (overwrites instance) request to given url, returns dict
|
# makes a PUT (overwrites instance) request to given url, returns dict
|
||||||
def putDB(data, url):
|
def putDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PUT request to the URL
|
Sends a PUT request to the URL
|
||||||
:param data:
|
:param data:
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||||
print("PUT:" + str(r.status_code))
|
print("PUT:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# makes a DELETE (delete instance) request to given url, returns dict
|
# makes a DELETE (delete instance) request to given url, returns dict
|
||||||
def delDB(url):
|
def delDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a DELETE request to the URL
|
Sends a DELETE request to the URL
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.delete(url=url, auth=(user, pwd))
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def command(command):
|
def command(command):
|
||||||
|
@ -112,7 +113,7 @@ def command(command):
|
||||||
|
|
||||||
# public methods: deleteClass, makeClass, update
|
# public methods: deleteClass, makeClass, update
|
||||||
class Student:
|
class Student:
|
||||||
def __init__(self, data):
|
def __init__(self, data, password):
|
||||||
# teacher info already stored in API
|
# teacher info already stored in API
|
||||||
# intitialze fields after GET request
|
# intitialze fields after GET request
|
||||||
"""
|
"""
|
||||||
|
@ -125,6 +126,7 @@ class Student:
|
||||||
self.grade = data['grade']
|
self.grade = data['grade']
|
||||||
self.completed = data['completed']
|
self.completed = data['completed']
|
||||||
self.user = data['user']
|
self.user = data['user']
|
||||||
|
self.password = password
|
||||||
# classes in id form (Example: 4,5)
|
# classes in id form (Example: 4,5)
|
||||||
# storing actual classes
|
# storing actual classes
|
||||||
cid = data['classes'].split(",")
|
cid = data['classes'].split(",")
|
||||||
|
@ -139,7 +141,7 @@ class Student:
|
||||||
classes = []
|
classes = []
|
||||||
for c in cid:
|
for c in cid:
|
||||||
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
|
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
|
||||||
classes.append(getDB(url))
|
classes.append(getDB(self.username, self.password,url))
|
||||||
|
|
||||||
self.classes = classes
|
self.classes = classes
|
||||||
self.sclass = str(data['classes'])
|
self.sclass = str(data['classes'])
|
||||||
|
@ -157,7 +159,7 @@ class Student:
|
||||||
nclasses = []
|
nclasses = []
|
||||||
for c in nid:
|
for c in nid:
|
||||||
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
|
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
|
||||||
nclasses.append(getDB(url))
|
nclasses.append(getDB(self.username, self.password,url))
|
||||||
|
|
||||||
self.new = nclasses
|
self.new = nclasses
|
||||||
self.snew = str(data['added_to'])
|
self.snew = str(data['added_to'])
|
||||||
|
@ -184,7 +186,7 @@ class Student:
|
||||||
data = {
|
data = {
|
||||||
'repo': self.repo
|
'repo': self.repo
|
||||||
}
|
}
|
||||||
print(patchDB(data, self.url))
|
print(patchDB(self.username, self.password,data, self.url))
|
||||||
print("Synced to " + self.username)
|
print("Synced to " + self.username)
|
||||||
|
|
||||||
def getClasses(self):
|
def getClasses(self):
|
||||||
|
@ -206,7 +208,7 @@ class Student:
|
||||||
print(c['name'])
|
print(c['name'])
|
||||||
alist = c['assignments']
|
alist = c['assignments']
|
||||||
for a in alist:
|
for a in alist:
|
||||||
ass = getDB("http://127.0.0.1:8000/api/assignments/" + a)
|
ass = getDB(self.username, self.password,"http://127.0.0.1:8000/api/assignments/" + a)
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
try:
|
try:
|
||||||
due = ass['due_date'].replace("T", " ").replace("Z", "")
|
due = ass['due_date'].replace("T", " ").replace("Z", "")
|
||||||
|
@ -231,7 +233,7 @@ class Student:
|
||||||
command("git checkout master")
|
command("git checkout master")
|
||||||
for c in self.classes:
|
for c in self.classes:
|
||||||
print("UPDATING CLASS: " + str(c['name']))
|
print("UPDATING CLASS: " + str(c['name']))
|
||||||
data = getDB("http://127.0.0.1:8000/api/classes/" + str(c['name']))
|
data = getDB(self.username, self.password,"http://127.0.0.1:8000/api/classes/" + str(c['name']))
|
||||||
# command("git checkout master")
|
# command("git checkout master")
|
||||||
command("git checkout " + data['name'])
|
command("git checkout " + data['name'])
|
||||||
command("git add .")
|
command("git add .")
|
||||||
|
@ -272,8 +274,8 @@ class Student:
|
||||||
:param cid: the id number of the class
|
:param cid: the id number of the class
|
||||||
:return: data from the class, None if an error occures
|
:return: data from the class, None if an error occures
|
||||||
"""
|
"""
|
||||||
data = getDB('http://127.0.0.1:8000/api/classes/' + str(cid))
|
data = getDB(self.username, self.password,'http://127.0.0.1:8000/api/classes/' + str(cid))
|
||||||
if not (cid in self.snew) or (self.username in data['confirmed']):
|
if ((cid in self.snew) == False or (self.username in data['confirmed'])):
|
||||||
print("Already enrolled in this class.")
|
print("Already enrolled in this class.")
|
||||||
return None
|
return None
|
||||||
if (cid in self.sclass) or not (self.username in data['unconfirmed']):
|
if (cid in self.sclass) or not (self.username in data['unconfirmed']):
|
||||||
|
@ -283,7 +285,7 @@ class Student:
|
||||||
# add class teacher as collaborator to student repo
|
# add class teacher as collaborator to student repo
|
||||||
print(os.getcwd())
|
print(os.getcwd())
|
||||||
pwd = input("Enter Github password: ")
|
pwd = input("Enter Github password: ")
|
||||||
tgit = getDB("http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git']
|
tgit = getDB(self.username, self.password,"http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git']
|
||||||
url = "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'"
|
url = "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'"
|
||||||
print(url)
|
print(url)
|
||||||
os.system(url)
|
os.system(url)
|
||||||
|
@ -336,7 +338,7 @@ class Student:
|
||||||
# recreate sclass field, using ids
|
# recreate sclass field, using ids
|
||||||
for c in self.new:
|
for c in self.new:
|
||||||
snew = snew + str(c['name']) + ","
|
snew = snew + str(c['name']) + ","
|
||||||
new.append(getDB("http://127.0.0.1:8000/api/classes/" + str(cid)))
|
new.append(getDB(self.username, self.password,"http://127.0.0.1:8000/api/classes/" + str(cid)))
|
||||||
self.snew = snew
|
self.snew = snew
|
||||||
self.new = new
|
self.new = new
|
||||||
break
|
break
|
||||||
|
@ -348,7 +350,7 @@ class Student:
|
||||||
'classes': self.sclass
|
'classes': self.sclass
|
||||||
}
|
}
|
||||||
print(self.url)
|
print(self.url)
|
||||||
print(patchDB(data, self.url))
|
print(patchDB(self.username, self.password,data, self.url))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def viewClass(self, courses):
|
def viewClass(self, courses):
|
||||||
|
@ -413,8 +415,8 @@ class Student:
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
|
||||||
# data = getStudent("2022rkhondak")
|
#data = getStudent("2022rkhondak", "PWD")
|
||||||
# s = Student(data)
|
#s = Student(data, "PWD")
|
||||||
# s.viewClass("APLit_eharris1")
|
# s.viewClass("APLit_eharris1")
|
||||||
# #s.addClass("APLit_eharris1")
|
# #s.addClass("APLit_eharris1")
|
||||||
# # #s.update()
|
# # #s.update()
|
||||||
|
|
|
@ -26,14 +26,16 @@ from datetime import datetime
|
||||||
# git clone student directory ==> <student-id>/classes/assignments
|
# git clone student directory ==> <student-id>/classes/assignments
|
||||||
|
|
||||||
# get teacher info from api
|
# get teacher info from api
|
||||||
def getTeacher(ion_user):
|
def getTeacher(ion_user, password):
|
||||||
"""
|
"""
|
||||||
Gets information about a teacher from the api
|
Gets information about a teacher from the api
|
||||||
:param ion_user: a teacher
|
:param ion_user: a teacher
|
||||||
|
:param password: a string
|
||||||
:return: teacher information or error
|
:return: teacher information or error
|
||||||
"""
|
"""
|
||||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||||
r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.get(url=URL, auth=(ion_user,password))
|
||||||
|
print(r.json())
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
data = r.json()
|
data = r.json()
|
||||||
return data
|
return data
|
||||||
|
@ -48,58 +50,67 @@ def getTeacher(ion_user):
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
|
|
||||||
#makes a GET request to given url, returns dict
|
#makes a GET request to given url, returns dict
|
||||||
def getDB(url):
|
def getDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a GET request to the URL
|
Sends a GET request to the URL
|
||||||
|
:param user: a string
|
||||||
|
:param password: a string
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.get(url=url, auth=(user, pwd))
|
||||||
print("GET:" + str(r.status_code))
|
print("GET:" + str(r.status_code))
|
||||||
return(r.json())
|
return(r.json())
|
||||||
|
|
||||||
#makes a PATCH (updates instance) request to given url, returns dict
|
#makes a PATCH (updates instance) request to given url, returns dict
|
||||||
def patchDB(data, url):
|
def patchDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PATCH request to the URL
|
Sends a PATCH request to the URL
|
||||||
:param data:
|
:param data:
|
||||||
|
:param user: a string
|
||||||
|
:param password: a string
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.patch(url=url, data=data, auth=(user, pwd))
|
||||||
print("PATCH:" + str(r.status_code))
|
print("PATCH:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
#makes a POST (makes new instance) request to given url, returns dict
|
#makes a POST (makes new instance) request to given url, returns dict
|
||||||
def postDB(data, url):
|
def postDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a POST request to the URL
|
Sends a POST request to the URL
|
||||||
:param data:
|
:param data:
|
||||||
|
:param user: a string
|
||||||
|
:param password: a string
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.post(url=url, data=data, auth=(user, pwd))
|
||||||
print("POST:" + str(r.status_code))
|
print("POST:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
#makes a PUT (overwrites instance) request to given url, returns dict
|
#makes a PUT (overwrites instance) request to given url, returns dict
|
||||||
def putDB(data, url):
|
def putDB(user, pwd, data, url):
|
||||||
"""
|
"""
|
||||||
Sends a PUT request to the URL
|
Sends a PUT request to the URL
|
||||||
:param data:
|
:param user: a string
|
||||||
|
:param password: a string
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.put(url=url, data=data, auth=(user, pwd))
|
||||||
print("PUT:" + str(r.status_code))
|
print("PUT:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
#makes a DELETE (delete instance) request to given url, returns dict
|
#makes a DELETE (delete instance) request to given url, returns dict
|
||||||
def delDB(url):
|
def delDB(user, pwd, url):
|
||||||
"""
|
"""
|
||||||
Sends a DELETE request to the URL
|
Sends a DELETE request to the URL
|
||||||
|
:param user: a string
|
||||||
|
:param password: a string
|
||||||
:param url: URL for request
|
:param url: URL for request
|
||||||
"""
|
"""
|
||||||
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.delete(url=url, auth=(user, pwd))
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -123,7 +134,7 @@ def command(command):
|
||||||
|
|
||||||
# public methods: deleteClass, makeClass, update
|
# public methods: deleteClass, makeClass, update
|
||||||
class Teacher:
|
class Teacher:
|
||||||
def __init__(self, data):
|
def __init__(self, data, password):
|
||||||
# teacher info already stored in API
|
# teacher info already stored in API
|
||||||
# intitialze fields after GET request
|
# intitialze fields after GET request
|
||||||
"""
|
"""
|
||||||
|
@ -134,6 +145,7 @@ class Teacher:
|
||||||
self.username = data['ion_user']
|
self.username = data['ion_user']
|
||||||
self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
|
self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
|
||||||
self.id = data['user']
|
self.id = data['user']
|
||||||
|
self.password = password
|
||||||
# classes in id form (Example: 4,5)
|
# classes in id form (Example: 4,5)
|
||||||
|
|
||||||
# array
|
# array
|
||||||
|
@ -218,15 +230,22 @@ class Teacher:
|
||||||
return
|
return
|
||||||
if self.checkClass(path):
|
if self.checkClass(path):
|
||||||
cpath = self.username + "/" + cname
|
cpath = self.username + "/" + cname
|
||||||
|
subject = cname.split("_")[0]
|
||||||
|
period = int(input("Enter period: "))
|
||||||
|
while(not (type(period) is int and period >= 0)):
|
||||||
|
print("Incorrect format")
|
||||||
|
period = int(input("Enter period: "))
|
||||||
data = {
|
data = {
|
||||||
"name": cname,
|
"name": cname,
|
||||||
"repo": "",
|
"repo": "",
|
||||||
"path": cpath,
|
"path": cpath,
|
||||||
|
"subject": subject,
|
||||||
|
"period":period,
|
||||||
"teacher": self.username,
|
"teacher": self.username,
|
||||||
"owner": self.id
|
"owner": self.id
|
||||||
}
|
}
|
||||||
# make class instance in db
|
# make class instance in db
|
||||||
postDB(data, 'http://127.0.0.1:8000/api/classes/')
|
postDB(self.username, self.password, data, 'http://127.0.0.1:8000/api/classes/')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.classes.append(cname)
|
self.classes.append(cname)
|
||||||
# add to instance
|
# add to instance
|
||||||
|
@ -235,7 +254,7 @@ class Teacher:
|
||||||
'classes': self.classes
|
'classes': self.classes
|
||||||
}
|
}
|
||||||
print(self.classes)
|
print(self.classes)
|
||||||
print(patchDB(data, 'http://127.0.0.1:8000/api/teachers/' + self.username + "/"))
|
print(patchDB(self.username, self.password, data, 'http://127.0.0.1:8000/api/teachers/' + self.username + "/"))
|
||||||
|
|
||||||
# make a new class from scratch
|
# make a new class from scratch
|
||||||
# subject: string, assignments: list
|
# subject: string, assignments: list
|
||||||
|
@ -248,7 +267,7 @@ class Teacher:
|
||||||
# check if class exists
|
# check if class exists
|
||||||
path = self.username + "/" + cname
|
path = self.username + "/" + cname
|
||||||
isclass = False
|
isclass = False
|
||||||
acourses = getDB("http://127.0.0.1:8000/api/classes/")['results']
|
acourses = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/")['results']
|
||||||
for c in acourses:
|
for c in acourses:
|
||||||
if c['name'] == cname:
|
if c['name'] == cname:
|
||||||
isclass = True
|
isclass = True
|
||||||
|
@ -300,7 +319,7 @@ class Teacher:
|
||||||
# 'classes':self.classes,
|
# 'classes':self.classes,
|
||||||
# }
|
# }
|
||||||
# print(patchDB(data, self.url))
|
# print(patchDB(data, self.url))
|
||||||
delDB("http://127.0.0.1:8000/api/classes/" + cname + "/")
|
delDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname + "/")
|
||||||
break
|
break
|
||||||
|
|
||||||
# remove locally
|
# remove locally
|
||||||
|
@ -318,7 +337,7 @@ class Teacher:
|
||||||
:return: True if student exists, False otherwise
|
:return: True if student exists, False otherwise
|
||||||
"""
|
"""
|
||||||
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
|
r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/",
|
||||||
auth=('raffukhondaker', 'hackgroup1'))
|
auth=(self.username, self.password))
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -333,7 +352,7 @@ class Teacher:
|
||||||
if not self.isStudent(sname):
|
if not self.isStudent(sname):
|
||||||
print(sname + " does not exist.")
|
print(sname + " does not exist.")
|
||||||
return False
|
return False
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname)
|
||||||
if sname in str(course['unconfirmed']):
|
if sname in str(course['unconfirmed']):
|
||||||
print(sname + " already requested.")
|
print(sname + " already requested.")
|
||||||
return True
|
return True
|
||||||
|
@ -341,7 +360,7 @@ class Teacher:
|
||||||
print(sname + " already enrolled.")
|
print(sname + " already enrolled.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
|
student = getDB(self.username, self.password, "http://127.0.0.1:8000/api/students/" + sname)
|
||||||
try:
|
try:
|
||||||
if student['added_to'] == "":
|
if student['added_to'] == "":
|
||||||
student['added_to'] = course['name']
|
student['added_to'] = course['name']
|
||||||
|
@ -354,8 +373,8 @@ class Teacher:
|
||||||
data = {
|
data = {
|
||||||
'added_to': student['added_to'],
|
'added_to': student['added_to'],
|
||||||
}
|
}
|
||||||
student = patchDB(data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
|
student = patchDB(self.username, self.password, data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
|
||||||
student = getDB("http://localhost:8000/api/students/" + sname + "/")
|
student = getDB(self.username, self.password, "http://localhost:8000/api/students/" + sname + "/")
|
||||||
if not course['unconfirmed']:
|
if not course['unconfirmed']:
|
||||||
course['unconfirmed'] = student['ion_user']
|
course['unconfirmed'] = student['ion_user']
|
||||||
else:
|
else:
|
||||||
|
@ -364,7 +383,7 @@ class Teacher:
|
||||||
"unconfirmed": course['unconfirmed']
|
"unconfirmed": course['unconfirmed']
|
||||||
}
|
}
|
||||||
print(cinfo)
|
print(cinfo)
|
||||||
patchDB(cinfo, "http://localhost:8000/api/classes/" + course['name'] + "/")
|
patchDB(self.username, self.password, cinfo, "http://localhost:8000/api/classes/" + course['name'] + "/")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Student should have confirmed on their endd, but class had not been updated yet
|
# Student should have confirmed on their endd, but class had not been updated yet
|
||||||
|
@ -380,8 +399,8 @@ class Teacher:
|
||||||
print(sname + " does not exist.")
|
print(sname + " does not exist.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
|
student = getDB(self.username, self.password, "http://127.0.0.1:8000/api/students/" + sname)
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + cname)
|
||||||
|
|
||||||
if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (
|
if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (
|
||||||
student['ion_user'] in course['confirmed']) == True):
|
student['ion_user'] in course['confirmed']) == True):
|
||||||
|
@ -435,7 +454,7 @@ class Teacher:
|
||||||
"confirmed": course["confirmed"],
|
"confirmed": course["confirmed"],
|
||||||
"unconfirmed": course['unconfirmed']
|
"unconfirmed": course['unconfirmed']
|
||||||
}
|
}
|
||||||
print(putDB(course, "http://localhost:8000/api/classes/" + course['name'] + "/"))
|
print(putDB(self.username, self.password, course, "http://localhost:8000/api/classes/" + course['name'] + "/"))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# goes through list of studennts, tries to add, then request, return unconfirmed students
|
# goes through list of studennts, tries to add, then request, return unconfirmed students
|
||||||
|
@ -494,7 +513,7 @@ class Teacher:
|
||||||
print("Due-date format is incorrect")
|
print("Due-date format is incorrect")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
if aname in str(course['assignments']):
|
if aname in str(course['assignments']):
|
||||||
print("Assignment name already taken.")
|
print("Assignment name already taken.")
|
||||||
return False
|
return False
|
||||||
|
@ -525,22 +544,23 @@ class Teacher:
|
||||||
print(st + " already has assignment")
|
print(st + " already has assignment")
|
||||||
|
|
||||||
# check if assignment already exists
|
# check if assignment already exists
|
||||||
r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker', 'hackgroup1'))
|
r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=(self.username, self.password))
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
ass = {
|
ass = {
|
||||||
'name': oname,
|
'name': oname,
|
||||||
'path': path,
|
'path': path,
|
||||||
'classes': course['name'],
|
'classes': course['name'],
|
||||||
'teacher': self.username,
|
'teacher': self.username,
|
||||||
'due_date': due
|
'due_date': due,
|
||||||
|
'owner':self.id
|
||||||
}
|
}
|
||||||
postDB(ass, 'http://127.0.0.1:8000/api/assignments/')
|
postDB(self.username, self.password, ass, 'http://127.0.0.1:8000/api/assignments/')
|
||||||
course['assignments'].append(oname)
|
course['assignments'].append(oname)
|
||||||
|
|
||||||
cinfo = {
|
cinfo = {
|
||||||
"assignments": course['assignments'],
|
"assignments": course['assignments'],
|
||||||
}
|
}
|
||||||
print(patchDB(cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/"))
|
print(patchDB(self.username, self.password, cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/"))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print("Assignment already addedd")
|
print("Assignment already addedd")
|
||||||
|
@ -561,12 +581,12 @@ class Teacher:
|
||||||
d = {
|
d = {
|
||||||
'due_date': due,
|
'due_date': due,
|
||||||
}
|
}
|
||||||
print(patchDB(d, 'http://localhost:8000/api/assignments/' + oname + "/"))
|
print(patchDB(self.username, self.password, d, 'http://localhost:8000/api/assignments/' + oname + "/"))
|
||||||
print("Due-date changed " + due)
|
print("Due-date changed " + due)
|
||||||
except:
|
except:
|
||||||
print("Due-date is the same")
|
print("Due-date is the same")
|
||||||
input()
|
input()
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
|
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
for st in slist:
|
for st in slist:
|
||||||
|
@ -597,7 +617,7 @@ class Teacher:
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
|
||||||
def getCommits(self, student, course, commits):
|
def getCommits(self, student, course, commits):
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
try:
|
try:
|
||||||
if not (student in course['confirmed']):
|
if not (student in course['confirmed']):
|
||||||
print("Student not in class")
|
print("Student not in class")
|
||||||
|
@ -645,7 +665,7 @@ class Teacher:
|
||||||
:param course: the course
|
:param course: the course
|
||||||
:param commits: commits the CLI has made for the assignment
|
:param commits: commits the CLI has made for the assignment
|
||||||
"""
|
"""
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course + "/")
|
course = getDB(self.username, self.password, "http://127.0.0.1:8000/api/classes/" + course + "/")
|
||||||
ar = self.getCommits(student, course['name'], commits)
|
ar = self.getCommits(student, course['name'], commits)
|
||||||
commit = ar[len(ar) - 1][0]
|
commit = ar[len(ar) - 1][0]
|
||||||
start = ""
|
start = ""
|
||||||
|
@ -670,7 +690,7 @@ class Teacher:
|
||||||
|
|
||||||
def afterSubmit(self, course, assignment, student):
|
def afterSubmit(self, course, assignment, student):
|
||||||
|
|
||||||
assignment = getDB("http://127.0.0.1:8000/api/assignments/" + assignment)
|
assignment = getDB(self.username, self.password, "http://127.0.0.1:8000/api/assignments/" + assignment)
|
||||||
# assignment = {
|
# assignment = {
|
||||||
# 'name': assignment,
|
# 'name': assignment,
|
||||||
# 'due_date': "2020-04-11 16:58:33.383124",
|
# 'due_date': "2020-04-11 16:58:33.383124",
|
||||||
|
@ -705,8 +725,9 @@ class Teacher:
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
|
|
||||||
# data = getTeacher("eharris1")
|
# data = getTeacher("eharris1","PWD")
|
||||||
# t = Teacher(data)
|
# print(data)
|
||||||
|
# t = Teacher(data, "PWD")
|
||||||
# t.makeClass("APLit_eharris1")
|
# t.makeClass("APLit_eharris1")
|
||||||
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||||
# ar = ['2022rkhondak','2022inafi','2023rumareti']
|
# ar = ['2022rkhondak','2022inafi','2023rumareti']
|
||||||
|
|
|
@ -3,50 +3,51 @@ from django.contrib.auth.models import User
|
||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Student(models.Model):
|
class Student(models.Model):
|
||||||
user = models.OneToOneField(User, blank=True, on_delete=models.CASCADE)
|
user = models.OneToOneField(User, blank=True, on_delete=models.CASCADE)
|
||||||
ion_user = models.CharField(max_length=100, primary_key=True)
|
ion_user = models.CharField(max_length=100, primary_key=True)
|
||||||
grade = models.IntegerField(default=0, blank=True)
|
grade = models.IntegerField(default=0, blank=True)
|
||||||
git = models.CharField(default="", max_length=100, blank=True)
|
git=models.CharField(default="", max_length=100, blank=True)
|
||||||
repo = models.URLField(default="", blank=True)
|
repo=models.URLField(default="", blank=True)
|
||||||
classes = models.CharField(max_length=100, default="", blank=True)
|
classes=models.CharField(max_length=100, default="", blank=True)
|
||||||
added_to = models.CharField(max_length=100, default="", blank=True)
|
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||||
completed = models.TextField(default="", blank=True)
|
completed=models.TextField(default="", blank=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Student, self).save(*args, **kwargs)
|
super(Student, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.user.username}'s Profile"
|
return f"{self.user.first_name} {self.user.last_name} ({self.user.username})"
|
||||||
|
|
||||||
|
|
||||||
class Assignment(models.Model):
|
class Assignment(models.Model):
|
||||||
owner = models.ForeignKey(User, null=True, blank=True, related_name='aowner', on_delete=models.CASCADE)
|
owner = models.ForeignKey(User, null=True, blank=True, related_name='aowner', on_delete=models.CASCADE)
|
||||||
|
name=models.CharField(max_length=100, primary_key=True)
|
||||||
name = models.CharField(max_length=100, primary_key=True)
|
due_date=models.DateTimeField()
|
||||||
due_date = models.DateTimeField()
|
|
||||||
# files = models.ManyToManyField(DefFiles)
|
# files = models.ManyToManyField(DefFiles)
|
||||||
files = models.CharField(max_length=100, default="", blank=True)
|
files=models.CharField(max_length=100, default="", blank=True)
|
||||||
path = models.CharField(max_length=100)
|
path=models.CharField(max_length=100, default="", blank=True)
|
||||||
classes = models.CharField(max_length=100)
|
classes=models.CharField(max_length=100, default="", blank=True)
|
||||||
teacher = models.CharField(max_length=100)
|
teacher=models.CharField(max_length=100, default="", blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s' % (self.name)
|
return f'{self.name}'
|
||||||
|
|
||||||
|
|
||||||
class Class(models.Model):
|
class Class(models.Model):
|
||||||
owner = models.ForeignKey(User, null=True, blank=True, related_name='cowner', on_delete=models.CASCADE)
|
owner = models.ForeignKey(User, null=True, blank=True, related_name='cowner', on_delete=models.CASCADE)
|
||||||
teacher = models.CharField(max_length=100)
|
teacher = models.CharField(max_length=100, blank=True)
|
||||||
|
subject = models.CharField(max_length=50, blank=True)
|
||||||
|
period = models.PositiveIntegerField(null=True, blank=True, default=0)
|
||||||
name = models.CharField(primary_key=True, max_length=100)
|
name = models.CharField(primary_key=True, max_length=100)
|
||||||
id = models.CharField(max_length=8, blank=True, null=True)
|
id = models.CharField(max_length=8, blank=True, null=True)
|
||||||
description = models.CharField(default="Class Description", max_length=500)
|
description = models.CharField(default="Class Description", max_length=500, blank=True)
|
||||||
repo = models.URLField(default="", blank=True)
|
repo=models.URLField(default="", blank=True)
|
||||||
path = models.CharField(max_length=100, default="")
|
path=models.CharField(max_length=100, default="", blank=True)
|
||||||
assignments = models.ManyToManyField(Assignment, blank=True)
|
assignments=models.ManyToManyField(Assignment, blank=True)
|
||||||
default_file = models.CharField(max_length=100, default="", blank=True)
|
default_file=models.CharField(max_length=100, default="", blank=True)
|
||||||
confirmed = models.ManyToManyField(Student, blank=True, related_name='confirmed')
|
confirmed=models.ManyToManyField(Student, blank=True, related_name='confirmed')
|
||||||
unconfirmed = models.ManyToManyField(Student, blank=True, related_name='unconfirmed')
|
unconfirmed=models.ManyToManyField(Student, blank=True, related_name='unconfirmed')
|
||||||
|
|
||||||
# assignments = models.ManyToManyField(Assignment, default="")
|
# assignments = models.ManyToManyField(Assignment, default="")
|
||||||
# default_file = models.ManyToManyField(DefFiles)
|
# default_file = models.ManyToManyField(DefFiles)
|
||||||
|
@ -60,22 +61,20 @@ class Class(models.Model):
|
||||||
return super(Class, self).save(*args, **kwargs)
|
return super(Class, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return f"{self.name}"
|
||||||
|
|
||||||
|
|
||||||
class Teacher(models.Model):
|
class Teacher(models.Model):
|
||||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
classes = models.ManyToManyField(Class, blank=True, related_name='classes')
|
classes=models.ManyToManyField(Class, blank=True, related_name='classes')
|
||||||
git = models.CharField(max_length=100, default="", blank=True)
|
git=models.CharField(max_length=100, default="", blank=True)
|
||||||
ion_user = models.CharField(primary_key=True, max_length=100)
|
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.user.username}'s Profile"
|
return f"{self.user.first_name} {self.user.last_name} ({self.user.username})"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Teacher, self).save(*args, **kwargs)
|
super(Teacher, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# class Student(models.Model):
|
# class Student(models.Model):
|
||||||
# user = models.OneToOneField(User, on_delete=models.CASCADE)
|
# user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
# ion_user=models.CharField(primary_key=True, max_length=100)
|
# ion_user=models.CharField(primary_key=True, max_length=100)
|
||||||
|
@ -88,8 +87,8 @@ class Teacher(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class DefFiles(models.Model):
|
class DefFiles(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name=models.CharField(max_length=100)
|
||||||
path = models.CharField(max_length=100)
|
path=models.CharField(max_length=100)
|
||||||
assignment = models.CharField(max_length=100, default="")
|
assignment=models.CharField(max_length=100, default="")
|
||||||
classes = models.CharField(max_length=100)
|
classes=models.CharField(max_length=100)
|
||||||
teacher = models.CharField(max_length=100)
|
teacher=models.CharField(max_length=100)
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ClassSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Class
|
model = Class
|
||||||
# fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
|
# fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
|
||||||
fields = ['name', 'repo','path','assignments',"teacher","default_file", 'confirmed', 'unconfirmed','owner']
|
fields = ['name', 'repo','path','subject','period','assignments',"teacher","default_file", 'confirmed', 'unconfirmed','owner']
|
||||||
|
|
||||||
class StudentSerializer(serializers.ModelSerializer):
|
class StudentSerializer(serializers.ModelSerializer):
|
||||||
# Class = ClassSerializer(many=True, read_only=True,allow_null=True)
|
# Class = ClassSerializer(many=True, read_only=True,allow_null=True)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from api.models import Student, Teacher
|
from api.models import Student, Teacher, Class, Assignment
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class UserUpdateForm(forms.ModelForm):
|
class UserUpdateForm(forms.ModelForm):
|
||||||
|
@ -26,3 +26,47 @@ class TeacherUpdateForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Teacher
|
model = Teacher
|
||||||
fields = ['git']
|
fields = ['git']
|
||||||
|
|
||||||
|
class ClassCreationForm (forms.ModelForm):
|
||||||
|
subject = forms.CharField(max_length=50)
|
||||||
|
period = forms.IntegerField(min_value=0, max_value=9)
|
||||||
|
description = forms.CharField(widget=forms.Textarea)
|
||||||
|
unconfirmed = forms.ModelMultipleChoiceField(queryset=Student.objects.all(), label="Invite students")
|
||||||
|
|
||||||
|
|
||||||
|
def clean_period(self):
|
||||||
|
pd = self.cleaned_data['period']
|
||||||
|
if pd < 1 or pd > 9:
|
||||||
|
raise forms.ValidationError("Invalid period")
|
||||||
|
return pd;
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ClassCreationForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['period'].widget.attrs['min'] = 0
|
||||||
|
# Only in case we build the form from an instance
|
||||||
|
# (otherwise, 'unconfirmed' list should be empty)
|
||||||
|
if kwargs.get('instance'):
|
||||||
|
# We get the 'initial' keyword argument or initialize it
|
||||||
|
# as a dict if it didn't exist.
|
||||||
|
initial = kwargs.setdefault('initial', {})
|
||||||
|
# The widget for a ModelMultipleChoiceField expects
|
||||||
|
# a list of primary key for the selected data.
|
||||||
|
initial['unconfirmed'] = [t.pk for t in kwargs['instance'].unconfirmed.all()]
|
||||||
|
|
||||||
|
# Overriding save allows us to process the value of 'unconfirmed' field
|
||||||
|
def save(self, username=""):
|
||||||
|
cleaned_data = self.cleaned_data
|
||||||
|
print(self)
|
||||||
|
|
||||||
|
# Get the unsave Class instance
|
||||||
|
instance = forms.ModelForm.save(self)
|
||||||
|
instance.unconfirmed.clear()
|
||||||
|
instance.unconfirmed.add(*cleaned_data['unconfirmed'])
|
||||||
|
instance.name = cleaned_data['subject'] + str(cleaned_data['period']) + "_" + username
|
||||||
|
print("Class name: " + instance.name)
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Class
|
||||||
|
fields = ['subject', 'period', 'description', 'unconfirmed']
|
||||||
|
|
|
@ -34,6 +34,12 @@
|
||||||
<!-- Navbar Right Side -->
|
<!-- Navbar Right Side -->
|
||||||
<div class="navbar-nav">
|
<div class="navbar-nav">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
{% if isTeacher %}
|
||||||
|
<a class="nav-item nav-link" href="{% url 'create-assignment' %}">Create Assignment</a>
|
||||||
|
<a class="nav-item nav-link" href="{% url 'create-class' %}">Create Class</a>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
<a class="nav-item nav-link" href="{% url 'profile' %}">{{ user.username }}</a>
|
<a class="nav-item nav-link" href="{% url 'profile' %}">{{ user.username }}</a>
|
||||||
<a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
|
<a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -11,6 +11,12 @@
|
||||||
<small class="text-muted">Due: {{ assignment.due_date|date:"F d, Y" }}</small>
|
<small class="text-muted">Due: {{ assignment.due_date|date:"F d, Y" }}</small>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
{% empty %}
|
||||||
|
{% if isTeacher %}
|
||||||
|
<p class="mr-2">Looks like you haven't made any assignments yet, hit the button in the top right to get started</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="mr-2">Looks like there aren't any assignments at the moment, you got lucky this time!</p>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -20,6 +26,8 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for teacher in teachers %}
|
{% for teacher in teachers %}
|
||||||
<li>{{ teacher.user.first_name }} {{ teacher.user.last_name }} ({{teacher.ion_user}})</li>
|
<li>{{ teacher.user.first_name }} {{ teacher.user.last_name }} ({{teacher.ion_user}})</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>No Teachers, weird...</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
26
Website/skoolos/templates/skoolos/createClass.html
Normal file
26
Website/skoolos/templates/skoolos/createClass.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{% extends "skoolos/base.html" %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% block content %}
|
||||||
|
<legend class="border-bottom mb-4">Classes</legend>
|
||||||
|
<ul>
|
||||||
|
{% for class in classes %}
|
||||||
|
<li>{{ class.name }}</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>Not teaching any classes</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset class="form-group">
|
||||||
|
<legend class="border-bottom mb-4"> Create a new class </legend>
|
||||||
|
{{ classForm|crispy }}
|
||||||
|
<!-- mmmm crispy yummm -->
|
||||||
|
<small class="text-secondary">Use ctrl to select multiple students</small>
|
||||||
|
</fieldset>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-outline-info">Create</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
|
@ -10,6 +10,12 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% empty %}
|
||||||
|
{% if isTeacher %}
|
||||||
|
<p>Looks like you haven't created any classes yet, hit the button in the top right to get started.</p>
|
||||||
|
{% else %}
|
||||||
|
<p>Looks like you're not enrolled in any classes at the moment! Ask your teacher if you think this is wrong.</p>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<div class="media">
|
<div class="media">
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
<h2 class="account-heading">{{ user.username }}</h2>
|
<h2 class="account-heading">{{ user.username }}</h2>
|
||||||
|
<p class="text-secondary">Student</p>
|
||||||
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
||||||
<p class="text-secondary">
|
<p class="text-secondary">
|
||||||
{{ user.email }}
|
{{ user.email }}
|
||||||
|
@ -16,6 +17,8 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for class in classes %}
|
{% for class in classes %}
|
||||||
<li>{{ class.name }}</li>
|
<li>{{ class.name }}</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>No classes</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<div class="media">
|
<div class="media">
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
<h2 class="account-heading">{{ user.username }}</h2>
|
<h2 class="account-heading">{{ user.username }}</h2>
|
||||||
|
<p class="text-secondary">Teacher</p>
|
||||||
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
||||||
<p class="text-secondary">
|
<p class="text-secondary">
|
||||||
{{ user.email }}
|
{{ user.email }}
|
||||||
|
@ -16,6 +17,8 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for class in classes %}
|
{% for class in classes %}
|
||||||
<li>{{ class.name }}</li>
|
<li>{{ class.name }}</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>Not teaching any classes</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
|
|
@ -7,4 +7,6 @@ urlpatterns = [
|
||||||
path('', views.home, name='home'),
|
path('', views.home, name='home'),
|
||||||
path('profile/', views.profile, name='profile'),
|
path('profile/', views.profile, name='profile'),
|
||||||
path("class/<str:id>", views.classDetail, name="class"),
|
path("class/<str:id>", views.classDetail, name="class"),
|
||||||
|
path("create-class/", views.createClass, name="create-class"),
|
||||||
|
path("create-assignment/", views.createAssignment, name="create-assignment"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,7 +5,12 @@ from django.contrib import messages
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from .forms import UserUpdateForm, StudentUpdateForm, TeacherUpdateForm
|
from .forms import (
|
||||||
|
UserUpdateForm,
|
||||||
|
StudentUpdateForm,
|
||||||
|
TeacherUpdateForm,
|
||||||
|
ClassCreationForm,
|
||||||
|
)
|
||||||
|
|
||||||
from api.models import Student, Teacher, Class, Assignment
|
from api.models import Student, Teacher, Class, Assignment
|
||||||
|
|
||||||
|
@ -14,14 +19,14 @@ from api.models import Student, Teacher, Class, Assignment
|
||||||
@login_required()
|
@login_required()
|
||||||
def home (request):
|
def home (request):
|
||||||
try:
|
try:
|
||||||
student = Student.objects.get(user=request.user)
|
student = request.user.student
|
||||||
return render(request, "skoolos/home.html", {'classes': student.confirmed.all()})
|
return render(request, "skoolos/home.html", {'classes': student.confirmed.all(), 'isTeacher': False})
|
||||||
except Student.DoesNotExist:
|
except Student.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
teacher = Teacher.objects.get(user=request.user)
|
teacher = request.user.teacher
|
||||||
return render(request, "skoolos/home.html", {'classes': teacher.classes.all()})
|
return render(request, "skoolos/home.html", {'classes': teacher.classes.all(), 'isTeacher': True})
|
||||||
except Teacher.DoesNotExist:
|
except Teacher.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -36,38 +41,37 @@ def classDetail (request, id):
|
||||||
classObj = Class.objects.get(id=id)
|
classObj = Class.objects.get(id=id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
student = Student.objects.get(user=request.user)
|
student = request.user.student
|
||||||
except Student.DoesNotExist:
|
except Student.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if classObj.confirmed.filter(user=student.user).count() != 1:
|
if classObj.confirmed.filter(user=student.user).count() != 1:
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
else:
|
else:
|
||||||
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all()})
|
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all(), 'isTeacher': False})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
teacher = Teacher.objects.get(user=request.user)
|
teacher = request.user.teacher
|
||||||
return render(request, "skoolos/home.html", {'classes': teacher.classes.all()})
|
|
||||||
except Teacher.DoesNotExist:
|
except Teacher.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if classObj.confirmed.filter(user=student.user).count() != 1:
|
if teacher.classes.filter(id=classObj.id).count() != 1:
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
else:
|
else:
|
||||||
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all()})
|
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all(), 'isTeacher': True})
|
||||||
|
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def profile (request):
|
def profile (request):
|
||||||
try:
|
try:
|
||||||
student = Student.objects.get(user=request.user)
|
student = request.user.student
|
||||||
return student_profile(request)
|
return student_profile(request)
|
||||||
except Student.DoesNotExist:
|
except Student.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
teacher = Teacher.objects.get(user=request.user)
|
teacher = request.user.teacher
|
||||||
return teacher_profile(request)
|
return teacher_profile(request)
|
||||||
except Teacher.DoesNotExist:
|
except Teacher.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
@ -91,7 +95,8 @@ def student_profile (request):
|
||||||
context = {
|
context = {
|
||||||
'userForm': userForm,
|
'userForm': userForm,
|
||||||
'profileForm': profileForm,
|
'profileForm': profileForm,
|
||||||
'classes': request.user.student.confirmed.all()
|
'classes': request.user.student.confirmed.all(),
|
||||||
|
'isTeacher': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'skoolos/profile_student.html', context)
|
return render(request, 'skoolos/profile_student.html', context)
|
||||||
|
@ -113,7 +118,46 @@ def teacher_profile (request):
|
||||||
context = {
|
context = {
|
||||||
'userForm': userForm,
|
'userForm': userForm,
|
||||||
'profileForm': profileForm,
|
'profileForm': profileForm,
|
||||||
'classes': request.user.teacher.classes.all()
|
'classes': request.user.teacher.classes.all(),
|
||||||
|
'isTeacher': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'skoolos/profile_teacher.html', context)
|
return render(request, 'skoolos/profile_teacher.html', context)
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def createClass (request):
|
||||||
|
try:
|
||||||
|
teacher = request.user.teacher
|
||||||
|
except Teacher.DoesNotExist:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return createClassHelper(request)
|
||||||
|
|
||||||
|
return redirect('/')
|
||||||
|
|
||||||
|
def createClassHelper(request):
|
||||||
|
teacher = request.user.teacher
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
classForm = ClassCreationForm(request.POST)
|
||||||
|
if classForm.is_valid():
|
||||||
|
cleaned_data = classForm.clean()
|
||||||
|
print(cleaned_data)
|
||||||
|
classForm.save(username=teacher.user.username)
|
||||||
|
messages.success(request, cleaned_data['subject'].capitalize() + " has been created!")
|
||||||
|
return redirect('home')
|
||||||
|
else:
|
||||||
|
classForm = ClassCreationForm()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'teacher': teacher,
|
||||||
|
'classes': teacher.classes.all(),
|
||||||
|
'classForm': classForm
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, "skoolos/createClass.html", context)
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def createAssignment (request):
|
||||||
|
pass
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
||||||
kskskksks
|
|
229
skoolos.py
229
skoolos.py
|
@ -40,7 +40,9 @@ def main():
|
||||||
print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝ ░╚════╝░╚═════╝░")
|
print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝ ░╚════╝░╚═════╝░")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")):
|
profiles = os.listdir()
|
||||||
|
|
||||||
|
if not ("profile" in str(profiles)):
|
||||||
try:
|
try:
|
||||||
URL = "http://127.0.0.1:8000/api/"
|
URL = "http://127.0.0.1:8000/api/"
|
||||||
r = requests.get(url=URL)
|
r = requests.get(url=URL)
|
||||||
|
@ -65,6 +67,7 @@ def main():
|
||||||
info.append(d)
|
info.append(d)
|
||||||
users.append(str(count) + ") " + d['username'])
|
users.append(str(count) + ") " + d['username'])
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
users.append(str(count) + ") Make new user")
|
||||||
user = [
|
user = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
|
@ -74,6 +77,9 @@ def main():
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
u = int(prompt(user)['user'].split(")")[0]) - 1
|
u = int(prompt(user)['user'].split(")")[0]) - 1
|
||||||
|
if(u+1 == count):
|
||||||
|
authenticate()
|
||||||
|
return
|
||||||
data = info[u]
|
data = info[u]
|
||||||
PWD = data['password']
|
PWD = data['password']
|
||||||
USER = data['username']
|
USER = data['username']
|
||||||
|
@ -83,8 +89,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
teacherCLI(USER, PWD)
|
teacherCLI(USER, PWD)
|
||||||
|
|
||||||
|
#################################################################################################### STUDENT METHODS
|
||||||
################################################ STUDENT METHODS
|
|
||||||
|
|
||||||
def studentCLI(user, password):
|
def studentCLI(user, password):
|
||||||
"""
|
"""
|
||||||
|
@ -94,11 +99,13 @@ def studentCLI(user, password):
|
||||||
"""
|
"""
|
||||||
from CLI import student
|
from CLI import student
|
||||||
data = getUser(user, password, 'student')
|
data = getUser(user, password, 'student')
|
||||||
student = student.Student(data)
|
student = student.Student(data, password)
|
||||||
student.update()
|
student.update()
|
||||||
EXIT = False
|
EXIT = False
|
||||||
while not EXIT:
|
while not EXIT:
|
||||||
course = chooseClassStudent(student)
|
course = chooseClassStudent(student)
|
||||||
|
if(course == "Exit SkoolOS"):
|
||||||
|
return
|
||||||
EXIT = classOptionsStudent(student, course)
|
EXIT = classOptionsStudent(student, course)
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,7 +169,7 @@ def classOptionsStudent(student, course):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
################################################ TEACHER METHODS
|
#################################################################################################### TEACHER METHODS
|
||||||
def teacherCLI(user, password):
|
def teacherCLI(user, password):
|
||||||
from CLI import teacher
|
from CLI import teacher
|
||||||
data = getUser(user, password, 'teacher')
|
data = getUser(user, password, 'teacher')
|
||||||
|
@ -174,26 +181,25 @@ def teacherCLI(user, password):
|
||||||
# 3. Get progress logs on a student
|
# 3. Get progress logs on a student
|
||||||
# 2. make an assignment for a class
|
# 2. make an assignment for a class
|
||||||
# 3. view student submissions for an assignment
|
# 3. view student submissions for an assignment
|
||||||
while (not EXIT):
|
while(not EXIT):
|
||||||
# Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
#Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"
|
||||||
course = chooseGeneralTeacher(teacher)
|
course = chooseGeneralTeacher(teacher)
|
||||||
if course == "Exit SkoolOS":
|
if course == "Exit SkoolOS":
|
||||||
EXIT = True
|
EXIT = True
|
||||||
elif course == "Make New Class":
|
elif course == "Make New Class":
|
||||||
EXIT = makeClassTeacher(teacher)
|
EXIT = makeClassTeacher(teacher)
|
||||||
# selected a class
|
#selected a class
|
||||||
else:
|
else:
|
||||||
option = classOptionsTeacher(teacher, course)
|
option = classOptionsTeacher(teacher, course)
|
||||||
if (option == '1'):
|
if(option == '1'):
|
||||||
EXIT = addStudentsTeacher(teacher, course)
|
EXIT = addStudentsTeacher(teacher, course)
|
||||||
elif (option == '2'):
|
elif(option == '2'):
|
||||||
EXIT = addAssignmentTeacher(teacher, course)
|
EXIT = addAssignmentTeacher(teacher, course)
|
||||||
elif (option == '3'):
|
elif(option == '3'):
|
||||||
EXIT = viewStudentsTeacher(teacher, course)
|
EXIT = viewStudentsTeacher(teacher, course)
|
||||||
else:
|
else:
|
||||||
EXIT = True
|
EXIT = True
|
||||||
|
|
||||||
|
|
||||||
def chooseGeneralTeacher(teacher):
|
def chooseGeneralTeacher(teacher):
|
||||||
carray = []
|
carray = []
|
||||||
for c in teacher.classes:
|
for c in teacher.classes:
|
||||||
|
@ -201,57 +207,56 @@ def chooseGeneralTeacher(teacher):
|
||||||
carray.append("Make New Class")
|
carray.append("Make New Class")
|
||||||
carray.append("Exit SkoolOS")
|
carray.append("Exit SkoolOS")
|
||||||
courses = [
|
courses = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices': carray,
|
'choices':carray,
|
||||||
'message': 'Select class: ',
|
'message': 'Select class: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
course = prompt(courses)['course']
|
course = prompt(courses)['course']
|
||||||
return course
|
return course
|
||||||
|
|
||||||
|
|
||||||
def makeClassTeacher(teacher):
|
def makeClassTeacher(teacher):
|
||||||
questions = [
|
questions = [
|
||||||
|
{
|
||||||
|
'type': 'input',
|
||||||
|
'name': 'cname',
|
||||||
|
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cname = prompt(questions)['cname']
|
||||||
|
print(cname)
|
||||||
|
while(not ("_" + teacher.username) in cname):
|
||||||
|
print("Incorrect naming format")
|
||||||
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
'name': 'cname',
|
'name': 'cname',
|
||||||
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
||||||
},
|
},
|
||||||
]
|
|
||||||
cname = prompt(questions)['cname']
|
|
||||||
print(cname)
|
|
||||||
while (not ("_" + teacher.username) in cname):
|
|
||||||
print("Incorrect naming format")
|
|
||||||
questions = [
|
|
||||||
{
|
|
||||||
'type': 'input',
|
|
||||||
'name': 'cname',
|
|
||||||
'message': 'Class Name (Must be: <subject>_<ion_user>): ',
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
cname = prompt(questions)['cname']
|
cname = prompt(questions)['cname']
|
||||||
|
|
||||||
teacher.makeClass(cname)
|
teacher.makeClass(cname)
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices': soption,
|
'choices':soption,
|
||||||
'name': 'students',
|
'name': 'students',
|
||||||
'message': 'Add Students): ',
|
'message': 'Add Students): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
choice = prompt(questions)['students'].split(")")[0]
|
choice = prompt(questions)['students'].split(")")[0]
|
||||||
if ("1" == choice):
|
if("1" == choice):
|
||||||
s = input("Student name: ")
|
s = input("Student name: ")
|
||||||
teacher.addStudent(s, cname)
|
teacher.addStudent(s, cname)
|
||||||
if ("2" == choice):
|
if("2" == choice):
|
||||||
print("File must be .txt and have 1 student username per line")
|
print("File must be .txt and have 1 student username per line")
|
||||||
path = input("Relative Path: ")
|
path = input("Relative Path: ")
|
||||||
while (not os.path.exists(path)):
|
while(not os.path.exists(path)):
|
||||||
if (path == 'N'):
|
if(path == 'N'):
|
||||||
return True
|
return True
|
||||||
print(path + " is not a valid path")
|
print(path + " is not a valid path")
|
||||||
path = input("Enter file path ('N' to exit): ")
|
path = input("Enter file path ('N' to exit): ")
|
||||||
|
@ -260,7 +265,6 @@ def makeClassTeacher(teacher):
|
||||||
teacher.reqAddStudentList(students, cname)
|
teacher.reqAddStudentList(students, cname)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def classOptionsTeacher(teacher, course):
|
def classOptionsTeacher(teacher, course):
|
||||||
print("Class: " + course)
|
print("Class: " + course)
|
||||||
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
|
||||||
|
@ -268,50 +272,49 @@ def classOptionsTeacher(teacher, course):
|
||||||
teacher.addStudent(s, course)
|
teacher.addStudent(s, course)
|
||||||
options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"]
|
options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"]
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'name': 'course',
|
'name': 'course',
|
||||||
'choices': options,
|
'choices':options,
|
||||||
'message': 'Select option: ',
|
'message': 'Select option: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
option = prompt(questions)['course'].split(")")[0]
|
option = prompt(questions)['course'].split(")")[0]
|
||||||
return option
|
return option
|
||||||
|
|
||||||
|
|
||||||
def addStudentsTeacher(teacher, course):
|
def addStudentsTeacher(teacher, course):
|
||||||
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices': soption,
|
'choices':soption,
|
||||||
'name': 'students',
|
'name': 'students',
|
||||||
'message': 'Add list of students (input path): ',
|
'message': 'Add list of students (input path): ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
schoice = prompt(questions)['students'].split(")")[0]
|
schoice = prompt(questions)['students'].split(")")[0]
|
||||||
if (schoice == '1'):
|
if(schoice == '1'):
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
'name': 'student',
|
'name': 'student',
|
||||||
'message': 'Student Name: ',
|
'message': 'Student Name: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
s = prompt(questions)['student']
|
s = prompt(questions)['student']
|
||||||
teacher.reqStudent(s, course)
|
teacher.reqStudent(s, course)
|
||||||
return False
|
return False
|
||||||
if (schoice == '2'):
|
if(schoice == '2'):
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'input',
|
'type': 'input',
|
||||||
'name': 'path',
|
'name': 'path',
|
||||||
'message': 'Path: ',
|
'message': 'Path: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
path = prompt(questions)['path']
|
path = prompt(questions)['path']
|
||||||
while (not os.path.exists(path)):
|
while(not os.path.exists(path)):
|
||||||
if (path == 'N'):
|
if(path == 'N'):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
print(path + " is not a valid path")
|
print(path + " is not a valid path")
|
||||||
path = input("Enter file path ('N' to exit): ")
|
path = input("Enter file path ('N' to exit): ")
|
||||||
|
@ -322,7 +325,6 @@ def addStudentsTeacher(teacher, course):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def addAssignmentTeacher(teacher, course):
|
def addAssignmentTeacher(teacher, course):
|
||||||
nlist = os.listdir(teacher.username + "/" + course)
|
nlist = os.listdir(teacher.username + "/" + course)
|
||||||
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
|
||||||
|
@ -332,36 +334,36 @@ def addAssignmentTeacher(teacher, course):
|
||||||
for n in nlist:
|
for n in nlist:
|
||||||
b = True
|
b = True
|
||||||
print(teacher.username + "/" + course + "/" + n)
|
print(teacher.username + "/" + course + "/" + n)
|
||||||
for a in alist:
|
for a in alist:
|
||||||
if (n in a or n == a):
|
if(n in a or n == a):
|
||||||
# print("Assignments: " + n)
|
#print("Assignments: " + n)
|
||||||
b = False
|
b = False
|
||||||
if (not os.path.isdir(teacher.username + "/" + course + "/" + n)):
|
if(not os.path.isdir(teacher.username + "/" + course + "/" + n)):
|
||||||
b = False
|
b = False
|
||||||
if (b):
|
if(b):
|
||||||
tlist.append(n)
|
tlist.append(n)
|
||||||
|
|
||||||
|
|
||||||
nlist = tlist
|
nlist = tlist
|
||||||
if (len(nlist) == 0):
|
if(len(nlist) == 0):
|
||||||
print("No new assignments found")
|
print("No new assignments found")
|
||||||
print(
|
print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
|
||||||
"To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder")
|
|
||||||
return False
|
return False
|
||||||
questions = [
|
questions = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'choices': nlist,
|
'choices':nlist,
|
||||||
'name': 'assignment',
|
'name': 'assignment',
|
||||||
'message': 'Select new assignment: ',
|
'message': 'Select new assignment: ',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
ass = prompt(questions)['assignment']
|
ass = prompt(questions)['assignment']
|
||||||
apath = teacher.username + "/" + course + "/" + ass
|
apath = teacher.username + "/" + course + "/" + ass
|
||||||
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||||
due = due + ":33.383124"
|
due = due + ":33.383124"
|
||||||
due = due.strip()
|
due = due.strip()
|
||||||
f = False
|
f = False
|
||||||
while (not f):
|
while(not f):
|
||||||
try:
|
try:
|
||||||
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
f = True
|
f = True
|
||||||
|
@ -369,11 +371,10 @@ def addAssignmentTeacher(teacher, course):
|
||||||
print("Due-date format is incorrect.")
|
print("Due-date format is incorrect.")
|
||||||
print(due)
|
print(due)
|
||||||
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
due = input("Enter due date (Example: 2020-08-11 16:58): ")
|
||||||
due = due + ":33.383124"
|
due = due + ":33.383124"
|
||||||
teacher.addAssignment(apath, course, due)
|
teacher.addAssignment(apath, course, due)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def viewStudentsTeacher(teacher, course):
|
def viewStudentsTeacher(teacher, course):
|
||||||
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
|
||||||
students = data["confirmed"]
|
students = data["confirmed"]
|
||||||
|
@ -385,7 +386,7 @@ def viewStudentsTeacher(teacher, course):
|
||||||
for s in unconf:
|
for s in unconf:
|
||||||
print(s)
|
print(s)
|
||||||
student = input("View student (Enter student's ion username): ")
|
student = input("View student (Enter student's ion username): ")
|
||||||
while ((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))):
|
while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))):
|
||||||
print("Student not affiliated with class")
|
print("Student not affiliated with class")
|
||||||
student = input("View student ('N' to exit): ")
|
student = input("View student ('N' to exit): ")
|
||||||
if student == 'N':
|
if student == 'N':
|
||||||
|
@ -393,7 +394,8 @@ def viewStudentsTeacher(teacher, course):
|
||||||
print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
|
print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
|
||||||
|
############################################################################################################################################
|
||||||
|
|
||||||
|
|
||||||
def getUser(ion_user, password, utype):
|
def getUser(ion_user, password, utype):
|
||||||
|
@ -408,6 +410,7 @@ def getUser(ion_user, password, utype):
|
||||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||||
else:
|
else:
|
||||||
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
|
||||||
|
print(URL)
|
||||||
r = requests.get(url=URL, auth=(ion_user, password))
|
r = requests.get(url=URL, auth=(ion_user, password))
|
||||||
print(r.json())
|
print(r.json())
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
|
@ -424,49 +427,32 @@ def getUser(ion_user, password, utype):
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def patchDB(USER, PWD, url, data):
|
||||||
def patchDB(data, url):
|
r = requests.patch(url = url, data=data, auth=(USER,PWD))
|
||||||
r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
|
||||||
print("PATH:" + str(r.status_code))
|
print("PATH:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def getDB(url):
|
def getDB(USER, PWD, url):
|
||||||
"""
|
r = requests.get(url = url, auth=(USER,PWD))
|
||||||
Sends a GET request to the URL
|
|
||||||
:param url: URL for request
|
|
||||||
"""
|
|
||||||
r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
|
||||||
print("GET:" + str(r.status_code))
|
print("GET:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def postDB(data, url):
|
def postDB(USER, PWD, url, data):
|
||||||
"""
|
r = requests.post(url = url, data=data, auth=(USER,PWD))
|
||||||
Sends a POST request to the URL
|
|
||||||
:param url: URL for request
|
|
||||||
"""
|
|
||||||
r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
|
||||||
print("POST:" + str(r.status_code))
|
print("POST:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def putDB(data, url):
|
def putDB(USER, PWD, url, data):
|
||||||
"""
|
r = requests.put(url = url, data=data, auth=(USER,PWD))
|
||||||
Sends a PUT request to the URL
|
|
||||||
:param url: URL for request
|
|
||||||
"""
|
|
||||||
r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1'))
|
|
||||||
print("PUT:" + str(r.status_code))
|
print("PUT:" + str(r.status_code))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def delDB(url):
|
def delDB(USER, PWD, url):
|
||||||
"""
|
r = requests.delete(url = url, auth=(USER,PWD))
|
||||||
Sends a DEL request to the URL
|
|
||||||
:param url: URL for request
|
|
||||||
"""
|
|
||||||
r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1'))
|
|
||||||
print("DELETE:" + str(r.status_code))
|
print("DELETE:" + str(r.status_code))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -514,10 +500,7 @@ def authenticate():
|
||||||
# Linux: chromdriver-linux
|
# Linux: chromdriver-linux
|
||||||
# Macos: chromdriver-mac
|
# Macos: chromdriver-mac
|
||||||
# Windows: chromdriver.exe
|
# Windows: chromdriver.exe
|
||||||
if 'CLI' in os.getcwd():
|
path = os.path.join(os.getcwd(),'chromedriver','chromedriver-mac')
|
||||||
path = os.path.join(os.getcwd(), '../', 'chromedriver-mac')
|
|
||||||
else:
|
|
||||||
path = os.path.join(os.getcwd(), 'chromedriver-mac')
|
|
||||||
|
|
||||||
browser = webdriver.Chrome(path)
|
browser = webdriver.Chrome(path)
|
||||||
|
|
||||||
|
@ -577,7 +560,8 @@ def authenticate():
|
||||||
'is_student': is_student,
|
'is_student': is_student,
|
||||||
'password': pwd,
|
'password': pwd,
|
||||||
}
|
}
|
||||||
profileFile = open(".sprofile", "w")
|
fname = "." + username + "profile"
|
||||||
|
profileFile = open(fname, "w")
|
||||||
profileFile.write(json.dumps(profile))
|
profileFile.write(json.dumps(profile))
|
||||||
profileFile.close()
|
profileFile.close()
|
||||||
|
|
||||||
|
@ -591,7 +575,8 @@ def authenticate():
|
||||||
'is_student': is_student,
|
'is_student': is_student,
|
||||||
'password': pwd,
|
'password': pwd,
|
||||||
}
|
}
|
||||||
profileFile = open(".tprofile", "w")
|
fname = "." + username + "profile"
|
||||||
|
profileFile = open(fname, "w")
|
||||||
profileFile.write(json.dumps(profile))
|
profileFile.write(json.dumps(profile))
|
||||||
profileFile.close()
|
profileFile.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user