mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
cli
This commit is contained in:
parent
52a88c6880
commit
f8fff8882b
118
CLI/teacher.py
118
CLI/teacher.py
|
@ -9,18 +9,18 @@ import time
|
||||||
import pyperclip
|
import pyperclip
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from django.conf import settings
|
# from django.conf import settings
|
||||||
import django
|
# import django
|
||||||
|
|
||||||
from Website.config.settings import DATABASES, INSTALLED_APPS
|
# from Website.config.settings import DATABASES, INSTALLED_APPS
|
||||||
INSTALLED_APPS.remove('users.apps.UsersConfig')
|
# INSTALLED_APPS.remove('users.apps.UsersConfig')
|
||||||
INSTALLED_APPS.remove('api')
|
# INSTALLED_APPS.remove('api')
|
||||||
INSTALLED_APPS.remove('skoolos.apps.SkoolosConfig')
|
# INSTALLED_APPS.remove('skoolos.apps.SkoolosConfig')
|
||||||
INSTALLED_APPS.append('Website.api')
|
# INSTALLED_APPS.append('Website.api')
|
||||||
settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
|
# settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
|
||||||
django.setup()
|
# django.setup()
|
||||||
|
|
||||||
from Website.api.models import *
|
# from ..Website.api.models import *
|
||||||
#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
|
||||||
|
@ -46,7 +46,7 @@ def getDB(url):
|
||||||
return(r.json())
|
return(r.json())
|
||||||
def patchDB(data, url):
|
def patchDB(data, url):
|
||||||
r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
||||||
print("PATH:" + str(r.status_code))
|
print("PATCH:" + str(r.status_code))
|
||||||
return(r.json())
|
return(r.json())
|
||||||
|
|
||||||
def postDB(data, url):
|
def postDB(data, url):
|
||||||
|
@ -150,29 +150,31 @@ class Teacher:
|
||||||
|
|
||||||
#make class from existing directory, add to git and api
|
#make class from existing directory, add to git and api
|
||||||
def addClass(self, path):
|
def addClass(self, path):
|
||||||
|
cname = path.split("/")
|
||||||
|
cname = cname[len(cname)-1]
|
||||||
|
for c in self.classes:
|
||||||
|
if c == cname:
|
||||||
|
print(cname + " already exists.")
|
||||||
|
return
|
||||||
if (self.checkClass(path)):
|
if (self.checkClass(path)):
|
||||||
cname = path.split("/")
|
|
||||||
cname = cname[len(cname)-1]
|
|
||||||
cpath = self.username + "/" + cname
|
cpath = self.username + "/" + cname
|
||||||
data = {
|
data = {
|
||||||
"name": cname,
|
"name": cname,
|
||||||
"repo": "",
|
"repo": "",
|
||||||
"path": cpath,
|
"path": cpath,
|
||||||
"teacher": self.username,
|
"teacher": self.username,
|
||||||
"assignments": "",
|
"owner":self.id
|
||||||
"default_file": "",
|
|
||||||
"confirmed": "",
|
|
||||||
"unconfirmed": ""
|
|
||||||
}
|
}
|
||||||
#make class instance in db
|
#make class instance in db
|
||||||
data = postDB(data, 'http://127.0.0.1:8000/api/classes/')
|
postDB(data, 'http://127.0.0.1:8000/api/classes/')
|
||||||
|
self.classes.append(cname)
|
||||||
#add to instance
|
#add to instance
|
||||||
#upate self.classes
|
#upate self.classes
|
||||||
self.classes.append(data)
|
|
||||||
data = {
|
data = {
|
||||||
'classes':self.classes
|
'classes':self.classes
|
||||||
}
|
}
|
||||||
patchDB(data, self.url)
|
print(self.username)
|
||||||
|
print(patchDB(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
|
||||||
|
@ -252,28 +254,28 @@ class Teacher:
|
||||||
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("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
|
||||||
if(sname in str(course['confirmed'])):
|
# if(sname in str(course['confirmed'])):
|
||||||
print (sname + " alredy enrolled.")
|
# print (sname + " alredy enrolled.")
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
student = getDB("http://127.0.0.1:8000/api/students/" + sname)
|
|
||||||
try:
|
|
||||||
if(student['added_to']==""):
|
|
||||||
student['added_to']=course['name']
|
|
||||||
else:
|
|
||||||
student['added_to']=student['added_to']+ "," + course['name']
|
|
||||||
except:
|
|
||||||
print(sname + " does not exist.")
|
|
||||||
return False
|
|
||||||
print(student['added_to'])
|
|
||||||
data={
|
|
||||||
'added_to':student['added_to'],
|
|
||||||
}
|
|
||||||
student = patchDB(data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
|
|
||||||
|
|
||||||
|
# student = getDB("http://127.0.0.1:8000/api/students/" + sname)
|
||||||
|
# try:
|
||||||
|
# if(student['added_to']==""):
|
||||||
|
# student['added_to']=course['name']
|
||||||
|
# else:
|
||||||
|
# student['added_to']=student['added_to']+ "," + course['name']
|
||||||
|
# except:
|
||||||
|
# print(sname + " does not exist.")
|
||||||
|
# return False
|
||||||
|
# print(student['added_to'])
|
||||||
|
# data={
|
||||||
|
# 'added_to':student['added_to'],
|
||||||
|
# }
|
||||||
|
# student = patchDB(data, "http://localhost:8000/api/students/" + student['ion_user'] + "/")
|
||||||
|
student = getDB( "http://localhost:8000/api/students/" + (sname)+ "/")
|
||||||
if(course['unconfirmed']==[]):
|
if(course['unconfirmed']==[]):
|
||||||
course['unconfirmed']=student['ion_user']
|
course['unconfirmed']=student['ion_user']
|
||||||
else:
|
else:
|
||||||
|
@ -281,7 +283,8 @@ class Teacher:
|
||||||
cinfo = {
|
cinfo = {
|
||||||
"unconfirmed": course['unconfirmed']
|
"unconfirmed": course['unconfirmed']
|
||||||
}
|
}
|
||||||
print(patchDB(cinfo, "http://localhost:8000/api/classes/" + course['name'] + "/"))
|
print(cinfo)
|
||||||
|
patchDB(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
|
||||||
|
@ -364,10 +367,10 @@ class Teacher:
|
||||||
parts = path.split("/")
|
parts = path.split("/")
|
||||||
aname = parts[len(parts)-1]
|
aname = parts[len(parts)-1]
|
||||||
|
|
||||||
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in self.sclass:
|
if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in str(self.classes):
|
||||||
print("Not valid path.")
|
print("Not valid path.")
|
||||||
return False
|
return False
|
||||||
if((parts[1] in self.sclass) == False):
|
if((parts[1] in str(self.classes)) == False):
|
||||||
print("Not in valid class directory")
|
print("Not in valid class directory")
|
||||||
return False
|
return False
|
||||||
#parts of assignment name (Essay1, APLit)
|
#parts of assignment name (Essay1, APLit)
|
||||||
|
@ -439,16 +442,9 @@ class Teacher:
|
||||||
course['assignments'] = course['assignments'].append(ass)
|
course['assignments'] = course['assignments'].append(ass)
|
||||||
|
|
||||||
cinfo = {
|
cinfo = {
|
||||||
"name": course['name'],
|
|
||||||
"repo": "",
|
|
||||||
"path": course['path'],
|
|
||||||
"teacher": "eharris1",
|
|
||||||
"assignments": course['assignments'],
|
"assignments": course['assignments'],
|
||||||
"default_file": "",
|
|
||||||
"confirmed": course["confirmed"],
|
|
||||||
"unconfirmed": course['unconfirmed']
|
|
||||||
}
|
}
|
||||||
putDB(cinfo, "http://127.0.0.1:8000/api/classes/" + course['name'] + "/")
|
patchDB(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")
|
||||||
|
@ -457,18 +453,22 @@ class Teacher:
|
||||||
#try to avoid
|
#try to avoid
|
||||||
#copy modified assignments to student directories
|
#copy modified assignments to student directories
|
||||||
def updateAssignment(self, path, course, due):
|
def updateAssignment(self, path, course, due):
|
||||||
|
parts = path.split("/")
|
||||||
|
aname = parts[len(parts)-1]
|
||||||
if(os.path.isdir(path) == False):
|
if(os.path.isdir(path) == False):
|
||||||
print(path + " is not an assignment.")
|
print(path + " is not an assignment.")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if(due != None or due == ""):
|
if(due != None or due == ""):
|
||||||
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
|
d = {
|
||||||
|
'due_date':due,
|
||||||
|
}
|
||||||
|
patchDB(d, 'http://localhost:8000/api/assignments/' + aname + "/")
|
||||||
|
print("Due-date changed " + due)
|
||||||
except:
|
except:
|
||||||
print("Due-date format is incorrect")
|
print("Due-date is the same")
|
||||||
return
|
|
||||||
input()
|
input()
|
||||||
parts = path.split("/")
|
|
||||||
aname = parts[len(parts)-1]
|
|
||||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
|
course = getDB("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()
|
||||||
|
@ -601,12 +601,12 @@ class Teacher:
|
||||||
|
|
||||||
data = getTeacher("eharris1")
|
data = getTeacher("eharris1")
|
||||||
t = Teacher(data)
|
t = Teacher(data)
|
||||||
# t.makeClass("APLit_eharris1")
|
#t.addClass("eharris1/APLit_eharris1")
|
||||||
#t.addAssignment("eharris1/APLit_eharris1/Lab3_APLit_eharris1", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
#t.addAssignment("eharris1/APLit_eharris1/Essay1_eharris1", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||||
#ar = ['2022rkhondak','2022inafi','2023rumareti']
|
#ar = ['2022rkhondak','2022inafi','2023rumareti']
|
||||||
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
|
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
|
||||||
#print(extra)
|
#print(extra)
|
||||||
# t.getStudents('2022rkhondak')
|
t.reqStudent('2022rkhondak', 'APLit_eharris1')
|
||||||
# t.getChanges('2022rkhondak','APLit_eharris1', 10)
|
# t.getChanges('2022rkhondak','APLit_eharris1', 10)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -6,7 +6,7 @@ import secrets
|
||||||
|
|
||||||
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(max_length=100)
|
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)
|
||||||
|
|
0
eharris1/APLit_eharris1/README.md
Normal file
0
eharris1/APLit_eharris1/README.md
Normal file
Loading…
Reference in New Issue
Block a user