From 90b323b42d7f94cbed976872d08cf255fe6932e8 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 14:09:12 -0400 Subject: [PATCH 01/40] more documentation --- CLI/commands.py | 40 +++-- CLI/s-git-oldd.py | 256 ----------------------------- CLI/server.py | 23 --- CLI/t-git-old.py | 372 ------------------------------------------ Website/api/models.py | 54 +++--- 5 files changed, 50 insertions(+), 695 deletions(-) delete mode 100644 CLI/s-git-oldd.py delete mode 100644 CLI/server.py delete mode 100644 CLI/t-git-old.py diff --git a/CLI/commands.py b/CLI/commands.py index c8827a1..b89acfc 100644 --- a/CLI/commands.py +++ b/CLI/commands.py @@ -4,7 +4,6 @@ import json import os import argparse - ''' my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again") my_parser.add_argument('--init', action="store_true") #returns true if run argument @@ -16,7 +15,8 @@ if(outputs['init']): start() ''' -#already ccrerrated account through website, has to login + +# already created account through website, has to login def update(): """ Gets data from the database @@ -24,6 +24,7 @@ def update(): """ return + def yesorno(question): questions = [ { @@ -33,17 +34,18 @@ def yesorno(question): }, ] answers = prompt(questions) - if(answers["response"] == "y"): + if answers["response"] == "y": return True return False + def login(): """ Login to the website with a username and password :return: user information json if successful, None otherwise """ - #enter username - #enter password + # enter username + # enter password questions = [ { 'type': 'input', @@ -57,12 +59,12 @@ def login(): }, ] user = prompt(questions) - #reading from json of users (replace w GET to database) to check if user is registered + # reading from json of users (replace w GET to database) to check if user is registered with open('users.json', 'r') as json_file: data = json.load(json_file) for i in range(len(data)): if user["webmail"] == data[i]["webmail"]: - if(user["password"] == data[i]["password"]): + if user["password"] == data[i]["password"]: print("Logged in!") return data[i] else: @@ -71,7 +73,8 @@ def login(): print("User not found. Please Try again") return None -#did not create account through website, has to signup/login + +# did not create account through website, has to signup/login def signup(): """ Used to create an account for the service. @@ -93,7 +96,7 @@ def signup(): 'type': 'list', 'name': 'grade', 'message': 'Grade?', - 'choices':["9","10","11","12"] + 'choices': ["9", "10", "11", "12"] }, { 'type': 'input', @@ -114,7 +117,7 @@ def signup(): if len(user["password"]) < 6: print("Password is too short. Try again.") return None - if (("@tjhsst.edu" in user['webmail']) == False): + if not ("@tjhsst.edu" in user['webmail']): print("Webmail entered was not a @tjhhsst.edu. Try again.") return None @@ -125,6 +128,7 @@ def signup(): open("users.json", "w").write(str(json.dumps(data))) return user + def relogin(): """ Login to an already verified user account @@ -135,15 +139,15 @@ def relogin(): 'type': 'list', 'name': 'choice', 'message': '', - 'choices':["Continue as current user","Login into new user","Sign up into new account"] + 'choices': ["Continue as current user", "Login into new user", "Sign up into new account"] }, ] answer = prompt(questions) def setup(user): - #Read classes/assignenments and setup directory: - #SkoolOS/Math/Week1 + # Read classes/assignenments and setup directory: + # SkoolOS/Math/Week1 """ Reads classes and assignments of/for the user and properly sets of their work directory :param user: @@ -154,20 +158,20 @@ def setup(user): for a in user["classes"][c]: os.makedirs(c + "/" + a) + def start(): """ Prompts the user for whether or not they have an account and allows them to login/signup depending on their response :return: """ - if(os.path.exists(".login.txt") == False): + if not os.path.exists(".login.txt"): b = yesorno("Do you have a SkoolOS account?(y/N)") - if(b): + if b: user = login() - if(user != None): + if user is not None: setup(user) open(".login.txt", "w").write(str(user)) else: user = signup() - if(user != None): + if user is not None: open(".login.txt").write(str(user)) - diff --git a/CLI/s-git-oldd.py b/CLI/s-git-oldd.py deleted file mode 100644 index 0cf4486..0000000 --- a/CLI/s-git-oldd.py +++ /dev/null @@ -1,256 +0,0 @@ -import subprocess -import os -import requests -import webbrowser -import pprint -import json -import shutil -import time -import pyperclip - -#git clone student directory ==> /classes/assignments - -#get teacher info from api -def getStudent(ion_user): - URL = "http://127.0.0.1:8000/students/" + ion_user + "/" - r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) - if(r.status_code == 200): - data = r.json() - return data - elif(r.status_code == 404): - return None - print("Make new account!") - elif(r.status_code == 403): - return None - print("Invalid username/password") - else: - return None - print(r.status_code) - -def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) - print("GET:" + str(r.status_code)) - return(r.json()) - -def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("POST:" + str(r.status_code)) - return(r.json()) - -def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("PUT:" + str(r.status_code)) - return(r.json()) - -def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) - print("DELETE:" + str(r.status_code)) - return None - -def command(command): - ar = [] - command = command.split(" ") - for c in command: - ar.append(c) - process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() - output = process.communicate()[1] - print(output.decode('utf-8')) - -#################################################################################################################################### - -#public methods: deleteClass, makeClass, update -class Student: - def __init__(self, data): - # teacher info already stored in API - # intitialze fields after GET request - self.first_name=data['first_name'] - self.last_name=data['last_name'] - self.git=data['git'] - self.username=data['ion_user'] - self.url= "http://127.0.0.1:8000/students/" + self.username + "/" - self.email = data['email'] - self.grade = data['grade'] - self.student_id=data['student_id'] - self.completed = data['completed'] - #classes in id form (Example: 4,5) - - #storing actual classes - cid=data['classes'].split(",") - try: - cid.remove('') - except: - pass - try: - cid.remove("") - except: - pass - classes=[] - for c in cid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" - classes.append(getDB(url)) - - self.classes = classes - self.sclass=str(data['classes']) - - #storing added_to classes - nid=data['added_to'].split(",") - try: - nid.remove('') - except: - pass - try: - nid.remove("") - except: - pass - nclasses=[] - for c in nid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" - nclasses.append(getDB(url)) - - self.new = nclasses - self.snew=str(data['added_to']) - if(os.path.isdir(self.username)): - print("Synced to " + self.username) - else: - os.mkdir(self.username) - - - #update API and Github, all assignments / classes - def update(self): - #lists all classes - ignore=['.DS_Store'] - classes = os.listdir(self.username) - for i in ignore: - try: - classes.remove(i) - except: - pass - - for i in range(len(classes)): - c = classes[i] - path = self.username + "/" + c - #lists all assignments and default files - #push to git - isclass = False - for d in os.listdir(path): - if(d == '.git'): - isclass=True - break - if(isclass): - loc = os.getcwd() - os.chdir(path) - command('git fetch origin') - command('git checkout ' + self.username) - command('git add .') - command('git commit -m ' + self.username + '-update') - command('git push -u origin ' + self.username) - command('git merge master') - os.chdir(loc) - print("Updated: " + c) - else: - print(d + " is not a class") - - #class name format: _ - - - #add classes from 'new' field - def addClass(self, cid): - if((cid in self.snew) == False): - if((cid in self.sclass) == True): - print("Already enrolled in this class.") - else: - print("Not added by teacher yet.") - return None - data = getDB('http://127.0.0.1:8000/classes/'+cid) - - #clone class repo and make student branch (branch name: username) - os.chdir(self.username) - command("git clone " + data['repo']) - os.chdir(data['name']) - command("git checkout " + self.username) - command("git push -u origin " + self.username) - - self.classes.append(data) - if(len(self.sclass)==0): - self.sclass = data['id'] - else: - self.sclass = self.sclass + "," + str(data['id']) - - #upddate self.new - s="" - nar = '' - for i in range(len(self.new)): - if(self.new[i]['id'] == int(data['id'])): - print("DELETE: " + self.new[i]['name']) - del self.new[i] - #recreate sclass field, using ids - for c in self.new: - s = s + str(c['id']) + "," - nar.append(c) - self.snew=s - self.new=nar - break - - #update teacher instance in db, classes field - data={ - 'first_name':self.first_name, - 'last_name':self.last_name, - 'git':self.git, - 'ion_user':self.username, - 'student_id':self.student_id, - 'added_to':self.snew, - 'url':self.url, - 'classes':self.sclass, - 'email':self.email, - 'grade':self.grade, - 'completed':self.completed - } - print(self.url) - print(putDB(data, self.url)) - return data - - def submit(self, path): - #2022rkhondak/English11_eharris1/Essay1 - #check if valid assignment - parts = path.split("/") - if(len(parts) != 3): - print("Assignment path too short") - return - isclass = False - for c in self.classes: - if(c['name'] == parts[1]): - isclass==True - break - if(parts[0] != self.username and isclass and os.path.isdir(path) == False): - print("Not valid assignment") - return - if((parts[1] + "/" + parts[2]) in self.completed): - print(parts[2] + " already submited. ") - # return - resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ") - if(resp == 'y'): - os.chdir(self.username + "/" + parts[1]) - command("git add .") - command("git commit -m submit") - command("git tag " + parts[1] + "-final") - command("git push -u origin " + self.username + " --tags") - self.completed = self.completed + "," + parts[1] + "/" + parts[2] - data={ - 'first_name':self.first_name, - 'last_name':self.last_name, - 'git':self.git, - 'ion_user':self.username, - 'student_id':self.student_id, - 'added_to':self.snew, - 'url':self.url, - 'classes':self.sclass, - 'email':self.email, - 'grade':self.grade, - 'completed':self.completed - } - #print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/")) - -data = getStudent("2022rkhondak") -s = Student(data) -s.update() \ No newline at end of file diff --git a/CLI/server.py b/CLI/server.py deleted file mode 100644 index 1cc095f..0000000 --- a/CLI/server.py +++ /dev/null @@ -1,23 +0,0 @@ -from http.server import HTTPServer - -class HTTPServer(BaseHTTPServer.HTTPServer): - - _continue = True - - def serve_until_shutdown(self): - while self._continue: - self.handle_request() - - def shutdown(self): - self._continue = False - # We fire a last request at the server in order to take it out of the - # while loop in `self.serve_until_shutdown`. - try: - urllib2.urlopen( - 'http://%s:%s/' % (self.server_name, self.server_port)) - except urllib2.URLError: - # If the server is already shut down, we receive a socket error, - # which we ignore. - pass - self.server_close() - diff --git a/CLI/t-git-old.py b/CLI/t-git-old.py deleted file mode 100644 index 6e11a47..0000000 --- a/CLI/t-git-old.py +++ /dev/null @@ -1,372 +0,0 @@ -import subprocess -import os -import requests -import webbrowser -import pprint -import json -import shutil -import time -import pyperclip - -#git clone student directory ==> /classes/assignments - -#get teacher info from api -def getTeacher(ion_user): - URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/" - r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) - if(r.status_code == 200): - data = r.json() - return data - elif(r.status_code == 404): - return None - print("Make new account!") - elif(r.status_code == 403): - return None - print("Invalid username/password") - else: - return None - print(r.status_code) - -def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) - print("GET:" + str(r.status_code)) - return(r.json()) - -def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("POST:" + str(r.status_code)) - return(r.json()) - -def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("PUT:" + str(r.status_code)) - return(r.json()) - -def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) - print("DELETE:" + str(r.status_code)) - return None - -def command(command): - ar = [] - command = command.split(" ") - for c in command: - ar.append(c) - process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() - output = process.communicate()[1] - #print(output.decode('utf-8')) - -#################################################################################################################################### - -#public methods: deleteClass, makeClass, update -class Teacher: - def __init__(self, data): - # teacher info already stored in API - # intitialze fields after GET request - self.first_name=data['first_name'] - self.last_name=data['last_name'] - self.git=data['git'] - self.username=data['ion_user'] - self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/" - self.email = data['email'] - #classes in id form (Example: 4,5) - - cid=data['classes'].split(",") - try: - cid.remove('') - except: - pass - try: - cid.remove("") - except: - pass - classes=[] - for c in cid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" - classes.append(getDB(url)) - - self.classes = classes - self.sclass=str(data['classes']) - if(os.path.isdir(self.username)): - print("Synced to " + self.username) - else: - os.mkdir(self.username) - - - #update API and Github, all assignments / classes - def update(self): - #lists all classes - ignore=['.git','.DS_Store'] - classes = os.listdir(self.username) - for i in ignore: - try: - classes.remove(i) - except: - pass - #list of classes that have been deleted (not with deleteClass) - extra = [] - for c in self.classes: - extra.append(c) - for i in range(len(extra)): - e = extra[i]['path'] - extra[i] = e - print("Extra: "+str(extra)) - print("Local:" + str(classes)) - #checks all class directories first - for c in classes: - path = self.username + "/" + c - if(self.checkClass(path) == False): - return - extra.remove(path) - print("Current classes: " + path) - - for e in extra: - self.deleteClass(e) - - for i in range(len(classes)): - c = classes[i] - path = self.username + "/" + c - #lists all assignments and default files - #if no .git, directory not synced to git or API - if (self.checkInDB(path)==False): - self.addClass(path) - else: - #push to git - loc = os.getcwd() - os.chdir(path) - command('git fetch origin') - command('git pull origin master') - command('git add .') - command('git commit -m "Update"') - command('git push -u origin master') - os.chdir(loc) - - #class name format: _ - - #turn existing directory into class, Pre-condition: directory exists - #relative path to class: 2022rkhondak/Math4 - def checkClass(self,path): - cname = path.split("/") - cname = cname[len(cname)-1] - if(os.path.isfile(path)): - print(path + " must be in a Class directory.") - return False - if(("_" + self.username) in cname) == False: - print("Incorrect class name: Must be in the format: " + self.username+ "/_, not " + path) - return False - dirs = os.listdir(path) - #checks if there is a file (not within Assignments) in class, need at least 1 - deffile = False - #checks if there is a file in an Assignment, need at least 1 (default True in case no assignments) - as_file = True - as_bad = "" - - for d in dirs: - if(os.path.isfile(d)): - deffile=True - else: - #checks if there is a file in an Assignment, need at least 1 - as_file = False - asdir = os.listdir(path + "/" + d) - for a in asdir: - if(os.path.isfile(path + "/" + d + "/" +a)): - as_file=True - if(as_file==False): - as_bad = d - break - if(as_file==False): - print("Assignment '" + as_bad + "' does not have a default file!") - return False - - if(deffile==False): - print("Need a default file in the " + path + " Directory!") - return False - return True - - def checkInDB(self, path): - n = path.split("/") - n = n[len(n)-1] - for c in self.classes: - if(n == c['name']): - return True - return False - - #adds class to git, not API - #Assuming valid class name - def addClasstoGit(self, path): - cname = path.split("/") - cname = cname[len(cname)-1] - #push to remote repo - url='https://github.com/' + self.git + "/" + cname - if(requests.get(url).status_code != 200): - input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n") - try: - pyperclip.copy(cname) - print(cname + " copied to clipboard.") - except: - pass - time.sleep(2) - webbrowser.open('https://github.com/new') - input("Repo created? (Press any key to continue)\n") - - print(url) - while(requests.get(url).status_code != 200): - r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n") - if(r=="N" or r=="No"): - return None - cdir = os.getcwd() - os.chdir(path) - command('git init') - command('git add .') - command('git commit -m Hello_Class') - command('git remote add origin ' + url + '.git') - command('git push -u origin master') - else: - cdir = os.getcwd() - os.chdir(path) - print("Repo already exists. Cloning instead.") - command('git clone') - command('git fetch origin') - command('git pull') - command('git add .') - command('git commit -m Hello_Class') - command('git push -u origin master') - os.chdir(cdir) - print(cdir) - data={ - 'name':cname, - 'repo':url, - 'path':path, - 'teacher':self.username, - } - return data - - #make class from existing directory, add to git and api - def addClass(self, path): - if (self.checkClass(path)): - data = self.addClasstoGit(path) - #make class instance in db - data = postDB(data, 'http://127.0.0.1:8000/classes/') - #add to instance - #upate self.classes - self.classes.append(data) - if(len(self.sclass)==0): - self.sclass = data['id'] - else: - self.sclass = self.sclass + "," + str(data['id']) - - #update teacher instance in db, classes field - data={ - 'first_name':self.first_name, - 'last_name':self.last_name, - 'git':self.git, - 'ion_user':self.username, - 'url':self.url, - 'classes':self.sclass, - 'email':self.email - } - putDB(data, self.url) - - return data - - - #make a new class from scratch - #subject: string, assignments: list - #class name must be: _ - def makeClass(self, cname, assignments): - #check if class exists - path = self.username + "/" + cname - if(os.path.exists(path)): - print("Class already exists: " + cname) - return - else: - if((("_" + self.username) in cname) == False): - print("class name must be: "+ cname + "_" + self.username) - return - cdir = os.getcwd() - os.mkdir(path) - f=open(path + "/README.md", "w") - f.close() - #push to remote repo - os.chdir(path) - for a in assignments: - os.mkdir(a) - f=open(a + "/instructions.txt", "w") - f.close() - os.chdir(cdir) - - data = self.addClass(path) - return data - - def deleteClass(self, path): - if(os.path.exists(path) == False): - print(path + " does not exist locally.") - resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ") - if(resp != 'y'): - return - - cname = path.split("/") - cname = cname[len(cname)-1] - cid = None - repo = '' - for c in self.classes: - if cname == c['name']: - cid = str(c['id']) - repo = c['repo'] - - #remove from api - for i in range(len(self.classes)): - if(self.classes[i]['id'] == int(cid)): - print("DELETE: " + self.classes[i]['name']) - del self.classes[i] - s="" - #recreate sclass field, using ids - for c in self.classes: - s = s + str(c['id']) + "," - print(s) - s = s[:-1] - print(s) - data={ - 'first_name':self.first_name, - 'last_name':self.last_name, - 'git':self.git, - 'ion_user':self.username, - 'url':self.url, - 'classes':s, - 'email':self.email - } - print(putDB(data, self.url)) - delDB("http://127.0.0.1:8000/classes/" + cid + "/") - break - - #remove locally - try: - shutil.rmtree(path) - except: - pass - - #remove from git - input("Delete repository: " + cname + ". Scroll to the bottom of the page and press 'Delete this repository' (Press any key to continue) ") - print(repo) - time.sleep(2) - webbrowser.open(repo + "/settings") - input("Repo deleted? (Press any key to continue) ") - - print(repo) - while(requests.get(repo).status_code == 200): - r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n") - if(r=="N" or r=="No" or r=='n'): - return None - -#make student repo by student id - def addStudent(self,stid): - print(stid) - - def comment(self): - print("heheheh") - -data = getTeacher("eharris1") -t = Teacher(data) -t.makeClass('English11_eharris1', ["Essay1"]) -t.update() diff --git a/Website/api/models.py b/Website/api/models.py index 9dc22f2..c4b92ae 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -3,16 +3,15 @@ from django.contrib.auth.models import User import secrets - class Student(models.Model): user = models.OneToOneField(User, blank=True, on_delete=models.CASCADE) 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) - classes=models.CharField(max_length=100, default="", blank=True) - added_to=models.CharField(max_length=100, default="", blank=True) - completed=models.TextField(default="", blank=True) + git = models.CharField(default="", max_length=100, blank=True) + repo = models.URLField(default="", blank=True) + classes = models.CharField(max_length=100, default="", blank=True) + added_to = models.CharField(max_length=100, default="", blank=True) + completed = models.TextField(default="", blank=True) def save(self, *args, **kwargs): super(Student, self).save(*args, **kwargs) @@ -24,13 +23,14 @@ class Student(models.Model): class Assignment(models.Model): owner = models.ForeignKey(User, null=True, blank=True, related_name='aowner', on_delete=models.CASCADE) - name=models.CharField(max_length=100, primary_key=True) - due_date=models.DateTimeField() + name = models.CharField(max_length=100, primary_key=True) + due_date = models.DateTimeField() # files = models.ManyToManyField(DefFiles) - files=models.CharField(max_length=100, default="", blank=True) - path=models.CharField(max_length=100) - classes=models.CharField(max_length=100) - teacher=models.CharField(max_length=100) + files = models.CharField(max_length=100, default="", blank=True) + path = models.CharField(max_length=100) + classes = models.CharField(max_length=100) + teacher = models.CharField(max_length=100) + def __str__(self): return '%s' % (self.name) @@ -41,12 +41,12 @@ class Class(models.Model): name = models.CharField(primary_key=True, max_length=100) id = models.CharField(max_length=8, blank=True, null=True) description = models.CharField(default="Class Description", max_length=500) - repo=models.URLField(default="", blank=True) - path=models.CharField(max_length=100, default="") - assignments=models.ManyToManyField(Assignment, blank=True) - default_file=models.CharField(max_length=100, default="", blank=True) - confirmed=models.ManyToManyField(Student, blank=True, related_name='confirmed') - unconfirmed=models.ManyToManyField(Student, blank=True, related_name='unconfirmed') + repo = models.URLField(default="", blank=True) + path = models.CharField(max_length=100, default="") + assignments = models.ManyToManyField(Assignment, blank=True) + default_file = models.CharField(max_length=100, default="", blank=True) + confirmed = models.ManyToManyField(Student, blank=True, related_name='confirmed') + unconfirmed = models.ManyToManyField(Student, blank=True, related_name='unconfirmed') # assignments = models.ManyToManyField(Assignment, default="") # default_file = models.ManyToManyField(DefFiles) @@ -62,11 +62,12 @@ class Class(models.Model): def __str__(self): return self.name + class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) - classes=models.ManyToManyField(Class, blank=True, related_name='classes') - git=models.CharField(max_length=100, default="", blank=True) - ion_user=models.CharField(primary_key=True, max_length=100) + classes = models.ManyToManyField(Class, blank=True, related_name='classes') + git = models.CharField(max_length=100, default="", blank=True) + ion_user = models.CharField(primary_key=True, max_length=100) def __str__(self): return f"{self.user.username}'s Profile" @@ -74,6 +75,7 @@ class Teacher(models.Model): def save(self, *args, **kwargs): super(Teacher, self).save(*args, **kwargs) + # class Student(models.Model): # user = models.OneToOneField(User, on_delete=models.CASCADE) # ion_user=models.CharField(primary_key=True, max_length=100) @@ -86,8 +88,8 @@ class Teacher(models.Model): class DefFiles(models.Model): - name=models.CharField(max_length=100) - path=models.CharField(max_length=100) - assignment=models.CharField(max_length=100, default="") - classes=models.CharField(max_length=100) - teacher=models.CharField(max_length=100) + name = models.CharField(max_length=100) + path = models.CharField(max_length=100) + assignment = models.CharField(max_length=100, default="") + classes = models.CharField(max_length=100) + teacher = models.CharField(max_length=100) From 5a04441e9b7ac74130eb0c55fdb351a4d15b0940 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 14:59:42 -0400 Subject: [PATCH 02/40] comments --- CLI/teacher.py | 9 ++++++- eharris1/Art12_eharris1/Painting1/rubric.txt | 0 eharris1/Art12_eharris1/README.md | 0 eharris1/English11_eharris1/README.md | 0 skoolos.py | 26 ++++++++++++++------ 5 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 eharris1/Art12_eharris1/Painting1/rubric.txt create mode 100644 eharris1/Art12_eharris1/README.md create mode 100644 eharris1/English11_eharris1/README.md diff --git a/CLI/teacher.py b/CLI/teacher.py index 08f0a70..2ba3032 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -40,25 +40,31 @@ def getTeacher(ion_user): return None print(r.status_code) +#makes a GET request to given url, returns dict def getDB(url): r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) print("GET:" + str(r.status_code)) return(r.json()) + +#makes a PATCH (updates instance) request to given url, returns dict def patchDB(data, url): r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("PATCH:" + str(r.status_code)) return(r.json()) +#makes a POST (makes new instance) request to given url, returns dict def postDB(data, url): r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("POST:" + str(r.status_code)) return(r.json()) +#makes a PUT (overwrites instance) request to given url, returns dict def putDB(data, url): r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("PUT:" + str(r.status_code)) return(r.json()) +#makes a DELETE (delete instance) request to given url, returns dict def delDB(url): r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) print("DELETE:" + str(r.status_code)) @@ -167,13 +173,14 @@ class Teacher: } #make class instance in db postDB(data, 'http://127.0.0.1:8000/api/classes/') + time.sleep(1) self.classes.append(cname) #add to instance #upate self.classes data = { 'classes':self.classes } - print(self.username) + print(self.classes) print(patchDB(data, 'http://127.0.0.1:8000/api/teachers/' + self.username + "/")) #make a new class from scratch diff --git a/eharris1/Art12_eharris1/Painting1/rubric.txt b/eharris1/Art12_eharris1/Painting1/rubric.txt new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/Art12_eharris1/README.md b/eharris1/Art12_eharris1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/English11_eharris1/README.md b/eharris1/English11_eharris1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/skoolos.py b/skoolos.py index 2003e6b..c35c68e 100644 --- a/skoolos.py +++ b/skoolos.py @@ -100,9 +100,11 @@ def teacherCLI(user, password): # 3. Get progress logs on a student # 2. make an assignment for a class # 3. view student submissions for an assignment - carray = teacher.classes - carray.append("Exit SkoolOS") + carray = [] + for c in teacher.classes: + carray.append(c) carray.append("Make New Class") + carray.append("Exit SkoolOS") courses = [ { 'type': 'list', @@ -119,10 +121,11 @@ def teacherCLI(user, password): { 'type': 'input', 'name': 'cname', - 'message': 'Class Name: ', + 'message': 'Class Name (Must be: _): ', }, ] cname = prompt(questions)['cname'] + print(cname) teacher.makeClass(cname) soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] questions = [ @@ -130,7 +133,7 @@ def teacherCLI(user, password): 'type': 'list', 'choices':soption, 'name': 'students', - 'message': 'Add list of students (input path): ', + 'message': 'Add Students): ', }, ] choice = prompt(questions)['students'].split(")")[0] @@ -138,15 +141,22 @@ def teacherCLI(user, password): s = input("Student name: ") teacher.addStudent(s, cname) if("2" == choice): - p = input("Relativee Path: ") - if(os.path.exists(p)): - print(p + " does not exist.") + print("File must be .txt and have 1 student username per line") + path = input("Relative Path: ") + while(not os.path.exists(path)): + if(path == 'N'): + sys.exit(0) + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, cname) else: print("Class: " + course) unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] for s in unconf: - teacher.addStudent() + teacher.addStudent(s, course) options = ['1) Request Student', "2) Add assignment", "3) View student information"] questions = [ { From 9fa43809cb7315e8c83f6079a1854686ef5b3dce Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 15:00:39 -0400 Subject: [PATCH 03/40] db methods comments student --- CLI/student.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index fd75366..3281fda 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -28,30 +28,34 @@ def getStudent(ion_user): return None print(r.status_code) +#makes a GET request to given url, returns dict def getDB(url): r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) print("GET:" + str(r.status_code)) return(r.json()) +#makes a PATCH (updates instance) request to given url, returns dict +def patchDB(data, url): + r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + print("PATCH:" + str(r.status_code)) + return(r.json()) + +#makes a POST (makes new instance) request to given url, returns dict def postDB(data, url): r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("POST:" + str(r.status_code)) return(r.json()) +#makes a PUT (overwrites instance) request to given url, returns dict def putDB(data, url): r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("PUT:" + str(r.status_code)) return(r.json()) -def patchDB(data, url): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("PATH:" + str(r.status_code)) - return(r.json()) - +#makes a DELETE (delete instance) request to given url, returns dict def delDB(url): r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) print("DELETE:" + str(r.status_code)) - return None def command(command): ar = [] From 71f288eaae9a0544e38243913c607e8b095f6bcf Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 15:01:29 -0400 Subject: [PATCH 04/40] more documentation --- CLI/student.py | 240 ++++++++++++++------------- CLI/teacher.py | 434 +++++++++++++++++++++++++++---------------------- 2 files changed, 364 insertions(+), 310 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index fd75366..75069f4 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -9,77 +9,85 @@ import time import pyperclip import datetime -#git clone student directory ==> /classes/assignments -#get teacher info from api +# git clone student directory ==> /classes/assignments + +# get teacher info from api def getStudent(ion_user): - URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" - r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) - if(r.status_code == 200): - data = r.json() - return data - elif(r.status_code == 404): - return None - print("Make new account!") - elif(r.status_code == 403): - return None - print("Invalid username/password") - else: - return None - print(r.status_code) + URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" + r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) + if (r.status_code == 200): + data = r.json() + return data + elif (r.status_code == 404): + return None + print("Make new account!") + elif (r.status_code == 403): + return None + print("Invalid username/password") + else: + return None + print(r.status_code) + def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) + r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1')) print("GET:" + str(r.status_code)) - return(r.json()) + return (r.json()) + def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("POST:" + str(r.status_code)) - return(r.json()) + return (r.json()) + def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) - return(r.json()) + return (r.json()) + 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)) - return(r.json()) + return (r.json()) + def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) print("DELETE:" + str(r.status_code)) return None + def command(command): ar = [] command = command.split(" ") for c in command: ar.append(c) - process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() + process = subprocess.Popen(ar, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = process.poll() output = process.communicate()[0] print(output.decode('utf-8')) return output.decode('utf-8') + #################################################################################################################################### -#public methods: deleteClass, makeClass, update +# public methods: deleteClass, makeClass, update class Student: def __init__(self, data): # teacher info already stored in API # intitialze fields after GET request - self.git=data['git'] - self.username=data['ion_user'] - self.url= "http://127.0.0.1:8000/api/students/" + self.username + "/" + self.git = data['git'] + self.username = data['ion_user'] + self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/" self.grade = data['grade'] - self.completed = data['completed'] - self.user = data['user'] - #classes in id form (Example: 4,5) - #storing actual classes - cid=data['classes'].split(",") + self.completed = data['completed'] + self.user = data['user'] + # classes in id form (Example: 4,5) + # storing actual classes + cid = data['classes'].split(",") try: cid.remove('') except: @@ -88,16 +96,16 @@ class Student: cid.remove("") except: pass - classes=[] + classes = [] for c in cid: url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" classes.append(getDB(url)) - + self.classes = classes - self.sclass=str(data['classes']) - - #storing added_to classes - nid=data['added_to'].split(",") + self.sclass = str(data['classes']) + + # storing added_to classes + nid = data['added_to'].split(",") try: nid.remove('') except: @@ -106,21 +114,21 @@ class Student: nid.remove("") except: pass - nclasses=[] + nclasses = [] for c in nid: url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" nclasses.append(getDB(url)) - + self.new = nclasses - self.snew=str(data['added_to']) + self.snew = str(data['added_to']) self.repo = data['repo'] - if(os.path.isdir(self.username) == False): - if(self.repo == ""): - user= self.git - pwd= input("Enter Github password: ") - #curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos - url= "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos" + if (os.path.isdir(self.username) == False): + if (self.repo == ""): + user = self.git + pwd = input("Enter Github password: ") + # curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos + url = "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos" print(url) os.system(url) cdir = os.getcwd() @@ -133,11 +141,11 @@ class Student: command('git push -u origin master') os.chdir(cdir) self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git' - data={ - 'repo':self.repo + data = { + 'repo': self.repo } print(patchDB(data, self.url)) - print("Synced to " + self.username) + print("Synced to " + self.username) def getClasses(self): classes = self.classes @@ -157,16 +165,16 @@ class Student: due = ass['due_date'].replace("T", " ").replace("Z", "") due = datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') diff = now - due - zero = datetime.timedelta(0,0) - #check due ddate is in span range is now past date (- timdelta) - if(diff < span and diff > zero): - print(a + " due in:" + str(now-due)) + zero = datetime.timedelta(0, 0) + # check due ddate is in span range is now past date (- timdelta) + if (diff < span and diff > zero): + print(a + " due in:" + str(now - due)) except Exception as e: print(e) pass - #update API and Github, all assignments / classes + # update API and Github, all assignments / classes def update(self): cdir = os.getcwd() os.chdir(self.username) @@ -187,10 +195,10 @@ class Student: self.addClass(str(c['name'])) command("git checkout master") print(os.getcwd()) - - #updates 1 class, does not switch to master + + # updates 1 class, does not switch to master def updateClass(self, course): - if((course in self.sclass) == False): + if ((course in self.sclass) == False): print("Class not found") return cdir = os.getcwd() @@ -201,45 +209,45 @@ class Student: command("git pull origin " + course) command("git push -u origin " + course) - #class name format: _ + # class name format: _ - #add classes from 'new' field + # add classes from 'new' field def addClass(self, cid): - data = getDB('http://127.0.0.1:8000/api/classes/'+ str(cid)) - if((cid in self.snew) == False or (self.username in data['confirmed'])): + data = getDB('http://127.0.0.1:8000/api/classes/' + str(cid)) + if ((cid in self.snew) == False or (self.username in data['confirmed'])): print("Already enrolled in this class.") return None - if((cid in self.sclass) or (self.username in data['unconfirmed']) == False): + if ((cid in self.sclass) or (self.username in data['unconfirmed']) == False): print("Not added by teacher yet.") return None - #add class teacher as cocllaborator to student repo + # add class teacher as cocllaborator to student repo 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'] - 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) os.system(url) cdir = os.getcwd() path1 = self.username + "/" + self.username path2 = self.username - if(os.path.isdir(path1)): + if (os.path.isdir(path1)): os.chdir(path1) else: os.chdir(self.username) command("git clone " + self.repo) os.chdir(self.username) - #push to git, start at master + # push to git, start at master os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") command("git push origin " + data['name']) command("git checkout master") - #git clone --single-branch --branch + # git clone --single-branch --branch os.chdir(cdir) # data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") @@ -250,79 +258,79 @@ class Student: # print(data['confirmed']) # print(putDB(data, 'http://127.0.0.1:8000/api/classes/'+ str(cid) + "/")) - #add teacher as collaborator - #curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR' + # add teacher as collaborator + # curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR' user = self.git self.classes.append(data) - if(len(self.sclass)==0): + if (len(self.sclass) == 0): self.sclass = data['name'] else: self.sclass = self.sclass + "," + str(data['name']) - #upddate self.new - snew="" + # upddate self.new + snew = "" new = [] for i in range(len(self.new)): - if(self.new[i]['name'] == data['name']): + if (self.new[i]['name'] == data['name']): del self.new[i] - #recreate sclass field, using ids + # recreate sclass field, using ids for c in self.new: snew = snew + str(c['name']) + "," new.append(getDB("http://127.0.0.1:8000/api/classes/" + str(cid))) - self.snew=snew - self.new=new + self.snew = snew + self.new = new break - - #update teacher instance in db, classes field - data={ - 'user':self.user, - 'added_to':self.snew, - 'classes':self.sclass + + # update teacher instance in db, classes field + data = { + 'user': self.user, + 'added_to': self.snew, + 'classes': self.sclass } print(self.url) print(patchDB(data, self.url)) return data - + def submit(self, path): - #2022rkhondak/English11_eharris1/Essay1 - #check if valid assignment + # 2022rkhondak/English11_eharris1/Essay1 + # check if valid assignment parts = path.split("/") - if(len(parts) != 3): + if (len(parts) != 3): print("Assignment path too short") return isclass = False - for c in self.classes: - if(c['name'] == parts[1]): - isclass==True + for c in self.classes: + if (c['name'] == parts[1]): + isclass == True break - if(parts[0] != self.username and isclass and os.path.isdir(path) == False): + if (parts[0] != self.username and isclass and os.path.isdir(path) == False): print("Not valid assignment") return - if((parts[1] + "/" + parts[2]) in self.completed): + if ((parts[1] + "/" + parts[2]) in self.completed): print(parts[2] + " already submited. ") # return resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ") - if(resp == 'y'): + if (resp == 'y'): os.chdir(self.username + "/" + parts[1]) command("git add .") command("git commit -m submit") command("git tag " + parts[1] + "-final") command("git push -u origin " + self.username + " --tags") self.completed = self.completed + "," + parts[1] + "/" + parts[2] - data={ - 'user':self.user, - 'git':self.git, - 'ion_user':self.username, - 'student_id':self.student_id, - 'added_to':self.snew, - 'url':self.url, - 'classes':self.sclass, - 'grade':self.grade, - 'completed':self.completed + data = { + 'user': self.user, + 'git': self.git, + 'ion_user': self.username, + 'student_id': self.student_id, + 'added_to': self.snew, + 'url': self.url, + 'classes': self.sclass, + 'grade': self.grade, + 'completed': self.completed } - #print(putDB(data, "http://127.0.0.1:8000/api/students/" + self.username + "/")) - + # print(putDB(data, "http://127.0.0.1:8000/api/students/" + self.username + "/")) + def viewClass(self, courses): self.update() cdir = os.getcwd() @@ -335,12 +343,12 @@ class Student: os.chdir(cdir) print("Class not found") return - + def exitCLI(self): print(os.getcwd()) self.update() command("git checkout master") - + def submit(self, course, assignment): cdir = os.getcwd() os.chdir(self.username) @@ -355,7 +363,7 @@ class Student: if a == assignment: inclass = True break - if(inclass == False): + if (inclass == False): print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) @@ -369,6 +377,7 @@ class Student: command('git checkout master') os.chdir(cdir) + # data = getStudent("2022rkhondak") # s = Student(data) # s.viewClass("APLit_eharris1") @@ -379,6 +388,7 @@ class Student: def main(): pass + if __name__ == "__main__": - # stuff only to run when not called via 'import' here - main() + # stuff only to run when not called via 'import' here + main() diff --git a/CLI/teacher.py b/CLI/teacher.py index 08f0a70..cfdc0a9 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -8,7 +8,9 @@ import shutil import time import pyperclip from distutils.dir_util import copy_tree -from datetime import datetime +from datetime import datetime + + # from django.conf import settings # import django @@ -21,211 +23,250 @@ from datetime import datetime # django.setup() # from ..Website.api.models import * -#git clone student directory ==> /classes/assignments +# git clone student directory ==> /classes/assignments -#get teacher info from api +# get teacher info from api def getTeacher(ion_user): - URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" - r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) - if(r.status_code == 200): - data = r.json() - return data - elif(r.status_code == 404): - return None - print("Make new account!") - elif(r.status_code == 403): - return None - print("Invalid username/password") - else: - return None - print(r.status_code) + """ + Gets information about a teacher from the api + :param ion_user: a teacher + :return: teacher information or error + """ + URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" + r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) + if r.status_code == 200: + data = r.json() + return data + elif r.status_code == 404: + return None + print("Make new account!") + elif r.status_code == 403: + return None + print("Invalid username/password") + else: + return None + print(r.status_code) + def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) + """ + 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)) - return(r.json()) + return r.json() + + def patchDB(data, url): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a PATCH request to the URL + :param data: + :param url: URL for request + """ + r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PATCH:" + str(r.status_code)) - return(r.json()) + return r.json() + def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a POST request to the URL + :param data: + :param url: URL for request + """ + r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("POST:" + str(r.status_code)) - return(r.json()) + return r.json() + def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a PUT request to the URL + :param data: + :param url: URL for request + """ + r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) - return(r.json()) + return r.json() + def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + """ + Sends a DELETE request to the URL + :param url: URL for request + """ + r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) print("DELETE:" + str(r.status_code)) return None + def command(command): ar = [] command = command.split(" ") for c in command: ar.append(c) - process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() + process = subprocess.Popen(ar, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = process.poll() output = process.communicate()[1] print(output.decode('utf-8')) + #################################################################################################################################### -#public methods: deleteClass, makeClass, update +# public methods: deleteClass, makeClass, update class Teacher: def __init__(self, data): # teacher info already stored in API # intitialze fields after GET request - self.git=data['git'] - self.username=data['ion_user'] - self.url= "http://127.0.0.1:8000/api/teachers/" + self.username + "/" + """ + Initializes a Teacher with the data from the api + :param data: api data + """ + self.git = data['git'] + self.username = data['ion_user'] + self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/" self.id = data['user'] - #classes in id form (Example: 4,5) - - #array - self.classes=data['classes'] - if(os.path.isdir(self.username + "/Students")): - print("Synced to " + self.username) + # classes in id form (Example: 4,5) + + # array + self.classes = data['classes'] + if os.path.isdir(self.username + "/Students"): + print("Synced to " + self.username) else: os.makedirs(self.username + "/Students") - #2020-05-11 12:25:00 + # 2020-05-11 12:25:00 - + # class name format: _ - #class name format: _ - - #turn existing directory into class, Pre-condition: directory exists - #relative path to class: 2022rkhondak/Math4 - def checkClass(self,path): + # turn existing directory into class, Pre-condition: directory exists + # relative path to class: 2022rkhondak/Math4 + def checkClass(self, path): cname = path.split("/") - cname = cname[len(cname)-1] - if(os.path.isfile(path)): + cname = cname[len(cname) - 1] + if os.path.isfile(path): print(path + " must be in a Class directory.") return False - if(("_" + self.username) in cname) == False: - print("Incorrect class name: Must be in the format: " + self.username+ "/_, not " + path) + if not (("_" + self.username) in cname): + print( + "Incorrect class name: Must be in the format: " + self.username + "/_, not " + path) return False dirs = os.listdir(path) - #checks if there is a file (not within Assignments) in class, need at least 1 + # checks if there is a file (not within Assignments) in class, need at least 1 deffile = False - #checks if there is a file in an Assignment, need at least 1 (default True in case no assignments) + # checks if there is a file in an Assignment, need at least 1 (default True in case no assignments) as_file = True as_bad = "" for d in dirs: - if(os.path.isfile(d)): - deffile=True + if os.path.isfile(d): + deffile = True else: - #checks if there is a file in an Assignment, need at least 1 + # checks if there is a file in an Assignment, need at least 1 as_file = False asdir = os.listdir(path + "/" + d) for a in asdir: - if(os.path.isfile(path + "/" + d + "/" +a)): - as_file=True - if(as_file==False): + if os.path.isfile(path + "/" + d + "/" + a): + as_file = True + if not as_file: as_bad = d break - if(as_file==False): + if not as_file: print("Assignment '" + as_bad + "' does not have a default file!") return False - if(deffile==False): + if not deffile: print("Need a default file in the " + path + " Directory!") - return False + return False return True - + def checkInDB(self, path): - n = path.split("/") - n = n[len(n)-1] + n = path.split("/") + n = n[len(n) - 1] for c in self.classes: - if(n == c['name']): + if n == c['name']: return True return False - #make class from existing directory, add to git and api + # make class from existing directory, add to git and api def addClass(self, path): cname = path.split("/") - cname = cname[len(cname)-1] + 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): cpath = self.username + "/" + cname data = { "name": cname, "repo": "", "path": cpath, "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/') self.classes.append(cname) - #add to instance - #upate self.classes + # add to instance + # update self.classes data = { - 'classes':self.classes + 'classes': self.classes } 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 - #class name must be: _ + # make a new class from scratch + # subject: string, assignments: list + # class name must be: _ def makeClass(self, cname): - #check if class exists + # check if class exists path = self.username + "/" + cname isclass = False acourses = getDB("http://127.0.0.1:8000/api/classes/")['results'] for c in acourses: if c['name'] == cname: - isclass=True + isclass = True break - if(os.path.exists(path) or isclass): + if os.path.exists(path) or isclass: print("Class already exists: " + cname) - if(isclass): + if isclass: print("Class already exists in Database") return else: - if((("_" + self.username) in cname) == False): - print("class name must be: "+ cname + "_" + self.username) + if not (("_" + self.username) in cname): + print("class name must be: " + cname + "_" + self.username) return cdir = os.getcwd() os.mkdir(path) - f=open(path + "/README.md", "w") + f = open(path + "/README.md", "w") f.close() - #push to remote repo + # push to remote repo # os.chdir(path) # for a in assignments: - + # os.mkdir(a) # f=open(a + "/instructions.txt", "w") # f.close() # os.chdir(cdir) self.addClass(path) - + def deleteClass(self, path): - if(os.path.exists(path) == False): + if not os.path.exists(path): print(path + " does not exist locally.") resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ") - if(resp != 'y'): + if resp != 'y': return cname = path.split("/") - cname = cname[len(cname)-1] + cname = cname[len(cname) - 1] repo = '' print("DELETE: " + self.classes[i]['name']) for i in range(len(self.classes)): c = self.classes[i] - if(c == cname): + if c == cname: del self.classes[i] # data={ # 'classes':self.classes, @@ -233,94 +274,95 @@ class Teacher: # print(patchDB(data, self.url)) delDB("http://127.0.0.1:8000/api/classes/" + cname + "/") break - - #remove locally + + # remove locally try: shutil.rmtree(path) except: pass - - #remove from student directories + # remove from student directories def isStudent(self, student): - r = requests.get(url = "http://127.0.0.1:8000/api/students/" + student + "/", auth=('raffukhondaker','hackgroup1')) - if(r.status_code != 200): + r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/", + auth=('raffukhondaker', 'hackgroup1')) + if r.status_code != 200: return False return True def reqStudent(self, sname, cname): - if(self.isStudent(sname) == False): + if not self.isStudent(sname): 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.") + if sname in str(course['unconfirmed']): + print(sname + " already requested.") return True - if(sname in str(course['confirmed'])): - print (sname + " alredy enrolled.") + if sname in str(course['confirmed']): + print(sname + " already enrolled.") return False - + student = getDB("http://127.0.0.1:8000/api/students/" + sname) try: - if(student['added_to']==""): - student['added_to']=course['name'] + if student['added_to'] == "": + student['added_to'] = course['name'] else: - student['added_to']=student['added_to']+ "," + course['name'] + 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'], + 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'] + student = getDB("http://localhost:8000/api/students/" + sname + "/") + if not course['unconfirmed']: + course['unconfirmed'] = student['ion_user'] else: - course['unconfirmed']=course['unconfirmed'].append(student['ion_user']) + course['unconfirmed'] = course['unconfirmed'].append(student['ion_user']) cinfo = { "unconfirmed": course['unconfirmed'] } 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 - #git clone confirmed student repo, copy files into repo and push branch + + # Student should have confirmed on their endd, but class had not been updated yet + # git clone confirmed student repo, copy files into repo and push branch def addStudent(self, sname, cname): - if(self.isStudent(sname) == False): + if not self.isStudent(sname): print(sname + " does not exist.") return False student = getDB("http://127.0.0.1:8000/api/students/" + sname) course = getDB("http://127.0.0.1:8000/api/classes/" + cname) - if(os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (student['ion_user'] in course['confirmed']) == True): + if (os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or ( + student['ion_user'] in course['confirmed']) == True): print(student['ion_user'] + " already added to class") return True - if((cname in student['added_to']) == True or (cname in student['classes']) == False): - print(student['ion_user']+ " has not confirmed class yet") + if (cname in student['added_to']) or not (cname in student['classes']): + print(student['ion_user'] + " has not confirmed class yet") return False - if((student['ion_user'] in course['unconfirmed']) == False): + if not (student['ion_user'] in course['unconfirmed']): print(course['unconfirmed']) - print(student['ion_user']+" has not been requested to join yet.") + print(student['ion_user'] + " has not been requested to join yet.") return False - - #git clone and make student/class directories + + # git clone and make student/class directories cdir = os.getcwd() cpath = self.username + "/" + cname path = self.username + "/Students/" + cname spath = self.username + "/Students/" + cname + "/" + student['ion_user'] - if(os.path.isdir(path) == False): + if not os.path.isdir(path): os.makedirs(path) - if(os.path.isdir(spath) == False): + if not os.path.isdir(spath): os.chdir(path) command("git clone " + student['repo']) os.chdir(cdir) - #push to git + # push to git os.chdir(spath) command('git checkout ' + cname) command('git pull origin ' + cname) @@ -332,15 +374,15 @@ class Teacher: command('git push -u origin ' + cname) os.chdir(cdir) - if(course['confirmed']==[]): - course['confirmed']=student['ion_user'] + if not course['confirmed']: + course['confirmed'] = student['ion_user'] else: course['confirmed'].append(student['ion_user']) - #only 1 pereson on confirmeed - if(len(course['unconfirmed']) == 1): - course['unconfirmed']=[] - #mutiple + # only 1 pereson on confirmeed + if len(course['unconfirmed']) == 1: + course['unconfirmed'] = [] + # mutiple else: course['unconfirmed'].remove(student['ion_user']) @@ -351,34 +393,34 @@ class Teacher: print(putDB(course, "http://localhost:8000/api/classes/" + course['name'] + "/")) 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 def reqAddStudentList(self, array, cname): unconf = [] for i in range(len(array)): a = array[i] - if(self.addStudent(a, cname) == False): + if not self.addStudent(a, cname): self.reqStudent(a, cname) unconf.append(a) return unconf - #add local path to student directory, make new instance in api + # add local path to student directory, make new instance in api def addAssignment(self, path, course, due): parts = path.split("/") - aname = parts[len(parts)-1] - oname = aname + "_" + course + aname = parts[len(parts) - 1] + oname = aname + "_" + course - if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in str(self.classes): + 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 str(self.classes)) == False): + if not (parts[1] in str(self.classes)): print("Not in valid class directory") return False - #parts of assignment name (Essay1, APLit) + # parts of assignment name (Essay1, APLit) # if((course in aname) == False): # print("Assignment named incorrectly; could be "+ aname + "_" + course) # return False - - ar = [x[2] for x in os.walk(path)] + + ar = [x[2] for x in os.walk(path)] print(ar) for folder in ar: if len(folder) == 0: @@ -393,25 +435,25 @@ class Teacher: except: print("Due-date format is incorrect") return False - + course = getDB("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.") return False print(course['assignments']) print(aname) #################### FINISH VERIFYING - if(os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']) == False): + if not os.path.exists(os.getcwd() + "/" + self.username + "/Students/" + course['name']): print("No students in this class yet") return True slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name']) cdir = os.getcwd() for st in slist: if st in str(course['confirmed']): - spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st) - if(os.path.exists(spath + "/" + aname) == False): - os.mkdir(spath + "/" + aname) + spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st) + if not os.path.exists(spath + "/" + aname): + os.mkdir(spath + "/" + aname) print(st) print(copy_tree(path, spath + "/" + aname)) os.chdir(spath) @@ -423,20 +465,20 @@ class Teacher: os.chdir(cdir) else: print(st + " already has assignment") - - #check if assignment already exists - r = requests.get(url = 'http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker','hackgroup1')) - if(r.status_code != 200): + + # check if assignment already exists + r = requests.get(url='http://127.0.0.1:8000/api/assignments/' + aname, auth=('raffukhondaker', 'hackgroup1')) + if r.status_code != 200: ass = { 'name': oname, - 'path':path, - 'classes':course['name'], - 'teacher':self.username, - 'due_date':due + 'path': path, + 'classes': course['name'], + 'teacher': self.username, + 'due_date': due } postDB(ass, 'http://127.0.0.1:8000/api/assignments/') course['assignments'].append(oname) - + cinfo = { "assignments": course['assignments'], } @@ -445,21 +487,21 @@ class Teacher: else: print("Assignment already addedd") return True - - #try to avoid - #copy modified assignments to student directories + + # try to avoid + # copy modified assignments to student directories def updateAssignment(self, path, course, due): parts = path.split("/") - aname = parts[len(parts)-1] - oname=aname + "_" + course - if(os.path.isdir(path) == False): + aname = parts[len(parts) - 1] + oname = aname + "_" + course + if not os.path.isdir(path): print(path + " is not an assignment.") return try: - if(due != None or due == ""): + if due != None or due == "": datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') d = { - 'due_date':due, + 'due_date': due, } print(patchDB(d, 'http://localhost:8000/api/assignments/' + oname + "/")) print("Due-date changed " + due) @@ -471,23 +513,23 @@ class Teacher: cdir = os.getcwd() for st in slist: if st in course['confirmed']: - spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st) + spath = os.path.join(os.getcwd() + "/" + self.username + "/Students/" + course['name'], st) print(st) print(copy_tree(path, spath + "/" + aname)) os.chdir(spath) - #command('git checkout ' + course['name']) + # command('git checkout ' + course['name']) command('git add .') command('git commit -m Hello') command('git pull origin ' + course['name']) command('git push -u origin ' + course['name']) os.chdir(cdir) - #pull student's work, no modifications + # pull student's work, no modifications def getStudents(self, course): - if((course in self.sclass) == False): + if not (course in self.sclass): print(course + " not a class.") return - path = self.username + "/Students/" + course + path = self.username + "/Students/" + course slist = os.listdir(path) cdir = os.getcwd() for st in slist: @@ -499,7 +541,7 @@ class Teacher: def getCommits(self, student, course, commits): course = getDB("http://127.0.0.1:8000/api/classes/" + course) try: - if((student in course['confirmed']) == False): + if not (student in course['confirmed']): print("Student not in class") return except: @@ -508,19 +550,20 @@ class Teacher: cdir = os.getcwd() os.chdir(self.username + "/Students/" + course['name'] + "/" + student) - process = subprocess.Popen(['git', 'log', '-' + str(commits), course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() + process = subprocess.Popen(['git', 'log', '-' + str(commits), course['name']], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + p = process.poll() output = process.communicate()[0].decode('utf-8').split('\n\n') months = ['Jan', 'Feb', 'Mar', "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"] fout = [] for i in range(len(output)): - if("Date" in output[i]): + if "Date" in output[i]: c = output[i].split("\n") for k in range(len(c)): temp = [] - if('commit' in c[k]): + if 'commit' in c[k]: c[k] = c[k].replace('commit', '').strip() - elif('Date:' in c[k]): + elif 'Date:' in c[k]: c[k] = c[k].replace('Date:', '').strip() date = c[2].split(" ") times = date[3].split(":") @@ -529,38 +572,40 @@ class Teacher: if date[1] == months[m]: mon = m d1 = datetime(int(date[4]), mon, int(date[2]), int(times[0]), int(times[1])) - #datetime1 = datetime.strptime('07/11/2019 02:45PM', '%m/%d/%Y %I:%M%p') - fout.append([c[0],d1]) - #output[i] = [c[0], d1] - #print(output[i]) + # datetime1 = datetime.strptime('07/11/2019 02:45PM', '%m/%d/%Y %I:%M%p') + fout.append([c[0], d1]) + # output[i] = [c[0], d1] + # print(output[i]) print(fout) os.chdir(cdir) return fout - + def getChanges(self, student, course, commits): course = getDB("http://127.0.0.1:8000/api/classes/" + course + "/") ar = self.getCommits(student, course['name'], commits) - commit = ar[len(ar)-1][0] + commit = ar[len(ar) - 1][0] start = "" print("END:" + commit) print("START: " + start) cdir = os.getcwd() os.chdir(self.username + "/Students/" + course['name'] + "/" + student) - process = subprocess.Popen(['git', 'diff', commit, '--name-status'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() + process = subprocess.Popen(['git', 'diff', commit, '--name-status'], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + p = process.poll() output = process.communicate()[0].decode('utf-8') print(output) os.chdir(cdir) - + ''' assignment = { 'name': English11_eharris1, 'due_date': 2020-06-11 16:58:33.383124 } ''' - #check if assignment changed after due date + # check if assignment changed after due date + def afterSubmit(self, course, assignment, student): - + assignment = getDB("http://127.0.0.1:8000/api/assignments/" + assignment) # assignment = { # 'name': assignment, @@ -573,14 +618,14 @@ class Teacher: cdir = os.getcwd() os.chdir(self.username + "/Students/" + course + "/" + student) for l in log: - process = subprocess.Popen(['git', 'show', l[0]], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - p=process.poll() + process = subprocess.Popen(['git', 'show', l[0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = process.poll() output = process.communicate()[0].decode('utf-8') - if(assignment['name'] in output): + if assignment['name'] in output: print(l[1]) print(assignment['due_date']) print("--------------") - if(l[1] > assignment['due_date']): + if l[1] > assignment['due_date']: print("LATE") os.chdir(cdir) return True @@ -594,12 +639,12 @@ class Teacher: # data = getTeacher("eharris1") # t = Teacher(data) -#t.makeClass("APLit_eharris1") +# t.makeClass("APLit_eharris1") # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') -#ar = ['2022rkhondak','2022inafi','2023rumareti'] -#extra = t.reqAddStudentList(ar, "APLit_eharris1") -#print(extra) -#t.addStudent('2022rkhondak', 'APLit_eharris1') +# ar = ['2022rkhondak','2022inafi','2023rumareti'] +# extra = t.reqAddStudentList(ar, "APLit_eharris1") +# print(extra) +# t.addStudent('2022rkhondak', 'APLit_eharris1') # t.getChanges('2022rkhondak','APLit_eharris1', 10) ''' @@ -614,4 +659,3 @@ TO-DO - check differences between commits - check if student changes file after submissionn deadline ''' - From 6056bc6e113ca93156eb9ae315f5e6173b621d89 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 16:01:11 -0400 Subject: [PATCH 05/40] basicc cli cocmpleted --- CLI/student.py | 21 +++++++++++---------- skoolos.py | 50 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index 3281fda..badc6bb 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -227,17 +227,18 @@ class Student: os.system(url) cdir = os.getcwd() - path1 = self.username + "/" + self.username - path2 = self.username - if(os.path.isdir(path1)): - os.chdir(path1) - else: - os.chdir(self.username) - command("git clone " + self.repo) - os.chdir(self.username) + os.chdir(self.username) + # path1 = self.username + "/" + self.username + # path2 = self.username + # if(os.path.isdir(path1)): + # os.chdir(path1) + # else: + # os.chdir(self.username) + # command("git clone " + self.repo) + # os.chdir(self.username) #push to git, start at master - os.chdir(self.username) + #os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") @@ -335,7 +336,7 @@ class Student: if c['name'] == courses: command("git checkout " + courses) print(os.listdir()) - break + return os.chdir(cdir) print("Class not found") return diff --git a/skoolos.py b/skoolos.py index c35c68e..0e33c8d 100644 --- a/skoolos.py +++ b/skoolos.py @@ -47,12 +47,29 @@ def main(): #webbrowser.open("http://127.0.0.1:8000/login", new=2) authenticate() else: - try: - f = open('.tprofile','r') - except: - f = open('.sprofile','r') - data = json.loads(f.read()) - f.close() + profiles = os.listdir() + users = [] + info = [] + count = 1 + for i in range(len(profiles)): + p = profiles[i] + if('profile' in p): + f = open(p,'r') + d = json.loads(f.read()) + f.close() + info.append(d) + users.append(str(count) + ") " + d['username']) + count = count+1 + user = [ + { + 'type': 'list', + 'name': 'user', + 'choices':users, + 'message': 'Select User: ', + }, + ] + u = int(prompt(user)['user'].split(")")[0]) -1 + data = info[u] PWD = data['password'] USER = data['username'] print(data['username']) @@ -68,6 +85,7 @@ def studentCLI(user, password): from CLI import student data = getUser(user, password, 'student') student = student.Student(data) + student.update() carray = student.sclass.split(",") if(len(carray) == 1 and carray[0] == ""): print("No classes") @@ -90,6 +108,10 @@ def studentCLI(user, password): student.viewClass(course) student.getAssignments(course, 100) +################################################ STUDENT METHODS + +################################################ TEACHER METHODS + def teacherCLI(user, password): from CLI import teacher data = getUser(user, password, 'teacher') @@ -157,7 +179,7 @@ def teacherCLI(user, password): unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] for s in unconf: teacher.addStudent(s, course) - options = ['1) Request Student', "2) Add assignment", "3) View student information"] + options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] questions = [ { 'type': 'list', @@ -206,7 +228,7 @@ def teacherCLI(user, password): students = f.read().splitlines() teacher.reqAddStudentList(students, course) else: - sys.exit() + sys.exit(0) if(option == '2'): nlist = os.listdir(teacher.username + "/" + course) alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] @@ -241,8 +263,18 @@ def teacherCLI(user, password): ass = prompt(questions)['assignment'] apath = teacher.username + "/" + course + "/" + ass due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":00.000000" + due = due + ":33.383124" due = due.strip() + f = False + while(not f): + try: + datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + f = True + except: + print("Due-date format is incorrect.") + print(due) + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" teacher.addAssignment(apath, course, due) From 4241f51fa0d66c3391c16a4cbbe3a48d732967f9 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 16:15:47 -0400 Subject: [PATCH 06/40] finished studdent cli --- CLI/student.py | 1 + skoolos.py | 44 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index badc6bb..ee16251 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -336,6 +336,7 @@ class Student: if c['name'] == courses: command("git checkout " + courses) print(os.listdir()) + os.chdir(cdir) return os.chdir(cdir) print("Class not found") diff --git a/skoolos.py b/skoolos.py index 0e33c8d..34d30ea 100644 --- a/skoolos.py +++ b/skoolos.py @@ -86,10 +86,19 @@ def studentCLI(user, password): data = getUser(user, password, 'student') student = student.Student(data) student.update() + EXIT = False + while(not EXIT): + course = chooseClassStudent(student) + EXIT = classOptionsStudent(student, course) + + +################################################ STUDENT METHODS +#return class +def chooseClassStudent(student): carray = student.sclass.split(",") if(len(carray) == 1 and carray[0] == ""): + carray.remove("") print("No classes") - return carray.append("Exit SkoolOS") courses = [ @@ -102,14 +111,35 @@ def studentCLI(user, password): ] course = prompt(courses)['course'] print(course) - if course == "Exit SkoolOS": + return course + +def classOptionsStudent(student, course): + student.viewClass(course) + student.getAssignments(course, 100) + choices = ["Save","Back","Exit SkoolOS"] + options = [ + { + 'type': 'list', + 'name': 'option', + 'choices':choices, + 'message': 'Select: ', + }, + ] + option = prompt(options)['option'] + if(option == "Save"): + student.update() + print("Saved!") + classOptionsStudent(student, course) + if(option == "Back"): student.exitCLI() - else: - student.viewClass(course) - student.getAssignments(course, 100) - -################################################ STUDENT METHODS + #dont exit cli + return False + if(option == "Exit SkoolOS"): + student.exitCLI() + #exit cli + return True + ################################################ TEACHER METHODS def teacherCLI(user, password): From f7624c3284e0fc3c6247a5b1a28aca9212f8c924 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 16:19:20 -0400 Subject: [PATCH 07/40] basic student cli done --- CLI/teacher.py | 3 --- skoolos.py | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CLI/teacher.py b/CLI/teacher.py index 2ba3032..f2b2de3 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -595,9 +595,6 @@ class Teacher: os.chdir(cdir) return False - def comment(self): - print("heheheh") - # data = getTeacher("eharris1") # t = Teacher(data) diff --git a/skoolos.py b/skoolos.py index 34d30ea..e11c15a 100644 --- a/skoolos.py +++ b/skoolos.py @@ -78,9 +78,8 @@ def main(): else: teacherCLI(USER, PWD) +################################################ STUDENT METHODS - # while True: - # pass def studentCLI(user, password): from CLI import student data = getUser(user, password, 'student') @@ -91,8 +90,6 @@ def studentCLI(user, password): course = chooseClassStudent(student) EXIT = classOptionsStudent(student, course) - -################################################ STUDENT METHODS #return class def chooseClassStudent(student): carray = student.sclass.split(",") @@ -141,6 +138,22 @@ def classOptionsStudent(student, course): ################################################ TEACHER METHODS +def chooseGeneralTeacher(teacher): + carray = [] + for c in teacher.classes: + carray.append(c) + carray.append("Make New Class") + carray.append("Exit SkoolOS") + courses = [ + { + 'type': 'list', + 'name': 'course', + 'choices':carray, + 'message': 'Select class: ', + }, + ] + course = prompt(courses)['course'] + return course def teacherCLI(user, password): from CLI import teacher @@ -307,6 +320,8 @@ def teacherCLI(user, password): due = due + ":33.383124" teacher.addAssignment(apath, course, due) +###################################################################### + def getUser(ion_user, password, utype): if('student' in utype): From 13d248202bddbc9342a1778ccfa985248e786daf Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 16:20:43 -0400 Subject: [PATCH 08/40] put back hehehhe --- CLI/teacher.py | 3 +++ skoolos.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CLI/teacher.py b/CLI/teacher.py index f2b2de3..2ba3032 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -595,6 +595,9 @@ class Teacher: os.chdir(cdir) return False + def comment(self): + print("heheheh") + # data = getTeacher("eharris1") # t = Teacher(data) diff --git a/skoolos.py b/skoolos.py index e11c15a..2941c21 100644 --- a/skoolos.py +++ b/skoolos.py @@ -178,7 +178,7 @@ def teacherCLI(user, password): 'message': 'Select class: ', }, ] - course = prompt(courses)['course'] + course = chooseGeneralTeacher(teacher) if course == "Exit SkoolOS": teacher.exitCLI() if course == "Make New Class": From 43d22a6991d3eb9e4e25789572f168c4cb9bcf49 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 16:20:50 -0400 Subject: [PATCH 09/40] finished documenting teacher.py --- CLI/teacher.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/CLI/teacher.py b/CLI/teacher.py index d1f3f4d..c332b3f 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -105,6 +105,10 @@ def delDB(url): def command(command): + """ + Runs a shell command + :param command: shell command + """ ar = [] command = command.split(" ") for c in command: @@ -146,6 +150,10 @@ class Teacher: # turn existing directory into class, Pre-condition: directory exists # relative path to class: 2022rkhondak/Math4 def checkClass(self, path): + """ + Checks if a directory is valid for creating a class + :param path: path to the new class directory + """ cname = path.split("/") cname = cname[len(cname) - 1] if os.path.isfile(path): @@ -185,6 +193,10 @@ class Teacher: return True def checkInDB(self, path): + """ + Checks if "path" is in the database + :param path: path to directory + """ n = path.split("/") n = n[len(n) - 1] for c in self.classes: @@ -194,6 +206,10 @@ class Teacher: # make class from existing directory, add to git and api def addClass(self, path): + """ + Creates a class from an existing directory, adding it to the proper git repository and the api + :param path: + """ cname = path.split("/") cname = cname[len(cname) - 1] for c in self.classes: @@ -225,6 +241,10 @@ class Teacher: # subject: string, assignments: list # class name must be: _ def makeClass(self, cname): + """ + Makes a class with its own new directory + :param cname: name of class + """ # check if class exists path = self.username + "/" + cname isclass = False @@ -258,6 +278,10 @@ class Teacher: self.addClass(path) def deleteClass(self, path): + """ + Deletes an existing class + :param path: class directory path + """ if not os.path.exists(path): print(path + " does not exist locally.") resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ") @@ -288,6 +312,11 @@ class Teacher: # remove from student directories def isStudent(self, student): + """ + Checks if the student exists + :param student: a student + :return: True if student exists, False otherwise + """ r = requests.get(url="http://127.0.0.1:8000/api/students/" + student + "/", auth=('raffukhondaker', 'hackgroup1')) if r.status_code != 200: @@ -295,6 +324,12 @@ class Teacher: return True def reqStudent(self, sname, cname): + """ + Request student informatiion from the api + :param sname: student's name + :param cname: class name + :return: True if successful + """ if not self.isStudent(sname): print(sname + " does not exist.") return False @@ -335,6 +370,12 @@ class Teacher: # Student should have confirmed on their endd, but class had not been updated yet # git clone confirmed student repo, copy files into repo and push branch def addStudent(self, sname, cname): + """ + Adds a student to a class + :param sname: student name + :param cname: class name + :return: + """ if not self.isStudent(sname): print(sname + " does not exist.") return False @@ -399,6 +440,12 @@ class Teacher: # goes through list of studennts, tries to add, then request, return unconfirmed students def reqAddStudentList(self, array, cname): + """ + Runs addStudent() on all students in array + :param array: an array of students + :param cname: class name + :return: students that have not confirmed the request + """ unconf = [] for i in range(len(array)): a = array[i] @@ -409,6 +456,13 @@ class Teacher: # add local path to student directory, make new instance in api def addAssignment(self, path, course, due): + """ + Creates an assignment for "course" that is due on "due" + :param path: directory of assignment + :param course: course name + :param due: due date + :return: False if unsuccessful + """ parts = path.split("/") aname = parts[len(parts) - 1] oname = aname + "_" + course @@ -585,6 +639,12 @@ class Teacher: return fout def getChanges(self, student, course, commits): + """ + Checks for new submissions by a student + :param student: the student + :param course: the course + :param commits: commits the CLI has made for the assignment + """ course = getDB("http://127.0.0.1:8000/api/classes/" + course + "/") ar = self.getCommits(student, course['name'], commits) commit = ar[len(ar) - 1][0] @@ -638,6 +698,10 @@ class Teacher: return False def comment(self): + """ + The ultimate form of laughter + :return: pure joy + """ print("heheheh") From 2d58262a8d89e2d37d7d8da7aee4b46ba1e5f3bf Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 16:28:17 -0400 Subject: [PATCH 10/40] Started on createAssignment and createClass --- Website/api/models.py | 21 +++--- Website/skoolos/forms.py | 53 ++++++++++++- Website/skoolos/templates/skoolos/base.html | 6 ++ .../templates/skoolos/class_detail.html | 8 ++ .../templates/skoolos/createClass.html | 26 +++++++ Website/skoolos/templates/skoolos/home.html | 6 ++ .../templates/skoolos/profile_student.html | 3 + .../templates/skoolos/profile_teacher.html | 3 + Website/skoolos/urls.py | 2 + Website/skoolos/views.py | 75 +++++++++++++++---- 10 files changed, 177 insertions(+), 26 deletions(-) create mode 100644 Website/skoolos/templates/skoolos/createClass.html diff --git a/Website/api/models.py b/Website/api/models.py index 9dc22f2..d62f9dc 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -18,31 +18,32 @@ class Student(models.Model): super(Student, self).save(*args, **kwargs) 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): owner = models.ForeignKey(User, null=True, blank=True, related_name='aowner', on_delete=models.CASCADE) - name=models.CharField(max_length=100, primary_key=True) due_date=models.DateTimeField() # files = models.ManyToManyField(DefFiles) files=models.CharField(max_length=100, default="", blank=True) - path=models.CharField(max_length=100) - classes=models.CharField(max_length=100) - teacher=models.CharField(max_length=100) + path=models.CharField(max_length=100, default="", blank=True) + classes=models.CharField(max_length=100, default="", blank=True) + teacher=models.CharField(max_length=100, default="", blank=True) def __str__(self): - return '%s' % (self.name) + return f'{self.name}' class Class(models.Model): 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) 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) - path=models.CharField(max_length=100, default="") + path=models.CharField(max_length=100, default="", blank=True) assignments=models.ManyToManyField(Assignment, blank=True) default_file=models.CharField(max_length=100, default="", blank=True) confirmed=models.ManyToManyField(Student, blank=True, related_name='confirmed') @@ -60,7 +61,7 @@ class Class(models.Model): return super(Class, self).save(*args, **kwargs) def __str__(self): - return self.name + return f"{self.user.first_name} {self.user.last_name} ({self.user.username})" class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) diff --git a/Website/skoolos/forms.py b/Website/skoolos/forms.py index 6374f97..e249d96 100644 --- a/Website/skoolos/forms.py +++ b/Website/skoolos/forms.py @@ -1,6 +1,6 @@ from django import forms from django.contrib.auth.models import User -from api.models import Student, Teacher +from api.models import Student, Teacher, Class, Assignment import re class UserUpdateForm(forms.ModelForm): @@ -26,3 +26,54 @@ class TeacherUpdateForm(forms.ModelForm): class Meta: model = Teacher 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, commit=True): + # Get the unsave Pizza instance + instance = forms.ModelForm.save(self, False) + + # Prepare a 'save_m2m' method for the form, + old_save_m2m = self.save_m2m + def save_m2m(): + old_save_m2m() + # This is where we actually link the pizza with toppings + instance.topping_set.clear() + instance.topping_set.add(*self.cleaned_data['unconfirmed']) + self.save_m2m = save_m2m + + # Do we need to save all changes now? + if commit: + instance.save() + self.save_m2m() + + return instance + + class Meta: + model = Class + fields = ['subject', 'period', 'description', 'unconfirmed'] diff --git a/Website/skoolos/templates/skoolos/base.html b/Website/skoolos/templates/skoolos/base.html index 2ec152d..fa2f42c 100644 --- a/Website/skoolos/templates/skoolos/base.html +++ b/Website/skoolos/templates/skoolos/base.html @@ -34,6 +34,12 @@ + {% empty %} + {% if isTeacher %} +

Looks like you haven't made any assignments yet, hit the button in the top right to get started

+ {% else %} +

Looks like there aren't any assignments at the moment, you got lucky this time!

+ {% endif %} {% endfor %} @@ -20,6 +26,8 @@
    {% for teacher in teachers %}
  • {{ teacher.user.first_name }} {{ teacher.user.last_name }} ({{teacher.ion_user}})
  • + {% empty %} +
  • No Teachers, weird...
  • {% endfor %}
diff --git a/Website/skoolos/templates/skoolos/createClass.html b/Website/skoolos/templates/skoolos/createClass.html new file mode 100644 index 0000000..4acb8f9 --- /dev/null +++ b/Website/skoolos/templates/skoolos/createClass.html @@ -0,0 +1,26 @@ +{% extends "skoolos/base.html" %} +{% load crispy_forms_tags %} +{% block content %} + Classes +
    + {% for class in classes %} +
  • {{ class.name }}
  • + {% empty %} +
  • Not teaching any classes
  • + {% endfor %} +
+
+ {% csrf_token %} +
+ Create a new class + {{ classForm|crispy }} + + Use ctrl to select multiple students +
+
+ +
+
+ + +{% endblock content %} diff --git a/Website/skoolos/templates/skoolos/home.html b/Website/skoolos/templates/skoolos/home.html index 6822cb6..45dfedc 100644 --- a/Website/skoolos/templates/skoolos/home.html +++ b/Website/skoolos/templates/skoolos/home.html @@ -10,6 +10,12 @@ + {% empty %} + {% if isTeacher %} +

Looks like you haven't created any classes yet, hit the button in the top right to get started.

+ {% else %} +

Looks like you're not enrolled in any classes at the moment! Ask your teacher if you think this is wrong.

+ {% endif %} {% endfor %} {% endblock content %} diff --git a/Website/skoolos/templates/skoolos/profile_student.html b/Website/skoolos/templates/skoolos/profile_student.html index 3da2f41..947dab7 100644 --- a/Website/skoolos/templates/skoolos/profile_student.html +++ b/Website/skoolos/templates/skoolos/profile_student.html @@ -5,6 +5,7 @@
+

Student

{{ user.first_name }} {{ user.last_name }}

{{ user.email }} @@ -16,6 +17,8 @@

    {% for class in classes %}
  • {{ class.name }}
  • + {% empty %} +
  • No classes
  • {% endfor %}
diff --git a/Website/skoolos/templates/skoolos/profile_teacher.html b/Website/skoolos/templates/skoolos/profile_teacher.html index 3da2f41..7c62793 100644 --- a/Website/skoolos/templates/skoolos/profile_teacher.html +++ b/Website/skoolos/templates/skoolos/profile_teacher.html @@ -5,6 +5,7 @@
+

Teacher

{{ user.first_name }} {{ user.last_name }}

{{ user.email }} @@ -16,6 +17,8 @@

    {% for class in classes %}
  • {{ class.name }}
  • + {% empty %} +
  • Not teaching any classes
  • {% endfor %}
diff --git a/Website/skoolos/urls.py b/Website/skoolos/urls.py index a028497..8fa2724 100644 --- a/Website/skoolos/urls.py +++ b/Website/skoolos/urls.py @@ -7,4 +7,6 @@ urlpatterns = [ path('', views.home, name='home'), path('profile/', views.profile, name='profile'), path("class/", views.classDetail, name="class"), + path("create-class/", views.createClass, name="create-class"), + path("create-assignment/", views.createAssignment, name="create-assignment"), ] diff --git a/Website/skoolos/views.py b/Website/skoolos/views.py index 3f67c84..c364365 100644 --- a/Website/skoolos/views.py +++ b/Website/skoolos/views.py @@ -5,7 +5,12 @@ from django.contrib import messages 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 @@ -14,14 +19,14 @@ from api.models import Student, Teacher, Class, Assignment @login_required() def home (request): try: - student = Student.objects.get(user=request.user) - return render(request, "skoolos/home.html", {'classes': student.confirmed.all()}) + student = request.user.student + return render(request, "skoolos/home.html", {'classes': student.confirmed.all(), 'isTeacher': False}) except Student.DoesNotExist: pass try: - teacher = Teacher.objects.get(user=request.user) - return render(request, "skoolos/home.html", {'classes': teacher.classes.all()}) + teacher = request.user.teacher + return render(request, "skoolos/home.html", {'classes': teacher.classes.all(), 'isTeacher': True}) except Teacher.DoesNotExist: pass @@ -36,38 +41,37 @@ def classDetail (request, id): classObj = Class.objects.get(id=id) try: - student = Student.objects.get(user=request.user) + student = request.user.student except Student.DoesNotExist: pass else: if classObj.confirmed.filter(user=student.user).count() != 1: return redirect('/') 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: - teacher = Teacher.objects.get(user=request.user) - return render(request, "skoolos/home.html", {'classes': teacher.classes.all()}) + teacher = request.user.teacher except Teacher.DoesNotExist: pass else: - if classObj.confirmed.filter(user=student.user).count() != 1: + if teacher.classes.filter(id=classObj.id).count() != 1: return redirect('/') 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('/') @login_required() def profile (request): try: - student = Student.objects.get(user=request.user) + student = request.user.student return student_profile(request) except Student.DoesNotExist: pass try: - teacher = Teacher.objects.get(user=request.user) + teacher = request.user.teacher return teacher_profile(request) except Teacher.DoesNotExist: pass @@ -91,7 +95,8 @@ def student_profile (request): context = { 'userForm': userForm, 'profileForm': profileForm, - 'classes': request.user.student.confirmed.all() + 'classes': request.user.student.confirmed.all(), + 'isTeacher': False, } return render(request, 'skoolos/profile_student.html', context) @@ -113,7 +118,47 @@ def teacher_profile (request): context = { 'userForm': userForm, 'profileForm': profileForm, - 'classes': request.user.teacher.classes.all() + 'classes': request.user.teacher.classes.all(), + 'isTeacher': True, } 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": + userForm = UserUpdateForm(request.POST, instance=request.user) + profileForm = TeacherUpdateForm(request.POST, + instance=request.user.teacher) + if userForm.is_valid() and profileForm.is_valid(): + userForm.save() + profileForm.save() + messages.success(request, "Your account has been updated!") + return redirect('profile') + 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 From 4b024f3932b5fa0e76b25169eaf9a2a97203ebed Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 16:30:54 -0400 Subject: [PATCH 11/40] teachher cli optimization --- skoolos.py | 351 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 201 insertions(+), 150 deletions(-) diff --git a/skoolos.py b/skoolos.py index 2941c21..866d568 100644 --- a/skoolos.py +++ b/skoolos.py @@ -155,170 +155,221 @@ def chooseGeneralTeacher(teacher): course = prompt(courses)['course'] return course +def makeClassTeacher(teacher): + questions = [ + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, + ] + cname = prompt(questions)['cname'] + print(cname) + teacher.makeClass(cname) + soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] + questions = [ + { + 'type': 'list', + 'choices':soption, + 'name': 'students', + 'message': 'Add Students): ', + }, + ] + choice = prompt(questions)['students'].split(")")[0] + if("1" == choice): + s = input("Student name: ") + teacher.addStudent(s, cname) + if("2" == choice): + print("File must be .txt and have 1 student username per line") + path = input("Relative Path: ") + while(not os.path.exists(path)): + if(path == 'N'): + return True + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, cname) + return False + +def classOptionsTeacher(teacher, course): + print("Class: " + course) + unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] + for s in unconf: + teacher.addStudent(s, course) + options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"] + questions = [ + { + 'type': 'list', + 'name': 'course', + 'choices':options, + 'message': 'Select option: ', + }, + ] + option = prompt(questions)['course'].split(")")[0] + return option + +def addStudentsTeacher(teacher, course): + soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] + questions = [ + { + 'type': 'list', + 'choices':soption, + 'name': 'students', + 'message': 'Add list of students (input path): ', + }, + ] + schoice = prompt(questions)['students'].split(")")[0] + if(schoice == '1'): + questions = [ + { + 'type': 'input', + 'name': 'student', + 'message': 'Student Name: ', + }, + ] + s = prompt(questions)['student'] + teacher.reqStudent(s, course) + return False + if(schoice == '2'): + questions = [ + { + 'type': 'input', + 'name': 'path', + 'message': 'Path: ', + }, + ] + path = prompt(questions)['path'] + while(not os.path.exists(path)): + if(path == 'N'): + sys.exit(0) + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, course) + return False + else: + return True + +def addAssignmentTeacher(teacher, course): + nlist = os.listdir(teacher.username + "/" + course) + alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] + print(nlist) + tlist = [] + b = True + for n in nlist: + b = True + print(teacher.username + "/" + course + "/" + n) + for a in alist: + if(n in a or n == a): + #print("Assignments: " + n) + b = False + if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): + b = False + if(b): + tlist.append(n) + + + nlist = tlist + if(len(nlist) == 0): + print("No new assignments found") + sys.exit(0) + questions = [ + { + 'type': 'list', + 'choices':nlist, + 'name': 'assignment', + 'message': 'Select new assignment: ', + }, + ] + ass = prompt(questions)['assignment'] + apath = teacher.username + "/" + course + "/" + ass + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" + due = due.strip() + f = False + while(not f): + try: + datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + f = True + except: + print("Due-date format is incorrect.") + print(due) + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" + teacher.addAssignment(apath, course, due) + def teacherCLI(user, password): from CLI import teacher data = getUser(user, password, 'teacher') print(data) teacher = teacher.Teacher(data) + EXIT = False # 1. make a class # 2. add studeents to an existing class # 3. Get progress logs on a student # 2. make an assignment for a class # 3. view student submissions for an assignment - carray = [] - for c in teacher.classes: - carray.append(c) - carray.append("Make New Class") - carray.append("Exit SkoolOS") - courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices':carray, - 'message': 'Select class: ', - }, - ] - course = chooseGeneralTeacher(teacher) - if course == "Exit SkoolOS": - teacher.exitCLI() - if course == "Make New Class": - questions = [ - { - 'type': 'input', - 'name': 'cname', - 'message': 'Class Name (Must be: _): ', - }, - ] - cname = prompt(questions)['cname'] - print(cname) - teacher.makeClass(cname) - soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] - questions = [ - { - 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add Students): ', - }, - ] - choice = prompt(questions)['students'].split(")")[0] - if("1" == choice): - s = input("Student name: ") - teacher.addStudent(s, cname) - if("2" == choice): - print("File must be .txt and have 1 student username per line") - path = input("Relative Path: ") - while(not os.path.exists(path)): - if(path == 'N'): - sys.exit(0) - print(path + " is not a valid path") - path = input("Enter file path ('N' to exit): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, cname) - - else: - print("Class: " + course) - unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] - for s in unconf: - teacher.addStudent(s, course) - options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] - questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices':options, - 'message': 'Select option: ', - }, - ] - option = prompt(questions)['course'].split(")")[0] - if(option == '1'): - soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] - questions = [ - { - 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add list of students (input path): ', - }, - ] - schoice = prompt(questions)['students'].split(")")[0] - if(schoice == '1'): - questions = [ - { - 'type': 'input', - 'name': 'student', - 'message': 'Student Name: ', - }, - ] - s = prompt(questions)['student'] - teacher.reqStudent(s, course) - if(schoice == '2'): - questions = [ - { - 'type': 'input', - 'name': 'path', - 'message': 'Path: ', - }, - ] - path = prompt(questions)['path'] - while(not os.path.exists(path)): - if(path == 'N'): - sys.exit(0) - print(path + " is not a valid path") - path = input("Enter file path ('N' to exit): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, course) - else: - sys.exit(0) - if(option == '2'): - nlist = os.listdir(teacher.username + "/" + course) - alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] - print(nlist) - tlist = [] - b = True - for n in nlist: + while(not EXIT): + #Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" + course = chooseGeneralTeacher(teacher) + if course == "Exit SkoolOS": + EXIT = True + if course == "Make New Class": + EXIT = makeClassTeacher(teacher) + #selected a class + else: + option = classOptionsTeacher(teacher, course) + if(option == '1'): + EXIT = addStudentsTeacher(teacher, course) + if(option == '2'): + nlist = os.listdir(teacher.username + "/" + course) + alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] + print(nlist) + tlist = [] b = True - print(teacher.username + "/" + course + "/" + n) - for a in alist: - if(n in a or n == a): - #print("Assignments: " + n) + for n in nlist: + b = True + print(teacher.username + "/" + course + "/" + n) + for a in alist: + if(n in a or n == a): + #print("Assignments: " + n) + b = False + if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): b = False - if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): - b = False - if(b): - tlist.append(n) + if(b): + tlist.append(n) - nlist = tlist - if(len(nlist) == 0): - print("No new assignments found") - sys.exit(0) - questions = [ - { - 'type': 'list', - 'choices':nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, - ] - ass = prompt(questions)['assignment'] - apath = teacher.username + "/" + course + "/" + ass - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - due = due.strip() - f = False - while(not f): - try: - datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') - f = True - except: - print("Due-date format is incorrect.") - print(due) - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - teacher.addAssignment(apath, course, due) + nlist = tlist + if(len(nlist) == 0): + print("No new assignments found") + sys.exit(0) + questions = [ + { + 'type': 'list', + 'choices':nlist, + 'name': 'assignment', + 'message': 'Select new assignment: ', + }, + ] + ass = prompt(questions)['assignment'] + apath = teacher.username + "/" + course + "/" + ass + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" + due = due.strip() + f = False + while(not f): + try: + datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + f = True + except: + print("Due-date format is incorrect.") + print(due) + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" + teacher.addAssignment(apath, course, due) ###################################################################### From 38532e7bfa035c52da16b736f0fd8d8002f5b95c Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 17:57:21 -0400 Subject: [PATCH 12/40] finished documenting skoolos.py --- CLI/student.py | 164 +++++++++++------- CLI/teacher.py | 2 +- skoolos.py | 450 +++++++++++++++++++++++++++++-------------------- 3 files changed, 365 insertions(+), 251 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index a97da2c..d215337 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -14,52 +14,89 @@ import datetime # get teacher info from api def getStudent(ion_user): + """ + Get's student information from the api + :param ion_user: a student + :return: student information or error + """ URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" r = requests.get(url=URL, auth=('raffukhondaker', 'hackgroup1')) - if (r.status_code == 200): + if r.status_code == 200: data = r.json() return data - elif (r.status_code == 404): + elif r.status_code == 404: return None print("Make new account!") - elif (r.status_code == 403): + elif r.status_code == 403: return None print("Invalid username/password") else: return None 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): + """ + 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)) - 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): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + Sends a PATCH request to the URL + :param data: + :param url: URL for request + """ + r = requests.patch(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) 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): + """ + Sends a POST request to the URL + :param data: + :param url: URL for request + """ r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) 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): + """ + Sends a PUT request to the URL + :param data: + :param url: URL for request + """ r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) 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): + """ + Sends a DELETE request to the URL + :param url: URL for request + """ r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) print("DELETE:" + str(r.status_code)) def command(command): + """ + Runs a shell command + :param command: shell command + """ ar = [] command = command.split(" ") for c in command: @@ -78,6 +115,10 @@ class Student: def __init__(self, data): # teacher info already stored in API # intitialze fields after GET request + """ + Initializes a Student with data from the api + :param data: api data + """ self.git = data['git'] self.username = data['ion_user'] self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/" @@ -122,8 +163,8 @@ class Student: self.snew = str(data['added_to']) self.repo = data['repo'] - if (os.path.isdir(self.username) == False): - if (self.repo == ""): + if os.path.isdir(self.username) == False: + if self.repo == "": user = self.git pwd = input("Enter Github password: ") # curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos @@ -147,11 +188,18 @@ class Student: print("Synced to " + self.username) def getClasses(self): + """ + Gets a lists of classes the student is enrolled in + """ classes = self.classes for c in classes: print(c['name']) - def getAssignments(self, course, span): + def getAssignments(self, span): + """ + Gets a list of assignments the student has + :param span: time span to check + """ span = datetime.timedelta(span, 0) classes = self.classes for c in classes: @@ -166,7 +214,7 @@ class Student: diff = now - due zero = datetime.timedelta(0, 0) # check due ddate is in span range is now past date (- timdelta) - if (diff < span and diff > zero): + if diff < span and diff > zero: print(a + " due in:" + str(now - due)) except Exception as e: @@ -175,6 +223,9 @@ class Student: # update API and Github, all assignments / classes def update(self): + """ + Updates the api, github, and all assignments and classes with new information + """ cdir = os.getcwd() os.chdir(self.username) command("git checkout master") @@ -197,7 +248,11 @@ class Student: # updates 1 class, does not switch to master def updateClass(self, course): - if ((course in self.sclass) == False): + """ + Updates a class with new information + :param course: class name in the format _ + """ + if (course in self.sclass) == False: print("Class not found") return cdir = os.getcwd() @@ -212,16 +267,20 @@ class Student: # add classes from 'new' field def addClass(self, cid): - + """ + Add student to a class + :param cid: the id number of the class + :return: data from the class, None if an error occures + """ data = getDB('http://127.0.0.1:8000/api/classes/' + str(cid)) - if ((cid in self.snew) == False or (self.username in data['confirmed'])): + if not (cid in self.snew) or (self.username in data['confirmed']): print("Already enrolled in this class.") return None - if ((cid in self.sclass) or (self.username in data['unconfirmed']) == False): + if (cid in self.sclass) or not (self.username in data['unconfirmed']): print("Not added by teacher yet.") return None - # add class teacher as cocllaborator to student repo + # add class teacher as collaborator to student repo print(os.getcwd()) pwd = input("Enter Github password: ") tgit = getDB("http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git'] @@ -241,7 +300,7 @@ class Student: # os.chdir(self.username) # push to git, start at master - #os.chdir(self.username) + # os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") @@ -263,7 +322,7 @@ class Student: user = self.git self.classes.append(data) - if (len(self.sclass) == 0): + if len(self.sclass) == 0: self.sclass = data['name'] else: self.sclass = self.sclass + "," + str(data['name']) @@ -272,7 +331,7 @@ class Student: snew = "" new = [] for i in range(len(self.new)): - if (self.new[i]['name'] == data['name']): + if self.new[i]['name'] == data['name']: del self.new[i] # recreate sclass field, using ids for c in self.new: @@ -292,46 +351,12 @@ class Student: print(patchDB(data, self.url)) return data - def submit(self, path): - # 2022rkhondak/English11_eharris1/Essay1 - # check if valid assignment - parts = path.split("/") - if (len(parts) != 3): - print("Assignment path too short") - return - isclass = False - for c in self.classes: - if (c['name'] == parts[1]): - isclass == True - break - if (parts[0] != self.username and isclass and os.path.isdir(path) == False): - print("Not valid assignment") - return - if ((parts[1] + "/" + parts[2]) in self.completed): - print(parts[2] + " already submited. ") - # return - resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ") - if (resp == 'y'): - os.chdir(self.username + "/" + parts[1]) - command("git add .") - command("git commit -m submit") - command("git tag " + parts[1] + "-final") - command("git push -u origin " + self.username + " --tags") - self.completed = self.completed + "," + parts[1] + "/" + parts[2] - data = { - 'user': self.user, - 'git': self.git, - 'ion_user': self.username, - 'student_id': self.student_id, - 'added_to': self.snew, - 'url': self.url, - 'classes': self.sclass, - 'grade': self.grade, - 'completed': self.completed - } - # print(putDB(data, "http://127.0.0.1:8000/api/students/" + self.username + "/")) - def viewClass(self, courses): + """ + Sets the current git branch to view each class in courses + :param courses: a list of classes + :return: + """ self.update() cdir = os.getcwd() os.chdir(self.username) @@ -346,11 +371,20 @@ class Student: return def exitCLI(self): + """ + Exits the cli + """ print(os.getcwd()) self.update() command("git checkout master") def submit(self, course, assignment): + """ + Submits an assignment + :param course: the class the assignment belongs to + :param assignment: the assignment + :return: + """ cdir = os.getcwd() os.chdir(self.username) print(os.getcwd()) @@ -364,7 +398,7 @@ class Student: if a == assignment: inclass = True break - if (inclass == False): + if inclass == False: print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) diff --git a/CLI/teacher.py b/CLI/teacher.py index c332b3f..0f1eaa7 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -87,7 +87,7 @@ def putDB(data, url): Sends a PUT request to the URL :param data: :param url: URL for request - """ + """ r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) print("PUT:" + str(r.status_code)) return r.json() diff --git a/skoolos.py b/skoolos.py index 2941c21..382eff0 100644 --- a/skoolos.py +++ b/skoolos.py @@ -25,7 +25,12 @@ scope = ["read"] USER = "" PWD = "" + def main(): + """ + The Command Line Interface (CLI) for SkoolOS + Serves to allow both teachers and students to access the majority of the features of SkoolOS + """ print("") print("░██████╗██╗░░██╗░█████╗░░█████╗░██╗░░░░░  ░█████╗░░██████╗") print("██╔════╝██║░██╔╝██╔══██╗██╔══██╗██║░░░░░  ██╔══██╗██╔════╝") @@ -38,13 +43,13 @@ def main(): if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")): try: URL = "http://127.0.0.1:8000/api/" - r = requests.get(url = URL) + r = requests.get(url=URL) except: print("Run Django server on http://127.0.0.1:8000/ before continuing") sys.exit(0) input("Welcome to SkoolOS. Press any key to create an account") - #webbrowser.open("http://127.0.0.1:8000/login", new=2) + # webbrowser.open("http://127.0.0.1:8000/login", new=2) authenticate() else: profiles = os.listdir() @@ -53,109 +58,140 @@ def main(): count = 1 for i in range(len(profiles)): p = profiles[i] - if('profile' in p): - f = open(p,'r') + if 'profile' in p: + f = open(p, 'r') d = json.loads(f.read()) f.close() info.append(d) users.append(str(count) + ") " + d['username']) - count = count+1 + count = count + 1 user = [ - { - 'type': 'list', - 'name': 'user', - 'choices':users, - 'message': 'Select User: ', - }, + { + 'type': 'list', + 'name': 'user', + 'choices': users, + 'message': 'Select User: ', + }, ] - u = int(prompt(user)['user'].split(")")[0]) -1 + u = int(prompt(user)['user'].split(")")[0]) - 1 data = info[u] PWD = data['password'] USER = data['username'] print(data['username']) - if(data['is_student']): + if data['is_student']: studentCLI(USER, PWD) else: teacherCLI(USER, PWD) - + + ################################################ STUDENT METHODS def studentCLI(user, password): + """ + The CLI for students to access + :param user: student username + :param password: student password + """ from CLI import student data = getUser(user, password, 'student') student = student.Student(data) student.update() EXIT = False - while(not EXIT): + while not EXIT: course = chooseClassStudent(student) EXIT = classOptionsStudent(student, course) -#return class -def chooseClassStudent(student): + +# return class +def chooseClassStudent(student): + """ + Chooses a class for a student to view and work on + :param student: a student + :return: a course prompt + """ carray = student.sclass.split(",") - if(len(carray) == 1 and carray[0] == ""): + if len(carray) == 1 and carray[0] == "": carray.remove("") print("No classes") - + carray.append("Exit SkoolOS") courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices':carray, - 'message': 'Select class: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices': carray, + 'message': 'Select class: ', + }, ] course = prompt(courses)['course'] print(course) return course + def classOptionsStudent(student, course): + """ + Allows students to choose what they want to do related to a class + The student can save, exit, or go back + :param student: a student + :param course: a course + :return: True if exiting, False if going back + """ student.viewClass(course) - student.getAssignments(course, 100) - choices = ["Save","Back","Exit SkoolOS"] + student.getAssignments(course, 100) + choices = ["Save", "Back", "Exit SkoolOS"] options = [ - { - 'type': 'list', - 'name': 'option', - 'choices':choices, - 'message': 'Select: ', - }, + { + 'type': 'list', + 'name': 'option', + 'choices': choices, + 'message': 'Select: ', + }, ] option = prompt(options)['option'] - if(option == "Save"): + if option == "Save": student.update() print("Saved!") classOptionsStudent(student, course) - if(option == "Back"): + if option == "Back": student.exitCLI() - #dont exit cli + # dont exit cli return False - if(option == "Exit SkoolOS"): + if option == "Exit SkoolOS": student.exitCLI() - #exit cli + # exit cli return True - + ################################################ TEACHER METHODS def chooseGeneralTeacher(teacher): + """ + Presents teachers with their options + :param teacher: a teacher + :return: a course prompt + """ carray = [] for c in teacher.classes: carray.append(c) carray.append("Make New Class") carray.append("Exit SkoolOS") courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices':carray, - 'message': 'Select class: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices': carray, + 'message': 'Select class: ', + }, ] course = prompt(courses)['course'] return course + def teacherCLI(user, password): + """ + The teachers' view of the CLI + :param user: username + :param password: password + """ from CLI import teacher data = getUser(user, password, 'teacher') print(data) @@ -171,45 +207,45 @@ def teacherCLI(user, password): carray.append("Make New Class") carray.append("Exit SkoolOS") courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices':carray, - 'message': 'Select class: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices': carray, + 'message': 'Select class: ', + }, ] course = chooseGeneralTeacher(teacher) if course == "Exit SkoolOS": teacher.exitCLI() if course == "Make New Class": questions = [ - { - 'type': 'input', - 'name': 'cname', - 'message': 'Class Name (Must be: _): ', - }, + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, ] cname = prompt(questions)['cname'] print(cname) teacher.makeClass(cname) soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] questions = [ - { - 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add Students): ', - }, + { + 'type': 'list', + 'choices': soption, + 'name': 'students', + 'message': 'Add Students): ', + }, ] choice = prompt(questions)['students'].split(")")[0] - if("1" == choice): + if "1" == choice: s = input("Student name: ") teacher.addStudent(s, cname) - if("2" == choice): + if "2" == choice: print("File must be .txt and have 1 student username per line") path = input("Relative Path: ") - while(not os.path.exists(path)): - if(path == 'N'): + while not os.path.exists(path): + if path == 'N': sys.exit(0) print(path + " is not a valid path") path = input("Enter file path ('N' to exit): ") @@ -224,46 +260,46 @@ def teacherCLI(user, password): teacher.addStudent(s, course) options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices':options, - 'message': 'Select option: ', - }, - ] - option = prompt(questions)['course'].split(")")[0] - if(option == '1'): - soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] - questions = [ { 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add list of students (input path): ', - }, + 'name': 'course', + 'choices': options, + 'message': 'Select option: ', + }, + ] + option = prompt(questions)['course'].split(")")[0] + if option == '1': + soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] + questions = [ + { + 'type': 'list', + 'choices': soption, + 'name': 'students', + 'message': 'Add list of students (input path): ', + }, ] schoice = prompt(questions)['students'].split(")")[0] - if(schoice == '1'): + if schoice == '1': questions = [ - { - 'type': 'input', - 'name': 'student', - 'message': 'Student Name: ', - }, + { + 'type': 'input', + 'name': 'student', + 'message': 'Student Name: ', + }, ] s = prompt(questions)['student'] teacher.reqStudent(s, course) - if(schoice == '2'): + if schoice == '2': questions = [ - { - 'type': 'input', - 'name': 'path', - 'message': 'Path: ', - }, + { + 'type': 'input', + 'name': 'path', + 'message': 'Path: ', + }, ] path = prompt(questions)['path'] - while(not os.path.exists(path)): - if(path == 'N'): + while not os.path.exists(path): + if path == 'N': sys.exit(0) print(path + " is not a valid path") path = input("Enter file path ('N' to exit): ") @@ -272,7 +308,7 @@ def teacherCLI(user, password): teacher.reqAddStudentList(students, course) else: sys.exit(0) - if(option == '2'): + if option == '2': nlist = os.listdir(teacher.username + "/" + course) alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] print(nlist) @@ -281,35 +317,34 @@ def teacherCLI(user, password): for n in nlist: b = True print(teacher.username + "/" + course + "/" + n) - for a in alist: - if(n in a or n == a): - #print("Assignments: " + n) + for a in alist: + if n in a or n == a: + # print("Assignments: " + n) b = False - if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): + if not os.path.isdir(teacher.username + "/" + course + "/" + n): b = False - if(b): + if b: tlist.append(n) - nlist = tlist - if(len(nlist) == 0): + if len(nlist) == 0: print("No new assignments found") sys.exit(0) questions = [ - { - 'type': 'list', - 'choices':nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, + { + 'type': 'list', + 'choices': nlist, + 'name': 'assignment', + 'message': 'Select new assignment: ', + }, ] ass = prompt(questions)['assignment'] apath = teacher.username + "/" + course + "/" + ass due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" + due = due + ":33.383124" due = due.strip() f = False - while(not f): + while not f: try: datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') f = True @@ -317,94 +352,133 @@ def teacherCLI(user, password): print("Due-date format is incorrect.") print(due) due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" + due = due + ":33.383124" teacher.addAssignment(apath, course, due) + ###################################################################### def getUser(ion_user, password, utype): - if('student' in utype): - URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" - else: - URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" - r = requests.get(url = URL, auth=(ion_user,password)) - print(r.json()) - if(r.status_code == 200): - data = r.json() - print(200) - return data - elif(r.status_code == 404): - print("Make new account!") - return None - elif(r.status_code == 403): - print("Invalid username/password") - return None - else: - print(r.status_code) - return None + """ + Returns user information + :param ion_user: user + :param password: user's password + :param utype: type of user (student or teacher + :return: api user information + """ + if 'student' in utype: + URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" + else: + URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" + r = requests.get(url=URL, auth=(ion_user, password)) + print(r.json()) + if r.status_code == 200: + data = r.json() + print(200) + return data + elif r.status_code == 404: + print("Make new account!") + return None + elif r.status_code == 403: + print("Invalid username/password") + return None + else: + print(r.status_code) + return None + + 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)) - return(r.json()) + return r.json() + def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) + """ + 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)) - return(r.json()) + return r.json() + def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + 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)) - return(r.json()) + return r.json() + def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + """ + 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)) - return(r.json()) + return r.json() + def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + """ + 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)) return None + def makePass(): + """ + Prompts the user to create a password + :return: the password + """ questions = [ - { - 'type': 'password', - 'name': 'pwd', - 'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ', - }, + { + 'type': 'password', + 'name': 'pwd', + 'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ', + }, ] pwd = prompt(questions)['pwd'] - while(len(pwd) < 7): + while len(pwd) < 7: print("Password too short (Must be over 6 characters)") pwd = prompt(questions)['pwd'] conf = [ - { - 'type': 'password', - 'name': 'pwd', - 'message': 'Re-enter password: ', - }, + { + 'type': 'password', + 'name': 'pwd', + 'message': 'Re-enter password: ', + }, ] pwd2 = prompt(conf)['pwd'] - while(not pwd == pwd2): + while not pwd == pwd2: print("Passwords do not match.") pwd2 = prompt(conf)['pwd'] else: print("PASSWORD SAVED") return pwd + def authenticate(): + """ + Authenticates the user via Ion OAuth + """ oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") cdir = os.getcwd() - #Linux: chromdriver-linux - #Macos: chromdriver-mac - #Windows: chromdriver.exe - if('CLI' in os.getcwd()): - path = os.path.join(os.getcwd(), '../','chromedriver-mac') + # Linux: chromdriver-linux + # Macos: chromdriver-mac + # Windows: chromdriver.exe + if 'CLI' in os.getcwd(): + path = os.path.join(os.getcwd(), '../', 'chromedriver-mac') else: path = os.path.join(os.getcwd(), 'chromedriver-mac') @@ -417,7 +491,8 @@ def authenticate(): url = browser.current_url gets = url_decode(url.replace("http://localhost:8000/login/?", "")) - while "http://localhost:8000/login/?username=" not in browser.current_url and (not browser.current_url == "http://localhost:8000/"): #http://localhost:8000/ + while "http://localhost:8000/login/?username=" not in browser.current_url and ( + not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/ time.sleep(0.25) url = browser.current_url @@ -428,42 +503,42 @@ def authenticate(): # print("states good") browser.quit() questions = [ - { - 'type': 'input', - 'name': 'username', - 'message': 'Enter SkoolOS Username (Same as ION Username): ', - }, - { - 'type': 'password', - 'name': 'pwd', - 'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ', - }, + { + 'type': 'input', + 'name': 'username', + 'message': 'Enter SkoolOS Username (Same as ION Username): ', + }, + { + 'type': 'password', + 'name': 'pwd', + 'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ', + }, ] - data =prompt(questions) + data = prompt(questions) pwd = data['pwd'] user = data['username'] - r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd)) - while(r.status_code != 200): + r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd)) + while r.status_code != 200: print("INCORRECT LOGIN CREDENTIALS") - r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd)) - data =prompt(questions) + r = requests.get(url="http://localhost:8000/api/", auth=(user, pwd)) + data = prompt(questions) pwd = data['pwd'] user = data['username'] print(r.status_code) - r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd)) + r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd)) is_student = False - if(r.status_code == 200): + if r.status_code == 200: is_student = True print("Welcome, student " + user) - r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd)) + r = requests.get(url="http://localhost:8000/api/students/" + user + "/", auth=(user, pwd)) profile = r.json() username = profile['ion_user'] grade = profile['grade'] profile = { - 'username':username, - 'grade':grade, - 'is_student':is_student, - 'password':pwd, + 'username': username, + 'grade': grade, + 'is_student': is_student, + 'password': pwd, } profileFile = open(".sprofile", "w") profileFile.write(json.dumps(profile)) @@ -471,26 +546,31 @@ def authenticate(): else: print("Welcome, teacher " + user) - r = requests.get(url = "http://localhost:8000/api/teachers/" + user + "/", auth=(user,pwd)) + r = requests.get(url="http://localhost:8000/api/teachers/" + user + "/", auth=(user, pwd)) profile = r.json() username = profile['ion_user'] profile = { - 'username':username, - 'is_student':is_student, - 'password':pwd, + 'username': username, + 'is_student': is_student, + 'password': pwd, } profileFile = open(".tprofile", "w") profileFile.write(json.dumps(profile)) profileFile.close() - sys.exit + sys.exit(0) + def create_server(): + """ + Creates a simple HTTP server for creating api requests from the CLI + """ port = 8000 handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", port), handler) print("serving at port:" + str(port)) httpd.serve_forever() + if __name__ == "__main__": main() From 9fec8ad95da4072c5578da12563c28dbc2d67f2d Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 18:03:07 -0400 Subject: [PATCH 13/40] DB requests uupdates --- .sprofile => .2022rkhondakprofile | 0 .tprofile => .eharris1profile | 0 CLI/student.py | 63 +++++-- CLI/teacher.py | 99 ++++++---- Website/api/serializers.py | 2 +- eharris1/APLit_eharris1/BookReport/rubric.txt | 7 - eharris1/APLit_eharris1/BookReport/sample.txt | 0 .../Essay1_APLit_eharris1/instruct.txt | 0 eharris1/APLit_eharris1/Essay2/instruct.txt | 0 eharris1/Art12_eharris1/Painting1/rubric.txt | 0 eharris1/Art12_eharris1/README.md | 0 eharris1/English11_eharris1/README.md | 0 .../README.md | 0 skoolos.py | 177 +++++++++--------- 14 files changed, 190 insertions(+), 158 deletions(-) rename .sprofile => .2022rkhondakprofile (100%) rename .tprofile => .eharris1profile (100%) delete mode 100644 eharris1/APLit_eharris1/BookReport/rubric.txt delete mode 100644 eharris1/APLit_eharris1/BookReport/sample.txt delete mode 100644 eharris1/APLit_eharris1/Essay1_APLit_eharris1/instruct.txt delete mode 100644 eharris1/APLit_eharris1/Essay2/instruct.txt delete mode 100644 eharris1/Art12_eharris1/Painting1/rubric.txt delete mode 100644 eharris1/Art12_eharris1/README.md delete mode 100644 eharris1/English11_eharris1/README.md rename eharris1/{APLit_eharris1 => English12_eharris1}/README.md (100%) diff --git a/.sprofile b/.2022rkhondakprofile similarity index 100% rename from .sprofile rename to .2022rkhondakprofile diff --git a/.tprofile b/.eharris1profile similarity index 100% rename from .tprofile rename to .eharris1profile diff --git a/CLI/student.py b/CLI/student.py index a97da2c..c503dfe 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -13,9 +13,9 @@ import datetime # git clone student directory ==> /classes/assignments # get teacher info from api -def getStudent(ion_user): +def getStudent(ion_user, password): 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): data = r.json() return data @@ -30,33 +30,60 @@ def getStudent(ion_user): print(r.status_code) #makes a GET request to given url, returns dict -def getDB(url): - r = requests.get(url=url, auth=('raffukhondaker', 'hackgroup1')) +def getDB(user, pwd, url): + """ + Sends a GET request to the URL + :param url: URL for request + """ + r = requests.get(url=url, auth=(user, pwd)) print("GET:" + str(r.status_code)) - return (r.json()) - -#makes a PATCH (updates instance) request to given url, returns dict -def patchDB(data, url): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - print("PATCH:" + str(r.status_code)) return(r.json()) +#makes a PATCH (updates instance) request to given url, returns dict +def patchDB(user, pwd, data, url): + """ + Sends a PATCH request to the URL + :param data: + :param url: URL for request + """ + r = requests.patch(url=url, data=data, auth=(user, pwd)) + print("PATCH:" + str(r.status_code)) + return r.json() + + #makes a POST (makes new instance) request to given url, returns dict -def postDB(data, url): - r = requests.post(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) +def postDB(user, pwd, data, url): + """ + Sends a POST request to the URL + :param data: + :param url: URL for request + """ + r = requests.post(url=url, data=data, auth=(user, pwd)) print("POST:" + str(r.status_code)) - return (r.json()) + return r.json() + #makes a PUT (overwrites instance) request to given url, returns dict -def putDB(data, url): - r = requests.put(url=url, data=data, auth=('raffukhondaker', 'hackgroup1')) +def putDB(user, pwd, data, url): + """ + Sends a PUT request to the URL + :param data: + :param url: URL for request + """ + r = requests.put(url=url, data=data, auth=(user, pwd)) print("PUT:" + str(r.status_code)) - return (r.json()) + return r.json() + #makes a DELETE (delete instance) request to given url, returns dict -def delDB(url): - r = requests.delete(url=url, auth=('raffukhondaker', 'hackgroup1')) +def delDB(user, pwd, url): + """ + Sends a DELETE request to the URL + :param url: URL for request + """ + r = requests.delete(url=url, auth=(user, pwd)) print("DELETE:" + str(r.status_code)) + return None def command(command): diff --git a/CLI/teacher.py b/CLI/teacher.py index c332b3f..fd58dfd 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -26,14 +26,16 @@ from datetime import datetime # git clone student directory ==> /classes/assignments # get teacher info from api -def getTeacher(ion_user): +def getTeacher(ion_user, password): """ Gets information about a teacher from the api :param ion_user: a teacher + :param password: a string :return: teacher information or error """ 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: data = r.json() return data @@ -48,58 +50,67 @@ def getTeacher(ion_user): print(r.status_code) #makes a GET request to given url, returns dict -def getDB(url): +def getDB(user, pwd, url): """ Sends a GET request to the URL + :param user: a string + :param password: a string :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)) return(r.json()) #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 :param data: + :param user: a string + :param password: a string :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)) return r.json() #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 :param data: + :param user: a string + :param password: a string :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)) return r.json() #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 - :param data: + :param user: a string + :param password: a string :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)) return r.json() #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 + :param user: a string + :param password: a string :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)) return None @@ -123,7 +134,7 @@ def command(command): # public methods: deleteClass, makeClass, update class Teacher: - def __init__(self, data): + def __init__(self, data, password): # teacher info already stored in API # intitialze fields after GET request """ @@ -134,6 +145,7 @@ class Teacher: self.username = data['ion_user'] self.url = "http://127.0.0.1:8000/api/teachers/" + self.username + "/" self.id = data['user'] + self.password = password # classes in id form (Example: 4,5) # array @@ -218,15 +230,22 @@ class Teacher: return if self.checkClass(path): 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 = { "name": cname, "repo": "", "path": cpath, + "subject": subject, + "period":period, "teacher": self.username, "owner": self.id } # 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) self.classes.append(cname) # add to instance @@ -235,7 +254,7 @@ class Teacher: 'classes': 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 # subject: string, assignments: list @@ -248,7 +267,7 @@ class Teacher: # check if class exists path = self.username + "/" + cname 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: if c['name'] == cname: isclass = True @@ -300,7 +319,7 @@ class Teacher: # 'classes':self.classes, # } # 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 # remove locally @@ -318,7 +337,7 @@ class Teacher: :return: True if student exists, False otherwise """ 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: return False return True @@ -333,7 +352,7 @@ class Teacher: if not self.isStudent(sname): print(sname + " does not exist.") 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']): print(sname + " already requested.") return True @@ -341,7 +360,7 @@ class Teacher: print(sname + " already enrolled.") 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: if student['added_to'] == "": student['added_to'] = course['name'] @@ -354,8 +373,8 @@ class Teacher: 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 + "/") + student = patchDB(self.username, self.password, data, "http://localhost:8000/api/students/" + student['ion_user'] + "/") + student = getDB(self.username, self.password, "http://localhost:8000/api/students/" + sname + "/") if not course['unconfirmed']: course['unconfirmed'] = student['ion_user'] else: @@ -364,7 +383,7 @@ class Teacher: "unconfirmed": course['unconfirmed'] } 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 # 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.") return False - student = getDB("http://127.0.0.1:8000/api/students/" + sname) - course = getDB("http://127.0.0.1:8000/api/classes/" + cname) + student = getDB(self.username, self.password, "http://127.0.0.1:8000/api/students/" + sname) + 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 ( student['ion_user'] in course['confirmed']) == True): @@ -435,7 +454,7 @@ class Teacher: "confirmed": course["confirmed"], "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 # 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") 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']): print("Assignment name already taken.") return False @@ -525,22 +544,23 @@ class Teacher: print(st + " already has assignment") # 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: ass = { 'name': oname, 'path': path, 'classes': course['name'], '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) cinfo = { "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 else: print("Assignment already addedd") @@ -561,12 +581,12 @@ class Teacher: d = { '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) except: print("Due-date is the same") 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']) cdir = os.getcwd() for st in slist: @@ -597,7 +617,7 @@ class Teacher: os.chdir(cdir) 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: if not (student in course['confirmed']): print("Student not in class") @@ -645,7 +665,7 @@ class Teacher: :param course: the course :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) commit = ar[len(ar) - 1][0] start = "" @@ -670,7 +690,7 @@ class Teacher: 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 = { # 'name': assignment, # 'due_date': "2020-04-11 16:58:33.383124", @@ -705,8 +725,9 @@ class Teacher: print("heheheh") -# data = getTeacher("eharris1") -# t = Teacher(data) +data = getTeacher("eharris1","hackgroup1") +print(data) +t = Teacher(data, "hackgroup1") # t.makeClass("APLit_eharris1") # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') # ar = ['2022rkhondak','2022inafi','2023rumareti'] diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 40521ac..7d7b2aa 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -34,7 +34,7 @@ class ClassSerializer(serializers.ModelSerializer): class Meta: model = Class # 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 = ClassSerializer(many=True, read_only=True,allow_null=True) diff --git a/eharris1/APLit_eharris1/BookReport/rubric.txt b/eharris1/APLit_eharris1/BookReport/rubric.txt deleted file mode 100644 index a65722f..0000000 --- a/eharris1/APLit_eharris1/BookReport/rubric.txt +++ /dev/null @@ -1,7 +0,0 @@ -kskskksks -kskskksks -kskskksks -kskskksks -kskskksks -kskskksks -kskskksks \ No newline at end of file diff --git a/eharris1/APLit_eharris1/BookReport/sample.txt b/eharris1/APLit_eharris1/BookReport/sample.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/APLit_eharris1/Essay1_APLit_eharris1/instruct.txt b/eharris1/APLit_eharris1/Essay1_APLit_eharris1/instruct.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/APLit_eharris1/Essay2/instruct.txt b/eharris1/APLit_eharris1/Essay2/instruct.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Art12_eharris1/Painting1/rubric.txt b/eharris1/Art12_eharris1/Painting1/rubric.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Art12_eharris1/README.md b/eharris1/Art12_eharris1/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/English11_eharris1/README.md b/eharris1/English11_eharris1/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/APLit_eharris1/README.md b/eharris1/English12_eharris1/README.md similarity index 100% rename from eharris1/APLit_eharris1/README.md rename to eharris1/English12_eharris1/README.md diff --git a/skoolos.py b/skoolos.py index 866d568..4041980 100644 --- a/skoolos.py +++ b/skoolos.py @@ -35,7 +35,9 @@ def main(): print("╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚══════╝  ░╚════╝░╚═════╝░") print("") - if not (os.path.exists(".sprofile") or os.path.exists(".tprofile")): + profiles = os.listdir() + + if not ("profile" in str(profiles)): try: URL = "http://127.0.0.1:8000/api/" r = requests.get(url = URL) @@ -60,6 +62,7 @@ def main(): info.append(d) users.append(str(count) + ") " + d['username']) count = count+1 + users.append(str(count) + ") Make new user") user = [ { 'type': 'list', @@ -69,6 +72,9 @@ def main(): }, ] u = int(prompt(user)['user'].split(")")[0]) -1 + if(u+1 == count): + authenticate() + return data = info[u] PWD = data['password'] USER = data['username'] @@ -78,7 +84,7 @@ def main(): else: teacherCLI(USER, PWD) -################################################ STUDENT METHODS +#################################################################################################### STUDENT METHODS def studentCLI(user, password): from CLI import student @@ -88,6 +94,8 @@ def studentCLI(user, password): EXIT = False while(not EXIT): course = chooseClassStudent(student) + if(course == "Exit SkoolOS"): + return EXIT = classOptionsStudent(student, course) #return class @@ -137,7 +145,37 @@ def classOptionsStudent(student, course): return True -################################################ TEACHER METHODS +#################################################################################################### TEACHER METHODS +def teacherCLI(user, password): + from CLI import teacher + data = getUser(user, password, 'teacher') + print(data) + teacher = teacher.Teacher(data) + EXIT = False + # 1. make a class + # 2. add studeents to an existing class + # 3. Get progress logs on a student + # 2. make an assignment for a class + # 3. view student submissions for an assignment + while(not EXIT): + #Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" + course = chooseGeneralTeacher(teacher) + if course == "Exit SkoolOS": + EXIT = True + elif course == "Make New Class": + EXIT = makeClassTeacher(teacher) + #selected a class + else: + option = classOptionsTeacher(teacher, course) + if(option == '1'): + EXIT = addStudentsTeacher(teacher, course) + elif(option == '2'): + EXIT = addAssignmentTeacher(teacher, course) + elif(option == '3'): + EXIT = viewStudentsTeacher(teacher, course) + else: + EXIT = True + def chooseGeneralTeacher(teacher): carray = [] for c in teacher.classes: @@ -192,7 +230,7 @@ def makeClassTeacher(teacher): teacher.reqAddStudentList(students, cname) return False -def classOptionsTeacher(teacher, course): +def classOptionsTeacher(teacher, course, password): print("Class: " + course) unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] for s in unconf: @@ -254,7 +292,7 @@ def addStudentsTeacher(teacher, course): def addAssignmentTeacher(teacher, course): nlist = os.listdir(teacher.username + "/" + course) - alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] + alist = getDB(teacher.username, "http://localhost:8000/api/classes/" + course)['assignments'] print(nlist) tlist = [] b = True @@ -274,7 +312,8 @@ def addAssignmentTeacher(teacher, course): nlist = tlist if(len(nlist) == 0): print("No new assignments found") - sys.exit(0) + print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder") + return False questions = [ { 'type': 'list', @@ -299,86 +338,37 @@ def addAssignmentTeacher(teacher, course): due = input("Enter due date (Example: 2020-08-11 16:58): ") due = due + ":33.383124" teacher.addAssignment(apath, course, due) + return False -def teacherCLI(user, password): - from CLI import teacher - data = getUser(user, password, 'teacher') - print(data) - teacher = teacher.Teacher(data) - EXIT = False - # 1. make a class - # 2. add studeents to an existing class - # 3. Get progress logs on a student - # 2. make an assignment for a class - # 3. view student submissions for an assignment - while(not EXIT): - #Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" - course = chooseGeneralTeacher(teacher) - if course == "Exit SkoolOS": - EXIT = True - if course == "Make New Class": - EXIT = makeClassTeacher(teacher) - #selected a class - else: - option = classOptionsTeacher(teacher, course) - if(option == '1'): - EXIT = addStudentsTeacher(teacher, course) - if(option == '2'): - nlist = os.listdir(teacher.username + "/" + course) - alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] - print(nlist) - tlist = [] - b = True - for n in nlist: - b = True - print(teacher.username + "/" + course + "/" + n) - for a in alist: - if(n in a or n == a): - #print("Assignments: " + n) - b = False - if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): - b = False - if(b): - tlist.append(n) +def viewStudentsTeacher(teacher, course): + data = getDB("http://127.0.0.1:8000/api/classes/" + course) + students = data["confirmed"] + unconf = data['unconfirmed'] + print("Studented in class: ") + for s in students: + print(s) + print("Requsted Students: ") + for s in unconf: + print(s) + student = input("View student (Enter student's ion username): ") + while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))): + print("Student not affiliated with class") + student = input("View student ('N' to exit): ") + if student == 'N': + return True + print(getDB("http://127.0.0.1:8000/api/students/" + student + "/")) - nlist = tlist - if(len(nlist) == 0): - print("No new assignments found") - sys.exit(0) - questions = [ - { - 'type': 'list', - 'choices':nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, - ] - ass = prompt(questions)['assignment'] - apath = teacher.username + "/" + course + "/" + ass - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - due = due.strip() - f = False - while(not f): - try: - datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') - f = True - except: - print("Due-date format is incorrect.") - print(due) - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - teacher.addAssignment(apath, course, due) -###################################################################### +############################################################################################################################################ def getUser(ion_user, password, utype): if('student' in utype): - URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" + URL = "http://127.0.0.1:8000/api/students/" + USER + "/" else: - URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" + URL = "http://127.0.0.1:8000/api/teachers/" + USER + "/" + print(URL) r = requests.get(url = URL, auth=(ion_user,password)) print(r.json()) if(r.status_code == 200): @@ -394,28 +384,29 @@ def getUser(ion_user, password, utype): else: print(r.status_code) return None -def patchDB(data, url): + +def patchDB(USER, PWD, url, data): r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) print("PATH:" + str(r.status_code)) return(r.json()) -def getDB(url): - r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) +def getDB(USER, PWD, url): + r = requests.get(url = url, auth=(USER,PWD)) print("GET:" + str(r.status_code)) return(r.json()) -def postDB(data, url): - r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) +def postDB(USER, PWD, url, data): + r = requests.post(url = url, data=data, auth=(USER,PWD)) print("POST:" + str(r.status_code)) return(r.json()) -def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) +def putDB(USER, PWD, url, data): + r = requests.put(url = url, data=data, auth=(USER,PWD)) print("PUT:" + str(r.status_code)) return(r.json()) -def delDB(url): - r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) +def delDB(USER, PWD, url): + r = requests.delete(url = url, auth=(USER,PWD)) print("DELETE:" + str(r.status_code)) return None @@ -454,10 +445,7 @@ def authenticate(): #Linux: chromdriver-linux #Macos: chromdriver-mac #Windows: chromdriver.exe - if('CLI' in os.getcwd()): - path = os.path.join(os.getcwd(), '../','chromedriver-mac') - else: - path = os.path.join(os.getcwd(), 'chromedriver-mac') + path = os.path.join(os.getcwd(),'chromedriver','chromedriver-mac') browser = webdriver.Chrome(path) @@ -516,7 +504,8 @@ def authenticate(): 'is_student':is_student, 'password':pwd, } - profileFile = open(".sprofile", "w") + fname = "." + username + "profile" + profileFile = open(fname, "w") profileFile.write(json.dumps(profile)) profileFile.close() @@ -530,11 +519,13 @@ def authenticate(): 'is_student':is_student, 'password':pwd, } - profileFile = open(".tprofile", "w") + fname = "." + username + "profile" + profileFile = open(fname, "w") profileFile.write(json.dumps(profile)) profileFile.close() - sys.exit + sys.exit(0) + def create_server(): port = 8000 From 9fefe43da6dd3730d1b09f1b13287c105662c049 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 18:15:32 -0400 Subject: [PATCH 14/40] unique auth login --- CLI/student.py | 25 +++++++++++++------------ CLI/teacher.py | 6 +++--- skoolos.py | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index c503dfe..ae61396 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -102,7 +102,7 @@ def command(command): # public methods: deleteClass, makeClass, update class Student: - def __init__(self, data): + def __init__(self, data, password): # teacher info already stored in API # intitialze fields after GET request self.git = data['git'] @@ -111,6 +111,7 @@ class Student: self.grade = data['grade'] self.completed = data['completed'] self.user = data['user'] + self.password = password # classes in id form (Example: 4,5) # storing actual classes cid = data['classes'].split(",") @@ -125,7 +126,7 @@ class Student: classes = [] for c in cid: 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.sclass = str(data['classes']) @@ -143,7 +144,7 @@ class Student: nclasses = [] for c in nid: 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.snew = str(data['added_to']) @@ -170,7 +171,7 @@ class Student: data = { 'repo': self.repo } - print(patchDB(data, self.url)) + print(patchDB(self.username, self.password,data, self.url)) print("Synced to " + self.username) def getClasses(self): @@ -185,7 +186,7 @@ class Student: print(c['name']) alist = c['assignments'] 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() try: due = ass['due_date'].replace("T", " ").replace("Z", "") @@ -207,7 +208,7 @@ class Student: command("git checkout master") for c in self.classes: 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 " + data['name']) command("git add .") @@ -240,7 +241,7 @@ class Student: # add classes from 'new' field def addClass(self, cid): - 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 ((cid in self.snew) == False or (self.username in data['confirmed'])): print("Already enrolled in this class.") return None @@ -251,7 +252,7 @@ class Student: # add class teacher as cocllaborator to student repo print(os.getcwd()) 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 + "'" print(url) os.system(url) @@ -304,7 +305,7 @@ class Student: # recreate sclass field, using ids for c in self.new: 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.new = new break @@ -316,7 +317,7 @@ class Student: 'classes': self.sclass } print(self.url) - print(patchDB(data, self.url)) + print(patchDB(self.username, self.password,data, self.url)) return data def submit(self, path): @@ -406,8 +407,8 @@ class Student: os.chdir(cdir) -# data = getStudent("2022rkhondak") -# s = Student(data) +#data = getStudent("2022rkhondak", "PWD") +#s = Student(data, "PWD") # s.viewClass("APLit_eharris1") # #s.addClass("APLit_eharris1") # # #s.update() diff --git a/CLI/teacher.py b/CLI/teacher.py index fd58dfd..363d80c 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -725,9 +725,9 @@ class Teacher: print("heheheh") -data = getTeacher("eharris1","hackgroup1") -print(data) -t = Teacher(data, "hackgroup1") +# data = getTeacher("eharris1","PWD") +# print(data) +# t = Teacher(data, "PWD") # t.makeClass("APLit_eharris1") # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') # ar = ['2022rkhondak','2022inafi','2023rumareti'] diff --git a/skoolos.py b/skoolos.py index 4041980..3bc163b 100644 --- a/skoolos.py +++ b/skoolos.py @@ -89,7 +89,7 @@ def main(): def studentCLI(user, password): from CLI import student data = getUser(user, password, 'student') - student = student.Student(data) + student = student.Student(data, password) student.update() EXIT = False while(not EXIT): @@ -150,7 +150,7 @@ def teacherCLI(user, password): from CLI import teacher data = getUser(user, password, 'teacher') print(data) - teacher = teacher.Teacher(data) + teacher = teacher.Teacher(data, password) EXIT = False # 1. make a class # 2. add studeents to an existing class @@ -230,9 +230,9 @@ def makeClassTeacher(teacher): teacher.reqAddStudentList(students, cname) return False -def classOptionsTeacher(teacher, course, password): +def classOptionsTeacher(teacher, course): print("Class: " + course) - unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] + unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed'] for s in unconf: teacher.addStudent(s, course) options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"] @@ -292,7 +292,7 @@ def addStudentsTeacher(teacher, course): def addAssignmentTeacher(teacher, course): nlist = os.listdir(teacher.username + "/" + course) - alist = getDB(teacher.username, "http://localhost:8000/api/classes/" + course)['assignments'] + alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments'] print(nlist) tlist = [] b = True @@ -341,7 +341,7 @@ def addAssignmentTeacher(teacher, course): return False def viewStudentsTeacher(teacher, course): - data = getDB("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"] unconf = data['unconfirmed'] print("Studented in class: ") @@ -356,7 +356,7 @@ def viewStudentsTeacher(teacher, course): student = input("View student ('N' to exit): ") if student == 'N': return True - print(getDB("http://127.0.0.1:8000/api/students/" + student + "/")) + print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/")) @@ -365,9 +365,9 @@ def viewStudentsTeacher(teacher, course): def getUser(ion_user, password, utype): if('student' in utype): - URL = "http://127.0.0.1:8000/api/students/" + USER + "/" + URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" else: - URL = "http://127.0.0.1:8000/api/teachers/" + USER + "/" + URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" print(URL) r = requests.get(url = URL, auth=(ion_user,password)) print(r.json()) @@ -386,7 +386,7 @@ def getUser(ion_user, password, utype): return None def patchDB(USER, PWD, url, data): - r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + r = requests.patch(url = url, data=data, auth=(USER,PWD)) print("PATH:" + str(r.status_code)) return(r.json()) From d05fcdcca2c652bbaf144af083d28912b34e837a Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 18:23:53 -0400 Subject: [PATCH 15/40] forcedd login in skoolos.py --- eharris1/Art12_eharris1/README.md | 0 skoolos.py | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 eharris1/Art12_eharris1/README.md diff --git a/eharris1/Art12_eharris1/README.md b/eharris1/Art12_eharris1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/skoolos.py b/skoolos.py index 3bc163b..ad7491b 100644 --- a/skoolos.py +++ b/skoolos.py @@ -203,6 +203,17 @@ def makeClassTeacher(teacher): ] 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: _): ', + }, + ] + cname = prompt(questions)['cname'] + teacher.makeClass(cname) soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] questions = [ From dab05345925e5f97aa7509611082a9ed36ffc793 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 18:24:16 -0400 Subject: [PATCH 16/40] Fixed some fields and started more work on forms --- Website/api/models.py | 4 ++-- Website/skoolos/forms.py | 25 +++++++++---------------- Website/skoolos/views.py | 15 +++++++-------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Website/api/models.py b/Website/api/models.py index d62f9dc..37364a1 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -61,7 +61,7 @@ class Class(models.Model): return super(Class, self).save(*args, **kwargs) def __str__(self): - return f"{self.user.first_name} {self.user.last_name} ({self.user.username})" + return f"{self.name}" class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) @@ -70,7 +70,7 @@ class Teacher(models.Model): ion_user=models.CharField(primary_key=True, max_length=100) 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): super(Teacher, self).save(*args, **kwargs) diff --git a/Website/skoolos/forms.py b/Website/skoolos/forms.py index e249d96..2f498c0 100644 --- a/Website/skoolos/forms.py +++ b/Website/skoolos/forms.py @@ -54,23 +54,16 @@ class ClassCreationForm (forms.ModelForm): 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, commit=True): - # Get the unsave Pizza instance - instance = forms.ModelForm.save(self, False) + def save(self, username=""): + cleaned_data = self.cleaned_data + print(self) - # Prepare a 'save_m2m' method for the form, - old_save_m2m = self.save_m2m - def save_m2m(): - old_save_m2m() - # This is where we actually link the pizza with toppings - instance.topping_set.clear() - instance.topping_set.add(*self.cleaned_data['unconfirmed']) - self.save_m2m = save_m2m - - # Do we need to save all changes now? - if commit: - instance.save() - self.save_m2m() + # 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 diff --git a/Website/skoolos/views.py b/Website/skoolos/views.py index c364365..ff00036 100644 --- a/Website/skoolos/views.py +++ b/Website/skoolos/views.py @@ -139,14 +139,13 @@ def createClassHelper(request): teacher = request.user.teacher if request.method == "POST": - userForm = UserUpdateForm(request.POST, instance=request.user) - profileForm = TeacherUpdateForm(request.POST, - instance=request.user.teacher) - if userForm.is_valid() and profileForm.is_valid(): - userForm.save() - profileForm.save() - messages.success(request, "Your account has been updated!") - return redirect('profile') + 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() From 19105021612f81a50d658daba5fe4188d47e6fa8 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:12:12 -0400 Subject: [PATCH 17/40] manually fixed skoolos.py --- skoolos.py | 367 +++++++++++++++++++++++++++++------------------------ 1 file changed, 199 insertions(+), 168 deletions(-) diff --git a/skoolos.py b/skoolos.py index 382eff0..453832d 100644 --- a/skoolos.py +++ b/skoolos.py @@ -163,197 +163,228 @@ def classOptionsStudent(student, course): ################################################ TEACHER METHODS -def chooseGeneralTeacher(teacher): - """ - Presents teachers with their options - :param teacher: a teacher - :return: a course prompt - """ - carray = [] - for c in teacher.classes: - carray.append(c) - carray.append("Make New Class") - carray.append("Exit SkoolOS") - courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices': carray, - 'message': 'Select class: ', - }, - ] - course = prompt(courses)['course'] - return course - - def teacherCLI(user, password): - """ - The teachers' view of the CLI - :param user: username - :param password: password - """ from CLI import teacher data = getUser(user, password, 'teacher') print(data) - teacher = teacher.Teacher(data) + teacher = teacher.Teacher(data, password) + EXIT = False # 1. make a class # 2. add studeents to an existing class # 3. Get progress logs on a student # 2. make an assignment for a class # 3. view student submissions for an assignment + while(not EXIT): + #Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" + course = chooseGeneralTeacher(teacher) + if course == "Exit SkoolOS": + EXIT = True + elif course == "Make New Class": + EXIT = makeClassTeacher(teacher) + #selected a class + else: + option = classOptionsTeacher(teacher, course) + if(option == '1'): + EXIT = addStudentsTeacher(teacher, course) + elif(option == '2'): + EXIT = addAssignmentTeacher(teacher, course) + elif(option == '3'): + EXIT = viewStudentsTeacher(teacher, course) + else: + EXIT = True + +def chooseGeneralTeacher(teacher): carray = [] for c in teacher.classes: carray.append(c) carray.append("Make New Class") carray.append("Exit SkoolOS") courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices': carray, - 'message': 'Select class: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices':carray, + 'message': 'Select class: ', + }, ] - course = chooseGeneralTeacher(teacher) - if course == "Exit SkoolOS": - teacher.exitCLI() - if course == "Make New Class": + course = prompt(courses)['course'] + return course + +def makeClassTeacher(teacher): + questions = [ + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, + ] + 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: _): ', - }, + { + 'type': 'input', + 'name': 'cname', + 'message': 'Class Name (Must be: _): ', + }, ] cname = prompt(questions)['cname'] - print(cname) - teacher.makeClass(cname) - soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] - questions = [ - { - 'type': 'list', - 'choices': soption, - 'name': 'students', - 'message': 'Add Students): ', - }, - ] - choice = prompt(questions)['students'].split(")")[0] - if "1" == choice: - s = input("Student name: ") - teacher.addStudent(s, cname) - if "2" == choice: - print("File must be .txt and have 1 student username per line") - path = input("Relative Path: ") - while not os.path.exists(path): - if path == 'N': - sys.exit(0) - print(path + " is not a valid path") - path = input("Enter file path ('N' to exit): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, cname) + teacher.makeClass(cname) + soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] + questions = [ + { + 'type': 'list', + 'choices':soption, + 'name': 'students', + 'message': 'Add Students): ', + }, + ] + choice = prompt(questions)['students'].split(")")[0] + if("1" == choice): + s = input("Student name: ") + teacher.addStudent(s, cname) + if("2" == choice): + print("File must be .txt and have 1 student username per line") + path = input("Relative Path: ") + while(not os.path.exists(path)): + if(path == 'N'): + return True + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, cname) + return False + +def classOptionsTeacher(teacher, course): + print("Class: " + course) + unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed'] + for s in unconf: + teacher.addStudent(s, course) + options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"] + questions = [ + { + 'type': 'list', + 'name': 'course', + 'choices':options, + 'message': 'Select option: ', + }, + ] + option = prompt(questions)['course'].split(")")[0] + return option + +def addStudentsTeacher(teacher, course): + soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] + questions = [ + { + 'type': 'list', + 'choices':soption, + 'name': 'students', + 'message': 'Add list of students (input path): ', + }, + ] + schoice = prompt(questions)['students'].split(")")[0] + if(schoice == '1'): + questions = [ + { + 'type': 'input', + 'name': 'student', + 'message': 'Student Name: ', + }, + ] + s = prompt(questions)['student'] + teacher.reqStudent(s, course) + return False + if(schoice == '2'): + questions = [ + { + 'type': 'input', + 'name': 'path', + 'message': 'Path: ', + }, + ] + path = prompt(questions)['path'] + while(not os.path.exists(path)): + if(path == 'N'): + sys.exit(0) + print(path + " is not a valid path") + path = input("Enter file path ('N' to exit): ") + f = open(path, 'r') + students = f.read().splitlines() + teacher.reqAddStudentList(students, course) + return False else: - print("Class: " + course) - unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] - for s in unconf: - teacher.addStudent(s, course) - options = ['1) Request Student', "2) Add assignment", "3) View student information", "Exit"] - questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices': options, - 'message': 'Select option: ', - }, - ] - option = prompt(questions)['course'].split(")")[0] - if option == '1': - soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] - questions = [ - { - 'type': 'list', - 'choices': soption, - 'name': 'students', - 'message': 'Add list of students (input path): ', - }, - ] - schoice = prompt(questions)['students'].split(")")[0] - if schoice == '1': - questions = [ - { - 'type': 'input', - 'name': 'student', - 'message': 'Student Name: ', - }, - ] - s = prompt(questions)['student'] - teacher.reqStudent(s, course) - if schoice == '2': - questions = [ - { - 'type': 'input', - 'name': 'path', - 'message': 'Path: ', - }, - ] - path = prompt(questions)['path'] - while not os.path.exists(path): - if path == 'N': - sys.exit(0) - print(path + " is not a valid path") - path = input("Enter file path ('N' to exit): ") - f = open(path, 'r') - students = f.read().splitlines() - teacher.reqAddStudentList(students, course) - else: - sys.exit(0) - if option == '2': - nlist = os.listdir(teacher.username + "/" + course) - alist = getDB("http://localhost:8000/api/classes/" + course)['assignments'] - print(nlist) - tlist = [] - b = True - for n in nlist: - b = True - print(teacher.username + "/" + course + "/" + n) - for a in alist: - if n in a or n == a: - # print("Assignments: " + n) - b = False - if not os.path.isdir(teacher.username + "/" + course + "/" + n): - b = False - if b: - tlist.append(n) + return True - nlist = tlist - if len(nlist) == 0: - print("No new assignments found") - sys.exit(0) - questions = [ - { - 'type': 'list', - 'choices': nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, - ] - ass = prompt(questions)['assignment'] - apath = teacher.username + "/" + course + "/" + ass +def addAssignmentTeacher(teacher, course): + nlist = os.listdir(teacher.username + "/" + course) + alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments'] + print(nlist) + tlist = [] + b = True + for n in nlist: + b = True + print(teacher.username + "/" + course + "/" + n) + for a in alist: + if(n in a or n == a): + #print("Assignments: " + n) + b = False + if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): + b = False + if(b): + tlist.append(n) + + + nlist = tlist + if(len(nlist) == 0): + print("No new assignments found") + print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder") + return False + questions = [ + { + 'type': 'list', + 'choices':nlist, + 'name': 'assignment', + 'message': 'Select new assignment: ', + }, + ] + ass = prompt(questions)['assignment'] + apath = teacher.username + "/" + course + "/" + ass + due = input("Enter due date (Example: 2020-08-11 16:58): ") + due = due + ":33.383124" + due = due.strip() + f = False + while(not f): + try: + datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + f = True + except: + print("Due-date format is incorrect.") + print(due) due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - due = due.strip() - f = False - while not f: - try: - datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') - f = True - except: - print("Due-date format is incorrect.") - print(due) - due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" - teacher.addAssignment(apath, course, due) + due = due + ":33.383124" + teacher.addAssignment(apath, course, due) + return False + +def viewStudentsTeacher(teacher, course): + data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course) + students = data["confirmed"] + unconf = data['unconfirmed'] + print("Studented in class: ") + for s in students: + print(s) + print("Requsted Students: ") + for s in unconf: + print(s) + student = input("View student (Enter student's ion username): ") + while((not student in str(data['confirmed'])) or (not student in str(data['unconfirmed']))): + print("Student not affiliated with class") + student = input("View student ('N' to exit): ") + if student == 'N': + return True + print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/")) ###################################################################### From d4be5f9eb86752b8ef116617f2adbf4c84e00374 Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Tue, 16 Jun 2020 19:12:34 -0400 Subject: [PATCH 18/40] formatting --- skoolos.py | 162 +++++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 78 deletions(-) diff --git a/skoolos.py b/skoolos.py index 453832d..6f2ba9f 100644 --- a/skoolos.py +++ b/skoolos.py @@ -174,25 +174,26 @@ def teacherCLI(user, password): # 3. Get progress logs on a student # 2. make an assignment for a class # 3. view student submissions for an assignment - while(not EXIT): - #Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" + while (not EXIT): + # Options: '1) Request Student', "2) Add assignment", "3) View student information", "4) Exit" course = chooseGeneralTeacher(teacher) if course == "Exit SkoolOS": EXIT = True elif course == "Make New Class": EXIT = makeClassTeacher(teacher) - #selected a class + # selected a class else: option = classOptionsTeacher(teacher, course) - if(option == '1'): + if (option == '1'): EXIT = addStudentsTeacher(teacher, course) - elif(option == '2'): + elif (option == '2'): EXIT = addAssignmentTeacher(teacher, course) - elif(option == '3'): + elif (option == '3'): EXIT = viewStudentsTeacher(teacher, course) else: EXIT = True + def chooseGeneralTeacher(teacher): carray = [] for c in teacher.classes: @@ -200,56 +201,57 @@ def chooseGeneralTeacher(teacher): carray.append("Make New Class") carray.append("Exit SkoolOS") courses = [ - { - 'type': 'list', - 'name': 'course', - 'choices':carray, - 'message': 'Select class: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices': carray, + 'message': 'Select class: ', + }, ] course = prompt(courses)['course'] return course + def makeClassTeacher(teacher): questions = [ - { - 'type': 'input', - 'name': 'cname', - 'message': 'Class Name (Must be: _): ', - }, - ] - 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: _): ', }, + ] + 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: _): ', + }, ] cname = prompt(questions)['cname'] teacher.makeClass(cname) soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] questions = [ - { - 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add Students): ', - }, + { + 'type': 'list', + 'choices': soption, + 'name': 'students', + 'message': 'Add Students): ', + }, ] choice = prompt(questions)['students'].split(")")[0] - if("1" == choice): + if ("1" == choice): s = input("Student name: ") teacher.addStudent(s, cname) - if("2" == choice): + if ("2" == choice): print("File must be .txt and have 1 student username per line") path = input("Relative Path: ") - while(not os.path.exists(path)): - if(path == 'N'): + while (not os.path.exists(path)): + if (path == 'N'): return True print(path + " is not a valid path") path = input("Enter file path ('N' to exit): ") @@ -258,6 +260,7 @@ def makeClassTeacher(teacher): teacher.reqAddStudentList(students, cname) return False + def classOptionsTeacher(teacher, course): print("Class: " + course) unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed'] @@ -265,49 +268,50 @@ def classOptionsTeacher(teacher, course): teacher.addStudent(s, course) options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"] questions = [ - { - 'type': 'list', - 'name': 'course', - 'choices':options, - 'message': 'Select option: ', - }, + { + 'type': 'list', + 'name': 'course', + 'choices': options, + 'message': 'Select option: ', + }, ] option = prompt(questions)['course'].split(")")[0] return option + def addStudentsTeacher(teacher, course): soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"] questions = [ - { - 'type': 'list', - 'choices':soption, - 'name': 'students', - 'message': 'Add list of students (input path): ', - }, + { + 'type': 'list', + 'choices': soption, + 'name': 'students', + 'message': 'Add list of students (input path): ', + }, ] schoice = prompt(questions)['students'].split(")")[0] - if(schoice == '1'): + if (schoice == '1'): questions = [ - { - 'type': 'input', - 'name': 'student', - 'message': 'Student Name: ', - }, + { + 'type': 'input', + 'name': 'student', + 'message': 'Student Name: ', + }, ] s = prompt(questions)['student'] teacher.reqStudent(s, course) return False - if(schoice == '2'): + if (schoice == '2'): questions = [ - { - 'type': 'input', - 'name': 'path', - 'message': 'Path: ', - }, + { + 'type': 'input', + 'name': 'path', + 'message': 'Path: ', + }, ] path = prompt(questions)['path'] - while(not os.path.exists(path)): - if(path == 'N'): + while (not os.path.exists(path)): + if (path == 'N'): sys.exit(0) print(path + " is not a valid path") path = input("Enter file path ('N' to exit): ") @@ -318,6 +322,7 @@ def addStudentsTeacher(teacher, course): else: return True + def addAssignmentTeacher(teacher, course): nlist = os.listdir(teacher.username + "/" + course) alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments'] @@ -327,36 +332,36 @@ def addAssignmentTeacher(teacher, course): for n in nlist: b = True print(teacher.username + "/" + course + "/" + n) - for a in alist: - if(n in a or n == a): - #print("Assignments: " + n) + for a in alist: + if (n in a or n == a): + # print("Assignments: " + n) b = False - if(not os.path.isdir(teacher.username + "/" + course + "/" + n)): + if (not os.path.isdir(teacher.username + "/" + course + "/" + n)): b = False - if(b): + if (b): tlist.append(n) - nlist = tlist - if(len(nlist) == 0): + if (len(nlist) == 0): print("No new assignments found") - print("To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder") + print( + "To make an assignment: make a subdirectory in the " + course + " folder. Add a file within the new folder") return False questions = [ - { - 'type': 'list', - 'choices':nlist, - 'name': 'assignment', - 'message': 'Select new assignment: ', - }, + { + 'type': 'list', + 'choices': nlist, + 'name': 'assignment', + 'message': 'Select new assignment: ', + }, ] ass = prompt(questions)['assignment'] apath = teacher.username + "/" + course + "/" + ass due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" + due = due + ":33.383124" due = due.strip() f = False - while(not f): + while (not f): try: datetime.datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') f = True @@ -364,10 +369,11 @@ def addAssignmentTeacher(teacher, course): print("Due-date format is incorrect.") print(due) due = input("Enter due date (Example: 2020-08-11 16:58): ") - due = due + ":33.383124" + due = due + ":33.383124" teacher.addAssignment(apath, course, due) return False + def viewStudentsTeacher(teacher, course): data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course) students = data["confirmed"] @@ -379,7 +385,7 @@ def viewStudentsTeacher(teacher, course): for s in unconf: print(s) 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") student = input("View student ('N' to exit): ") if student == 'N': @@ -523,7 +529,7 @@ def authenticate(): url = browser.current_url gets = url_decode(url.replace("http://localhost:8000/login/?", "")) while "http://localhost:8000/login/?username=" not in browser.current_url and ( - not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/ + not browser.current_url == "http://localhost:8000/"): # http://localhost:8000/ time.sleep(0.25) url = browser.current_url From 699dd72b24910f5f9ef669de1be8a30321b106a8 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 16 Jun 2020 19:35:08 -0400 Subject: [PATCH 19/40] added ClassCreationForm to teacher view --- Website/skoolos/forms.py | 14 -------------- Website/skoolos/static/skoolos/styles.css | 10 ++++++++++ Website/skoolos/templates/skoolos/base.html | 1 - Website/skoolos/templates/skoolos/home.html | 10 ++++++++-- Website/skoolos/urls.py | 1 - Website/skoolos/views.py | 13 ++++++++----- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Website/skoolos/forms.py b/Website/skoolos/forms.py index 2f498c0..f314f54 100644 --- a/Website/skoolos/forms.py +++ b/Website/skoolos/forms.py @@ -53,20 +53,6 @@ class ClassCreationForm (forms.ModelForm): # 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'] diff --git a/Website/skoolos/static/skoolos/styles.css b/Website/skoolos/static/skoolos/styles.css index 0f86d92..db1e636 100644 --- a/Website/skoolos/static/skoolos/styles.css +++ b/Website/skoolos/static/skoolos/styles.css @@ -92,3 +92,13 @@ a.article-title:hover { .account-heading { font-size: 2.5rem; } + +.class-card { + text-decoration: none; + color: gray; +} + +.class-card:hover { + text-decoration: none; + color: black; +} diff --git a/Website/skoolos/templates/skoolos/base.html b/Website/skoolos/templates/skoolos/base.html index fa2f42c..65c0801 100644 --- a/Website/skoolos/templates/skoolos/base.html +++ b/Website/skoolos/templates/skoolos/base.html @@ -35,7 +35,6 @@