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
|
||||
from distutils.dir_util import copy_tree
|
||||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
import django
|
||||
# from django.conf import settings
|
||||
# import django
|
||||
|
||||
from Website.config.settings import DATABASES, INSTALLED_APPS
|
||||
INSTALLED_APPS.remove('users.apps.UsersConfig')
|
||||
INSTALLED_APPS.remove('api')
|
||||
INSTALLED_APPS.remove('skoolos.apps.SkoolosConfig')
|
||||
INSTALLED_APPS.append('Website.api')
|
||||
settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
|
||||
django.setup()
|
||||
# from Website.config.settings import DATABASES, INSTALLED_APPS
|
||||
# INSTALLED_APPS.remove('users.apps.UsersConfig')
|
||||
# INSTALLED_APPS.remove('api')
|
||||
# INSTALLED_APPS.remove('skoolos.apps.SkoolosConfig')
|
||||
# INSTALLED_APPS.append('Website.api')
|
||||
# settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
|
||||
# django.setup()
|
||||
|
||||
from Website.api.models import *
|
||||
# from ..Website.api.models import *
|
||||
#git clone student directory ==> <student-id>/classes/assignments
|
||||
|
||||
#get teacher info from api
|
||||
|
@ -46,7 +46,7 @@ def getDB(url):
|
|||
return(r.json())
|
||||
def patchDB(data, url):
|
||||
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())
|
||||
|
||||
def postDB(data, url):
|
||||
|
@ -150,29 +150,31 @@ class Teacher:
|
|||
|
||||
#make class from existing directory, add to git and api
|
||||
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)):
|
||||
cname = path.split("/")
|
||||
cname = cname[len(cname)-1]
|
||||
cpath = self.username + "/" + cname
|
||||
data = {
|
||||
"name": cname,
|
||||
"repo": "",
|
||||
"path": cpath,
|
||||
"teacher": self.username,
|
||||
"assignments": "",
|
||||
"default_file": "",
|
||||
"confirmed": "",
|
||||
"unconfirmed": ""
|
||||
"owner":self.id
|
||||
}
|
||||
#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
|
||||
#upate self.classes
|
||||
self.classes.append(data)
|
||||
data = {
|
||||
'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
|
||||
#subject: string, assignments: list
|
||||
|
@ -252,28 +254,28 @@ class Teacher:
|
|||
print(sname + " does not exist.")
|
||||
return False
|
||||
course = getDB("http://127.0.0.1:8000/api/classes/" + cname)
|
||||
if(sname in str(course['unconfirmed'])):
|
||||
print (sname + " already requested.")
|
||||
return True
|
||||
if(sname in str(course['confirmed'])):
|
||||
print (sname + " alredy enrolled.")
|
||||
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'] + "/")
|
||||
# if(sname in str(course['unconfirmed'])):
|
||||
# print (sname + " already requested.")
|
||||
# return True
|
||||
# if(sname in str(course['confirmed'])):
|
||||
# print (sname + " alredy enrolled.")
|
||||
# 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://localhost:8000/api/students/" + (sname)+ "/")
|
||||
if(course['unconfirmed']==[]):
|
||||
course['unconfirmed']=student['ion_user']
|
||||
else:
|
||||
|
@ -281,7 +283,8 @@ class Teacher:
|
|||
cinfo = {
|
||||
"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
|
||||
|
||||
#Student should have confirmed on their endd, but class had not been updated yet
|
||||
|
@ -364,10 +367,10 @@ class Teacher:
|
|||
parts = path.split("/")
|
||||
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.")
|
||||
return False
|
||||
if((parts[1] in self.sclass) == False):
|
||||
if((parts[1] in str(self.classes)) == False):
|
||||
print("Not in valid class directory")
|
||||
return False
|
||||
#parts of assignment name (Essay1, APLit)
|
||||
|
@ -439,16 +442,9 @@ class Teacher:
|
|||
course['assignments'] = course['assignments'].append(ass)
|
||||
|
||||
cinfo = {
|
||||
"name": course['name'],
|
||||
"repo": "",
|
||||
"path": course['path'],
|
||||
"teacher": "eharris1",
|
||||
"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
|
||||
else:
|
||||
print("Assignment already addedd")
|
||||
|
@ -457,18 +453,22 @@ class Teacher:
|
|||
#try to avoid
|
||||
#copy modified assignments to student directories
|
||||
def updateAssignment(self, path, course, due):
|
||||
parts = path.split("/")
|
||||
aname = parts[len(parts)-1]
|
||||
if(os.path.isdir(path) == False):
|
||||
print(path + " is not an assignment.")
|
||||
return
|
||||
try:
|
||||
if(due != None or due == ""):
|
||||
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:
|
||||
print("Due-date format is incorrect")
|
||||
return
|
||||
print("Due-date is the same")
|
||||
input()
|
||||
parts = path.split("/")
|
||||
aname = parts[len(parts)-1]
|
||||
course = getDB("http://127.0.0.1:8000/api/classes/" + course)
|
||||
slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name'])
|
||||
cdir = os.getcwd()
|
||||
|
@ -601,12 +601,12 @@ class Teacher:
|
|||
|
||||
data = getTeacher("eharris1")
|
||||
t = Teacher(data)
|
||||
# t.makeClass("APLit_eharris1")
|
||||
#t.addAssignment("eharris1/APLit_eharris1/Lab3_APLit_eharris1", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||
#t.addClass("eharris1/APLit_eharris1")
|
||||
#t.addAssignment("eharris1/APLit_eharris1/Essay1_eharris1", "APLit_eharris1", '2020-08-11 16:58:33.383124')
|
||||
#ar = ['2022rkhondak','2022inafi','2023rumareti']
|
||||
#extra = t.reqAddStudentList(ar, "APLit_eharris1")
|
||||
#print(extra)
|
||||
# t.getStudents('2022rkhondak')
|
||||
t.reqStudent('2022rkhondak', 'APLit_eharris1')
|
||||
# t.getChanges('2022rkhondak','APLit_eharris1', 10)
|
||||
|
||||
'''
|
||||
|
|
|
@ -6,7 +6,7 @@ import secrets
|
|||
|
||||
class Student(models.Model):
|
||||
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)
|
||||
git=models.CharField(default="", max_length=100, 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