From 4ea39ae8dec3960d174a64ea3c4084a6afa6dc74 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 05:55:13 -0400 Subject: [PATCH 01/13] Hello --- CLI/s-git-oldd.py | 256 ++++++++++ CLI/s-git.py | 60 ++- CLI/t-git.py | 439 ++++++++++++++++++ .../api/migrations/0006_auto_20200610_0631.py | 28 ++ Website/api/models.py | 3 + Website/api/serializers.py | 4 +- .../Journal1/instructions.txt | 0 eharris1/English11_eharris1/README.md | 0 fork/English11_eharris1 | 1 + 9 files changed, 773 insertions(+), 18 deletions(-) create mode 100644 CLI/s-git-oldd.py create mode 100644 CLI/t-git.py create mode 100644 Website/api/migrations/0006_auto_20200610_0631.py create mode 100644 eharris1/English11_eharris1/Journal1/instructions.txt create mode 100644 eharris1/English11_eharris1/README.md create mode 160000 fork/English11_eharris1 diff --git a/CLI/s-git-oldd.py b/CLI/s-git-oldd.py new file mode 100644 index 0000000..0cf4486 --- /dev/null +++ b/CLI/s-git-oldd.py @@ -0,0 +1,256 @@ +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/s-git.py b/CLI/s-git.py index 0cf4486..ec1a520 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -54,7 +54,7 @@ def command(command): ar.append(c) process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) p=process.poll() - output = process.communicate()[1] + output = process.communicate()[0] print(output.decode('utf-8')) #################################################################################################################################### @@ -74,7 +74,6 @@ class Student: 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: @@ -110,11 +109,32 @@ class Student: 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) - + self.repo = data['repo'] + 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" + os.system(url) + command('git clone https://github.com/' + self.git + '/' + self.username + '.git') + self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git' + print(url) + 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, + 'repo':self.repo + } + print(putDB(data, self.url)) + print("Synced to " + self.username) #update API and Github, all assignments / classes def update(self): @@ -162,15 +182,24 @@ class Student: else: print("Not added by teacher yet.") return None + + pwd= input("Enter Github password: ") + url= "curl -i -u " + user + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + data['name'] + "/collaborators/" + data['teacher'] + "'" + data = getDB('http://127.0.0.1:8000/classes/'+cid) + data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") + data['unconfirmed'] = data['unconfirmed'].replace(self.username, "") + data['confirmed'] = data['confirmed'] + "," + self.username + if(data['confirmed'][0] == ','): + data['confirmed'] = data['confirmed'][1:] + print(data['confirmed']) + print(putDB(data, '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) - + #add teacher as collaborator + #curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR' + user = self.git + print(url) + os.system(url) self.classes.append(data) if(len(self.sclass)==0): self.sclass = data['id'] @@ -182,7 +211,6 @@ class Student: 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: @@ -253,4 +281,4 @@ class Student: data = getStudent("2022rkhondak") s = Student(data) -s.update() \ No newline at end of file +s.addClass('57') \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py new file mode 100644 index 0000000..0f4cf0d --- /dev/null +++ b/CLI/t-git.py @@ -0,0 +1,439 @@ +import subprocess +import os +import requests +import webbrowser +import pprint +import json +import shutil +import time +import pyperclip +from distutils.dir_util import copy_tree + + +#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)): + cname = path.split("/") + cname = cname[len(cname)-1] + cpath = self.username + "/" + cname[len(cname)-1] + data = { + "name": cname, + "repo": "", + "path": cpath, + "teacher": self.username, + "assignments": "", + "default_file": "", + "confirmed": "", + "unconfirmed": "" + } + #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 student directories + +#make student repo by student id + def reqStudent(self, student, classes): + cid = None + for c in self.classes: + print(c['name']) + if classes == c['name']: + cid = str(c['id']) + if(cid==None): + print(classes +" does not exist.") + return + + data = getDB("http://127.0.0.1:8000/students/" + student) + try: + if(data['added_to']==""): + data['added_to']=cid + else: + data['added_to']=data['added_to']+ "," + cid + except: + print(student + " does not exist.") + return + print(data['added_to']) + d={ + 'first_name':data["first_name"], + 'last_name':data["last_name"], + 'git':data["git"], + 'ion_user':data["ion_user"], + 'student_id':data["student_id"], + 'added_to':data['added_to'], + 'classes':data["classes"], + 'email':data["email"], + 'grade':data["grade"], + 'completed':data["completed"], + 'repo':data["repo"] + } + print(putDB(d, data['url'])) + data1 = getDB("http://127.0.0.1:8000/classes/" + cid) + if(data1['unconfirmed']==""): + data1['unconfirmed']=data['ion_user'] + else: + data1['unconfirmed']=data1['unconfirmed']+ "," + data['ion_user'] + d = { + "name": classes, + "repo": "", + "path": self.username + "/" + classes, + "teacher": self.username, + "assignments": "", + "default_file": "", + "confirmed": "", + "unconfirmed": data1['unconfirmed'] + } + print(putDB(d, data1['url'])) + + #confirmed students + def addStudent(self, student, classes): + cdir = os.getcwd() + cpath = self.username + "/" + classes + path = "Students/" + classes + if(os.path.isdir(path) == False): + os.mkdir(path) + os.chdir(path) + student = getDB("http://127.0.0.1:8000/students/" + student) + command("git clone " + student['repo']) + os.chdir(cdir) + shutil.copytree(path, cpath + "/" + student['ion_user']) + command('git branch ' + classes) + command('git add .') + command('git commit -m Hello') + command('git push -u origin ' + classes) + + def comment(self): + print("heheheh") + +data = getTeacher("eharris1") +t = Teacher(data) +t.addStudent('2022rkhondak','English11_eharris1') diff --git a/Website/api/migrations/0006_auto_20200610_0631.py b/Website/api/migrations/0006_auto_20200610_0631.py new file mode 100644 index 0000000..2083d0e --- /dev/null +++ b/Website/api/migrations/0006_auto_20200610_0631.py @@ -0,0 +1,28 @@ +# Generated by Django 3.0.7 on 2020-06-10 06:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0005_student_completed'), + ] + + operations = [ + migrations.AddField( + model_name='classes', + name='confirmed', + field=models.TextField(blank=True, default=''), + ), + migrations.AddField( + model_name='classes', + name='unconfirmed', + field=models.TextField(blank=True, default=''), + ), + migrations.AddField( + model_name='student', + name='repo', + field=models.URLField(blank=True, default=''), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index 71cad70..e75fddd 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -25,6 +25,8 @@ class Classes(models.Model): teacher=models.CharField(max_length=100, default="") assignments=models.CharField(max_length=100, default="") default_file=models.CharField(max_length=100, default="") + confirmed=models.TextField(default="", blank=True) + unconfirmed=models.TextField(default="", blank=True) # assignments = models.ManyToManyField(Assignment, default="") # default_file = models.ManyToManyField(DefFiles) @@ -50,6 +52,7 @@ class Student(models.Model): email=models.CharField(max_length=100, default="", blank=True) grade = models.IntegerField() git=models.CharField(max_length=100) + 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) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index f88fe97..6eb0f21 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -20,13 +20,13 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer): # default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Classes - fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id'] + fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id', 'confirmed', 'unconfirmed'] class StudentSerializer(serializers.HyperlinkedModelSerializer): # classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Student - fields = ['url', 'first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed'] + fields = ['url', 'first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo'] class TeacherSerializer(serializers.ModelSerializer): # classes = ClassesSerializer(many=True, read_only=True,allow_null=True) diff --git a/eharris1/English11_eharris1/Journal1/instructions.txt b/eharris1/English11_eharris1/Journal1/instructions.txt 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/fork/English11_eharris1 b/fork/English11_eharris1 new file mode 160000 index 0000000..ead6265 --- /dev/null +++ b/fork/English11_eharris1 @@ -0,0 +1 @@ +Subproject commit ead6265a08327f2cc099d1e61c01030d916e8cd9 From 6d7d8d450fcfcd863616cbffd98f4074e55069c2 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 05:57:46 -0400 Subject: [PATCH 02/13] Hello --- CLI/t-git.py | 2 +- Students/English11_eharris1/2022rkhondak | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 Students/English11_eharris1/2022rkhondak diff --git a/CLI/t-git.py b/CLI/t-git.py index 0f4cf0d..4d6a821 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -425,7 +425,7 @@ class Teacher: student = getDB("http://127.0.0.1:8000/students/" + student) command("git clone " + student['repo']) os.chdir(cdir) - shutil.copytree(path, cpath + "/" + student['ion_user']) + copy_tree(cpath, path + "/" + student['ion_user']) command('git branch ' + classes) command('git add .') command('git commit -m Hello') diff --git a/Students/English11_eharris1/2022rkhondak b/Students/English11_eharris1/2022rkhondak new file mode 160000 index 0000000..6f2b380 --- /dev/null +++ b/Students/English11_eharris1/2022rkhondak @@ -0,0 +1 @@ +Subproject commit 6f2b3806471b68a47db1208cc6b8c5dc37191df8 From 2b252b8f9dbac2e9ca5ac30d43037c32cd118c80 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 06:10:43 -0400 Subject: [PATCH 03/13] Hello --- CLI/s-git.py | 6 +++++- CLI/t-git.py | 5 +++-- Students/English11_eharris1/2022rkhondak | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CLI/s-git.py b/CLI/s-git.py index ec1a520..43d5268 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -117,6 +117,10 @@ class Student: url= "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos" os.system(url) command('git clone https://github.com/' + self.git + '/' + self.username + '.git') + command('touch README.md') + command('git add .') + command('git commit -m Hello') + command('git push -u origin master') self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git' print(url) data={ @@ -279,6 +283,6 @@ class Student: } #print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/")) -data = getStudent("2022rkhondak") +data = getStudent("2022inafi") s = Student(data) s.addClass('57') \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index 4d6a821..cf27ba1 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -57,7 +57,7 @@ def command(command): process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) p=process.poll() output = process.communicate()[1] - #print(output.decode('utf-8')) + print(output.decode('utf-8')) #################################################################################################################################### @@ -426,7 +426,8 @@ class Teacher: command("git clone " + student['repo']) os.chdir(cdir) copy_tree(cpath, path + "/" + student['ion_user']) - command('git branch ' + classes) + os.chdir("Students/" + classes + "/" + student['ion_user']) + command('git add .') command('git commit -m Hello') command('git push -u origin ' + classes) diff --git a/Students/English11_eharris1/2022rkhondak b/Students/English11_eharris1/2022rkhondak index 6f2b380..e863f41 160000 --- a/Students/English11_eharris1/2022rkhondak +++ b/Students/English11_eharris1/2022rkhondak @@ -1 +1 @@ -Subproject commit 6f2b3806471b68a47db1208cc6b8c5dc37191df8 +Subproject commit e863f414aed9de267ac442752c5585ead0536246 From 915becaaa30fc58db900011bafdc43d02f66b6ac Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 15:29:07 -0400 Subject: [PATCH 04/13] bug fix student --- CLI/s-git.py | 104 +++++++++--------- CLI/t-git.py | 79 ++++--------- Students/English11_eharris1/2022rkhondak | 1 - mlauerbach/Math5_mlauerbach/README.md | 0 .../Math5_mlauerbach/Test1/instructions.txt | 0 .../Week1_HW/instructions.txt | 0 6 files changed, 78 insertions(+), 106 deletions(-) delete mode 160000 Students/English11_eharris1/2022rkhondak create mode 100644 mlauerbach/Math5_mlauerbach/README.md create mode 100644 mlauerbach/Math5_mlauerbach/Test1/instructions.txt create mode 100644 mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt diff --git a/CLI/s-git.py b/CLI/s-git.py index 43d5268..46d69bc 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -110,19 +110,27 @@ class Student: self.new = nclasses self.snew=str(data['added_to']) self.repo = data['repo'] - 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" - os.system(url) + + 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() + os.mkdir(self.username) + os.chdir(self.username) command('git clone https://github.com/' + self.git + '/' + self.username + '.git') + os.chdir(self.username) + command('git checkout master') command('touch README.md') - command('git add .') - command('git commit -m Hello') + command('git add README.md') + command('git commit -m "Hello"') command('git push -u origin master') + os.chdir(cdir) self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git' - print(url) data={ 'first_name':self.first_name, 'last_name':self.last_name, @@ -142,38 +150,16 @@ class Student: #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") + for c in self.classes: + data = getDB("http://127.0.0.1:8000/classes/" + str(c['id'])) + os.chdir(self.username + "/" + data['name']) + command("git checkout -b " + data['name']) + command("git add " + data['name']) + command("git commit -m " + data['name']) + command("git push -u origin " + data['name']) + command("git pull origin " + data['name']) + for c in self.new: + self.addClass(str(c['id'])) #class name format: _ @@ -187,29 +173,49 @@ class Student: print("Not added by teacher yet.") return None + data = getDB('http://127.0.0.1:8000/classes/'+ str(cid)) pwd= input("Enter Github password: ") - url= "curl -i -u " + user + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + data['name'] + "/collaborators/" + data['teacher'] + "'" - - data = getDB('http://127.0.0.1:8000/classes/'+cid) + tgit = getDB("http://127.0.0.1:8000/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) + data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") data['unconfirmed'] = data['unconfirmed'].replace(self.username, "") data['confirmed'] = data['confirmed'] + "," + self.username if(data['confirmed'][0] == ','): data['confirmed'] = data['confirmed'][1:] print(data['confirmed']) - print(putDB(data, 'http://127.0.0.1:8000/classes/'+cid + "/")) + print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/")) #add teacher as collaborator #curl -i -u "USER:PASSWORDD" -X PUT -d '' 'https://api.github.com/repos/USER/REPO/collaborators/COLLABORATOR' user = self.git - print(url) - os.system(url) + self.classes.append(data) if(len(self.sclass)==0): self.sclass = data['id'] else: self.sclass = self.sclass + "," + str(data['id']) + 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) + + command("git checkout -b " + data['name']) + command("touch welcome.txt") + command("git add welcome.txt") + command("git commit -m initial") + command("git push origin " + data['name']) + #git clone --single-branch --branch + os.chdir(cdir) + shutil.move(path1, self.username + "/" + data['name']) #upddate self.new s="" nar = '' @@ -283,6 +289,6 @@ class Student: } #print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/")) -data = getStudent("2022inafi") +data = getStudent("2022rkhondak") s = Student(data) -s.addClass('57') \ No newline at end of file +s.update() \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index cf27ba1..bddcb4c 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -194,56 +194,6 @@ class Teacher: 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)): @@ -369,6 +319,13 @@ class Teacher: print(c['name']) if classes == c['name']: cid = str(c['id']) + data1 = getDB("http://127.0.0.1:8000/classes/" + cid) + if(student in data1['unconfirmed']): + print (student + " already requested.") + return + if(student in data1['confirmed']): + print (student + " alredy enrolled.") + break if(cid==None): print(classes +" does not exist.") return @@ -409,7 +366,7 @@ class Teacher: "teacher": self.username, "assignments": "", "default_file": "", - "confirmed": "", + "confirmed": data1["confirmed"], "unconfirmed": data1['unconfirmed'] } print(putDB(d, data1['url'])) @@ -418,23 +375,33 @@ class Teacher: def addStudent(self, student, classes): cdir = os.getcwd() cpath = self.username + "/" + classes - path = "Students/" + classes + path = self.username + "/Students/" + classes if(os.path.isdir(path) == False): - os.mkdir(path) + os.makedirs(path) os.chdir(path) student = getDB("http://127.0.0.1:8000/students/" + student) command("git clone " + student['repo']) os.chdir(cdir) copy_tree(cpath, path + "/" + student['ion_user']) - os.chdir("Students/" + classes + "/" + student['ion_user']) + os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user']) command('git add .') + command('git checkout -b ' + classes) command('git commit -m Hello') command('git push -u origin ' + classes) def comment(self): print("heheheh") + + def addAssignment(): + print() + + def updateAssignnment(): + print() -data = getTeacher("eharris1") +data = getTeacher("mlauerbach") t = Teacher(data) -t.addStudent('2022rkhondak','English11_eharris1') +t.makeClass("Math5_mlauerbach", ["Week1_HW", "Test1"]) +input() +t.reqStudent() +t.addStudent("2022rkhondak", "Math5_mlauerbach") diff --git a/Students/English11_eharris1/2022rkhondak b/Students/English11_eharris1/2022rkhondak deleted file mode 160000 index e863f41..0000000 --- a/Students/English11_eharris1/2022rkhondak +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e863f414aed9de267ac442752c5585ead0536246 diff --git a/mlauerbach/Math5_mlauerbach/README.md b/mlauerbach/Math5_mlauerbach/README.md new file mode 100644 index 0000000..e69de29 diff --git a/mlauerbach/Math5_mlauerbach/Test1/instructions.txt b/mlauerbach/Math5_mlauerbach/Test1/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt b/mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt new file mode 100644 index 0000000..e69de29 From f0a602432fca4929a09265f724876864d39a8132 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 15:47:18 -0400 Subject: [PATCH 05/13] env --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e67073c..57b1443 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,6 @@ celerybeat.pid # Environments .env .venv -env/ venv/ ENV/ env.bak/ From 50e73fcc5410f828f174130bd0bfc3da87d1a107 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 15:48:13 -0400 Subject: [PATCH 06/13] env --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 57b1443..a1ec019 100644 --- a/.gitignore +++ b/.gitignore @@ -102,7 +102,6 @@ celerybeat.pid *.sage.py # Environments -.env .venv venv/ ENV/ From 486fc8e009bb9f93c4417aea8f027c8b27996fc3 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 15:49:05 -0400 Subject: [PATCH 07/13] ennv --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a1ec019..e67073c 100644 --- a/.gitignore +++ b/.gitignore @@ -102,7 +102,9 @@ celerybeat.pid *.sage.py # Environments +.env .venv +env/ venv/ ENV/ env.bak/ From 69e1efafe286c4375334c705edad531f41a7d4e4 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 15:49:45 -0400 Subject: [PATCH 08/13] requirements --- requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requirements.txt b/requirements.txt index fbc7e54..a9d9bcc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,13 +9,17 @@ djangorestframework==3.11.0 idna==2.9 oauthlib==3.1.0 prompt-toolkit==1.0.14 +pyclipper==1.1.0.post3 Pygments==2.6.1 PyInquirer==1.0.3 +pyperclip==1.8.0 pytz==2020.1 regex==2020.5.14 requests==2.23.0 +requests-oauthlib==1.3.0 selenium==3.141.0 six==1.15.0 sqlparse==0.3.1 urllib3==1.25.9 wcwidth==0.2.3 +Werkzeug==1.0.1 From b8c033b71f8cab469d3629e24e68cce5c9380965 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Wed, 10 Jun 2020 17:32:34 -0400 Subject: [PATCH 09/13] ff --- 2022rkhondak | 1 - CLI/s-git.py | 2 +- CLI/t-git.py | 13 ++++++++++++- CLI/test.py | 16 ---------------- fork/English11_eharris1 | 1 - 5 files changed, 13 insertions(+), 20 deletions(-) delete mode 160000 2022rkhondak delete mode 100644 CLI/test.py delete mode 160000 fork/English11_eharris1 diff --git a/2022rkhondak b/2022rkhondak deleted file mode 160000 index 8dca8b7..0000000 --- a/2022rkhondak +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8dca8b78c03fab721e9976a4675e2996802328a7 diff --git a/CLI/s-git.py b/CLI/s-git.py index 46d69bc..9c2b514 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -291,4 +291,4 @@ class Student: data = getStudent("2022rkhondak") s = Student(data) -s.update() \ No newline at end of file +#s.update() \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index bddcb4c..84d1d4e 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -373,6 +373,17 @@ class Teacher: #confirmed students def addStudent(self, student, classes): + for c in self.classes: + if(c['name'] == classes): + cid = c['id'] + data = getDB("http://127.0.0.1:8000/classes/" + str(cid)) + if(student in data['confirmed']): + print("Student already added to " + classes) + return + if(student in data['unconfirmed']): + print("Student has been enrolled in " + classes) + return + cdir = os.getcwd() cpath = self.username + "/" + classes path = self.username + "/Students/" + classes @@ -403,5 +414,5 @@ data = getTeacher("mlauerbach") t = Teacher(data) t.makeClass("Math5_mlauerbach", ["Week1_HW", "Test1"]) input() -t.reqStudent() +t.reqStudent("2022rkhondak", "Math5_mlauerbach") t.addStudent("2022rkhondak", "Math5_mlauerbach") diff --git a/CLI/test.py b/CLI/test.py deleted file mode 100644 index 11389ac..0000000 --- a/CLI/test.py +++ /dev/null @@ -1,16 +0,0 @@ -import subprocess -import os -import time - -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()[0] - print(output) - -command('echo hello') -command('python runtest.py') diff --git a/fork/English11_eharris1 b/fork/English11_eharris1 deleted file mode 160000 index ead6265..0000000 --- a/fork/English11_eharris1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ead6265a08327f2cc099d1e61c01030d916e8cd9 From 14ddb22b2ce6523fc52bfb703357604991fff15b Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 11 Jun 2020 00:58:47 -0400 Subject: [PATCH 10/13] d --- CLI/s-git.py | 68 +++++++++++++------ CLI/t-git.py | 31 +++++---- .../APBiology_sjfrank/Lab1/instructions.txt | 0 sjfrank/APBiology_sjfrank/README.md | 0 4 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 sjfrank/APBiology_sjfrank/Lab1/instructions.txt create mode 100644 sjfrank/APBiology_sjfrank/README.md diff --git a/CLI/s-git.py b/CLI/s-git.py index 9c2b514..91047f5 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -120,8 +120,6 @@ class Student: print(url) os.system(url) cdir = os.getcwd() - os.mkdir(self.username) - os.chdir(self.username) command('git clone https://github.com/' + self.git + '/' + self.username + '.git') os.chdir(self.username) command('git checkout master') @@ -147,33 +145,38 @@ class Student: } print(putDB(data, self.url)) print("Synced to " + self.username) - + + #update API and Github, all assignments / classes def update(self): + cdir = os.getcwd() + os.chdir(self.username) for c in self.classes: data = getDB("http://127.0.0.1:8000/classes/" + str(c['id'])) - os.chdir(self.username + "/" + data['name']) - command("git checkout -b " + data['name']) + command("git checkout " + data['name']) command("git add " + data['name']) command("git commit -m " + data['name']) - command("git push -u origin " + data['name']) command("git pull origin " + data['name']) + command("git push -u origin " + data['name']) + os.chdir(cdir) for c in self.new: self.addClass(str(c['id'])) + command("git checkout master") #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: + return None + if((cid in self.snew) == True): print("Not added by teacher yet.") - return None + return None data = getDB('http://127.0.0.1:8000/classes/'+ str(cid)) + print(os.getcwd()) pwd= input("Enter Github password: ") tgit = getDB("http://127.0.0.1:8000/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 + "'" @@ -199,23 +202,22 @@ class Student: self.sclass = self.sclass + "," + str(data['id']) 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) + print(cdir) + # 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) - command("git checkout -b " + data['name']) - command("touch welcome.txt") - command("git add welcome.txt") + os.chdir(self.username) + command("git branch " + data['name']) command("git commit -m initial") command("git push origin " + data['name']) #git clone --single-branch --branch os.chdir(cdir) - shutil.move(path1, self.username + "/" + data['name']) #upddate self.new s="" nar = '' @@ -288,7 +290,29 @@ class Student: 'completed':self.completed } #print(putDB(data, "http://127.0.0.1:8000/students/" + self.username + "/")) + + def viewClass(self, courses): + cdir = os.getcwd() + os.chdir(self.username) + for c in self.classes: + if c['name'] == courses: + print(courses) + command("git checkout " + courses) + print(os.listdir()) + return + os.chdir(cdir) + print("Class not found") + return + + def submit(self, courses): + command("git add .") + command("git commit -m submit") + command("git tag " + parts[1] + "-final") + command("git push -u origin " + self.username + " --tags") -data = getStudent("2022rkhondak") +data = getStudent("2023rumareti") s = Student(data) +s.update() + + #s.update() \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index 84d1d4e..24a534b 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -371,33 +371,34 @@ class Teacher: } print(putDB(d, data1['url'])) - #confirmed students - def addStudent(self, student, classes): + #confirmed students + # pull student work and push updates + def updateStudent(self, student, classes): for c in self.classes: if(c['name'] == classes): cid = c['id'] data = getDB("http://127.0.0.1:8000/classes/" + str(cid)) - if(student in data['confirmed']): - print("Student already added to " + classes) - return if(student in data['unconfirmed']): - print("Student has been enrolled in " + classes) + print(student + " has not accepted request to " + classes) return cdir = os.getcwd() cpath = self.username + "/" + classes path = self.username + "/Students/" + classes + spath = self.username + "/Students/" + classes + "/" + student if(os.path.isdir(path) == False): os.makedirs(path) - os.chdir(path) - student = getDB("http://127.0.0.1:8000/students/" + student) - command("git clone " + student['repo']) - os.chdir(cdir) + if(os.path.isdir(spath) == False): + os.chdir(path) + student = getDB("http://127.0.0.1:8000/students/" + student) + command("git clone " + student['repo']) + os.chdir(cdir) copy_tree(cpath, path + "/" + student['ion_user']) os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user']) + command('git checkout ' + classes) + command('git pull origin ' + classes) command('git add .') - command('git checkout -b ' + classes) command('git commit -m Hello') command('git push -u origin ' + classes) @@ -412,7 +413,7 @@ class Teacher: data = getTeacher("mlauerbach") t = Teacher(data) -t.makeClass("Math5_mlauerbach", ["Week1_HW", "Test1"]) -input() -t.reqStudent("2022rkhondak", "Math5_mlauerbach") -t.addStudent("2022rkhondak", "Math5_mlauerbach") +t.reqStudent("2023rumareti", 'Math5_mlauerbach') +t.updateStudent("2023rumareti", 'Math5_mlauerbach') + + diff --git a/sjfrank/APBiology_sjfrank/Lab1/instructions.txt b/sjfrank/APBiology_sjfrank/Lab1/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/sjfrank/APBiology_sjfrank/README.md b/sjfrank/APBiology_sjfrank/README.md new file mode 100644 index 0000000..e69de29 From 5332a3281641a671919ba71ea83cc6856f14e6a6 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 11 Jun 2020 16:13:05 -0400 Subject: [PATCH 11/13] adding-assignments --- CLI/back.py | 2 + CLI/s-git.py | 118 ++++--- CLI/t-git.py | 312 ++++++++++-------- .../api/migrations/0007_auto_20200611_0831.py | 22 ++ Website/api/models.py | 2 +- Website/api/serializers.py | 2 +- .../instructions.txt => Entry1/rubric.txt} | 0 .../Entry1/sample_entry.txt | 0 .../English11_eharris1/Entry2/instruct.txt | 0 .../Week1_HW/instructions.txt | 0 .../APBiology_sjfrank/Lab1/instructions.txt | 0 sjfrank/APBiology_sjfrank/README.md | 0 12 files changed, 267 insertions(+), 191 deletions(-) create mode 100644 CLI/back.py create mode 100644 Website/api/migrations/0007_auto_20200611_0831.py rename eharris1/English11_eharris1/{Journal1/instructions.txt => Entry1/rubric.txt} (100%) rename mlauerbach/Math5_mlauerbach/README.md => eharris1/English11_eharris1/Entry1/sample_entry.txt (100%) rename mlauerbach/Math5_mlauerbach/Test1/instructions.txt => eharris1/English11_eharris1/Entry2/instruct.txt (100%) delete mode 100644 mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt delete mode 100644 sjfrank/APBiology_sjfrank/Lab1/instructions.txt delete mode 100644 sjfrank/APBiology_sjfrank/README.md diff --git a/CLI/back.py b/CLI/back.py new file mode 100644 index 0000000..05cf8af --- /dev/null +++ b/CLI/back.py @@ -0,0 +1,2 @@ +import os +os.spawnl(os.P_DETACH, 'some_long_running_command') \ No newline at end of file diff --git a/CLI/s-git.py b/CLI/s-git.py index 91047f5..2720a4a 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -56,6 +56,7 @@ def command(command): p=process.poll() output = process.communicate()[0] print(output.decode('utf-8')) + return output.decode('utf-8') #################################################################################################################################### @@ -152,30 +153,35 @@ class Student: cdir = os.getcwd() os.chdir(self.username) for c in self.classes: - data = getDB("http://127.0.0.1:8000/classes/" + str(c['id'])) + print("UPDATING CLASS: " + str(c['name'])) + data = getDB("http://127.0.0.1:8000/classes/" + str(c['name'])) + command("git checkout master") command("git checkout " + data['name']) - command("git add " + data['name']) + command("git add .") command("git commit -m " + data['name']) command("git pull origin " + data['name']) command("git push -u origin " + data['name']) + command("git checkout master") os.chdir(cdir) for c in self.new: - self.addClass(str(c['id'])) + print("ADDING CLASS: " + str(c['name'])) + self.addClass(str(c['name'])) command("git checkout master") #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.") - return None - if((cid in self.snew) == True): - print("Not added by teacher yet.") - return None data = getDB('http://127.0.0.1:8000/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): + print("Not added by teacher yet.") + return None + + #add class teacher as cocllaborator to student repo print(os.getcwd()) pwd= input("Enter Github password: ") tgit = getDB("http://127.0.0.1:8000/teachers/" + data['teacher'] + "/")['git'] @@ -183,26 +189,7 @@ class Student: print(url) os.system(url) - data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") - data['unconfirmed'] = data['unconfirmed'].replace(self.username, "") - data['confirmed'] = data['confirmed'] + "," + self.username - if(data['confirmed'][0] == ','): - data['confirmed'] = data['confirmed'][1:] - print(data['confirmed']) - print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/")) - - #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): - self.sclass = data['id'] - else: - self.sclass = self.sclass + "," + str(data['id']) - cdir = os.getcwd() - print(cdir) # path1 = self.username + "/" + self.username # path2 = self.username # if(os.path.isdir(path1)): @@ -212,24 +199,46 @@ class Student: # command("git clone " + self.repo) # os.chdir(self.username) + #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 os.chdir(cdir) + + # data['unconfirmed'] = data['unconfirmed'].replace("," + self.username, "") + # data['unconfirmed'] = data['unconfirmed'].replace(self.username, "") + # data['confirmed'] = data['confirmed'] + "," + self.username + # if(data['confirmed'][0] == ','): + # data['confirmed'] = data['confirmed'][1:] + # print(data['confirmed']) + # print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/")) + + #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): + self.sclass = data['name'] + else: + self.sclass = self.sclass + "," + str(data['name']) + #upddate self.new - s="" - nar = '' + snew="" + new = [] for i in range(len(self.new)): - if(self.new[i]['id'] == int(data['id'])): + if(self.new[i]['name'] == data['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 + snew = snew + str(c['name']) + "," + new.append(getDB("http://127.0.0.1:8000/classes/" + str(cid))) + self.snew=snew + self.new=new break #update teacher instance in db, classes field @@ -296,7 +305,6 @@ class Student: os.chdir(self.username) for c in self.classes: if c['name'] == courses: - print(courses) command("git checkout " + courses) print(os.listdir()) return @@ -304,15 +312,35 @@ class Student: print("Class not found") return - def submit(self, courses): + def submit(self, course, assignment): + cdir = os.getcwd() + os.chdir(self.username) + print(os.getcwd()) + command("git add .") + command("git commit -m update") + command('git checkout ' + course) + time.sleep(5) + ass = os.listdir() + inclass = False + for a in ass: + if a == assignment: + inclass = True + break + if(inclass == False): + print(assignment + " not an assignment of " + course) + command('git checkout master') + os.chdir(cdir) + return + + command('touch ' + assignment + '/SUBMISSION') command("git add .") command("git commit -m submit") - command("git tag " + parts[1] + "-final") - command("git push -u origin " + self.username + " --tags") + command("git tag " + assignment + "-final") + command("git push -u origin " + course + " --tags") + command('git checkout master') + os.chdir(cdir) -data = getStudent("2023rumareti") +data = getStudent("2022rkhondak") s = Student(data) -s.update() - - -#s.update() \ No newline at end of file +#s.viewClass("English11_eharris1") +s.submit("English11_eharris1", "Entry1") \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index 24a534b..e6dfb7e 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -90,59 +90,10 @@ class Teacher: self.classes = classes self.sclass=str(data['classes']) - if(os.path.isdir(self.username)): + if(os.path.isdir(self.username + "/Students")): 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) + os.makedirs(self.username + "/Students") #class name format: _ @@ -216,12 +167,12 @@ class Teacher: #upate self.classes self.classes.append(data) if(len(self.sclass)==0): - self.sclass = data['id'] + self.sclass = data['name'] else: - self.sclass = self.sclass + "," + str(data['id']) + self.sclass = self.sclass + "," + str(data['name']) #update teacher instance in db, classes field - data={ + teacher={ 'first_name':self.first_name, 'last_name':self.last_name, 'git':self.git, @@ -230,9 +181,9 @@ class Teacher: 'classes':self.sclass, 'email':self.email } - putDB(data, self.url) + putDB(teacher, self.url) - return data + return teacher #make a new class from scratch @@ -241,8 +192,16 @@ class Teacher: def makeClass(self, cname, assignments): #check if class exists path = self.username + "/" + cname - if(os.path.exists(path)): + isclass = False + acourses = getDB("http://127.0.0.1:8000/classes/")['results'] + for c in acourses: + if c['name'] == cname: + isclass=True + break + if(os.path.exists(path) or isclass): print("Class already exists: " + cname) + if(isclass): + print("Class already exists in Database") return else: if((("_" + self.username) in cname) == False): @@ -272,22 +231,16 @@ class Teacher: 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 + print("DELETE: " + self.classes[i]['name']) for i in range(len(self.classes)): - if(self.classes[i]['id'] == int(cid)): - print("DELETE: " + self.classes[i]['name']) + c = self.classes[i] + if(c['name'] == cname): del self.classes[i] s="" #recreate sclass field, using ids for c in self.classes: - s = s + str(c['id']) + "," + s = s + str(c['name']) + "," print(s) s = s[:-1] print(s) @@ -301,7 +254,7 @@ class Teacher: 'email':self.email } print(putDB(data, self.url)) - delDB("http://127.0.0.1:8000/classes/" + cid + "/") + delDB("http://127.0.0.1:8000/classes/" + cname + "/") break #remove locally @@ -312,108 +265,179 @@ class Teacher: #remove from student directories -#make student repo by student id - def reqStudent(self, student, classes): - cid = None - for c in self.classes: - print(c['name']) - if classes == c['name']: - cid = str(c['id']) - data1 = getDB("http://127.0.0.1:8000/classes/" + cid) - if(student in data1['unconfirmed']): - print (student + " already requested.") - return - if(student in data1['confirmed']): - print (student + " alredy enrolled.") - break - if(cid==None): - print(classes +" does not exist.") - return - data = getDB("http://127.0.0.1:8000/students/" + student) - try: - if(data['added_to']==""): - data['added_to']=cid - else: - data['added_to']=data['added_to']+ "," + cid - except: - print(student + " does not exist.") + def isStudent(self, student): + r = requests.get(url = "http://127.0.0.1:8000/students/" + student + "/", auth=('raffukhondaker','hackgroup1')) + if(r.status_code != 200): + return False + return True + + def reqStudent(self, sname, cname): + if(self.isStudent(sname) == False): + print(sname + " does not exist.") return - print(data['added_to']) - d={ - 'first_name':data["first_name"], - 'last_name':data["last_name"], - 'git':data["git"], - 'ion_user':data["ion_user"], - 'student_id':data["student_id"], - 'added_to':data['added_to'], - 'classes':data["classes"], - 'email':data["email"], - 'grade':data["grade"], - 'completed':data["completed"], - 'repo':data["repo"] + course = getDB("http://127.0.0.1:8000/classes/" + cname) + if(sname in course['unconfirmed']): + print (sname + " already requested.") + return + if(sname in course['confirmed']): + print (sname + " alredy enrolled.") + return + + student = getDB("http://127.0.0.1:8000/students/" + sname) + try: + if(student['added_to']==""): + student['added_to']=course['name'] + else: + student['added_to']=student['added_to']+ "," + course['name'] + except: + print(sname + " does not exist.") + return + print(student['added_to']) + s={ + 'first_name':student["first_name"], + 'last_name':student["last_name"], + 'git':student["git"], + 'ion_user':student["ion_user"], + 'student_id':student["student_id"], + 'added_to':student['added_to'], + 'classes':student["classes"], + 'email':student["email"], + 'grade':student["grade"], + 'completed':student["completed"], + 'repo':student["repo"] } - print(putDB(d, data['url'])) - data1 = getDB("http://127.0.0.1:8000/classes/" + cid) - if(data1['unconfirmed']==""): - data1['unconfirmed']=data['ion_user'] + student = putDB(s, student['url']) + + if(course['unconfirmed']==""): + course['unconfirmed']=student['ion_user'] else: - data1['unconfirmed']=data1['unconfirmed']+ "," + data['ion_user'] - d = { - "name": classes, + course['unconfirmed']=course['unconfirmed']+ "," + student['ion_user'] + cinfo = { + "name": course['name'], "repo": "", - "path": self.username + "/" + classes, + "path": self.username + "/" + course['name'], "teacher": self.username, "assignments": "", "default_file": "", - "confirmed": data1["confirmed"], - "unconfirmed": data1['unconfirmed'] + "confirmed": course["confirmed"], + "unconfirmed": course['unconfirmed'] } - print(putDB(d, data1['url'])) + print(putDB(cinfo, course['url'])) - #confirmed students - # pull student work and push updates - def updateStudent(self, student, classes): - for c in self.classes: - if(c['name'] == classes): - cid = c['id'] - data = getDB("http://127.0.0.1:8000/classes/" + str(cid)) - if(student in data['unconfirmed']): - print(student + " has not accepted request to " + classes) - return + #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): + print(sname + " does not exist.") + return + student = getDB("http://127.0.0.1:8000/students/" + sname) + course = getDB("http://127.0.0.1:8000/classes/" + cname) + + if((student['ion_user'] in course['unconfirmed']) == False): + print("Student has not been requested to join yet.") + return + if((cname in student['added_to']) == True or (cname in student['classes']) == False): + print("Student has not confirmed class yet") + return + if(os.path.exists(self.username + "/Students/" + cname + "/" + student['ion_user']) or (student['ion_user'] in course['confirmed']) == True): + print("Student already added to class") + + #git clone and make student/class directories cdir = os.getcwd() - cpath = self.username + "/" + classes - path = self.username + "/Students/" + classes - spath = self.username + "/Students/" + classes + "/" + student + cpath = self.username + "/" + cname + path = self.username + "/Students/" + cname + spath = self.username + "/Students/" + cname + "/" + student['ion_user'] if(os.path.isdir(path) == False): os.makedirs(path) if(os.path.isdir(spath) == False): os.chdir(path) - student = getDB("http://127.0.0.1:8000/students/" + student) command("git clone " + student['repo']) os.chdir(cdir) - copy_tree(cpath, path + "/" + student['ion_user']) - os.chdir(self.username + "/Students/" + classes + "/" + student['ion_user']) - command('git checkout ' + classes) - command('git pull origin ' + classes) + #push to git + copy_tree(cpath, path + "/" + student['ion_user']) + os.chdir(spath) + command('git checkout ' + cname) + command('git pull origin ' + cname) command('git add .') command('git commit -m Hello') - command('git push -u origin ' + classes) + command('git push -u origin ' + cname) + command('git checkout master') + + if(course['confirmed']==""): + course['confirmed']=student['ion_user'] + else: + course['confirmed']=course['confirmed']+ "," + student['ion_user'] + cinfo = { + "name": course['name'], + "repo": "", + "path": course['path'], + "teacher": course['name'], + "assignments": "", + "default_file": "", + "confirmed": course["confirmed"], + "unconfirmed": course['unconfirmed'] + } + print(putDB(cinfo, course['url'])) + + def addAssignment(self, path, course): + parts = path.split("/") + aname = parts[len(parts)-1] + if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in self.sclass: + print("Not valid path.") + return + if((parts[1] in self.sclass) == False): + print("Not in valid class directory") + return + ar = [x[2] for x in os.walk(path)] + print(ar) + for folder in ar: + if len(folder) == 0: + print("Assignment is completely empty, need a file.") + return + course = getDB("http://127.0.0.1:8000/classes/" + course) + slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name']) + cdir = os.getcwd() + for st in slist: + if st in 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) + print(st) + print(copy_tree(path, spath + "/" + aname)) + os.chdir(spath) + command('git checkout ' + course['name']) + command('git pull origin ' + course['name']) + command('git add .') + command('git commit -m Hello') + command('git push -u origin ' + course['name']) + os.chdir(cdir) + else: + print(st + " already has assignment") + + def getHistory(self, student, course): + course = getDB("http://127.0.0.1:8000/classes/" + course) + try: + if((student in course['confirmed']) == False): + print("Student not in class") + return + except: + print("class does not exist") + return + os.chdir(self.username + "/Students/" + course['name'] + "/" + student) + process = subprocess.Popen(['git', 'log', course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + p=process.poll() + output = process.communicate()[0].decode('utf-8') + print(output) def comment(self): print("heheheh") - def addAssignment(): - print() - def updateAssignnment(): print() -data = getTeacher("mlauerbach") +data = getTeacher("eharris1") t = Teacher(data) -t.reqStudent("2023rumareti", 'Math5_mlauerbach') -t.updateStudent("2023rumareti", 'Math5_mlauerbach') - - +t.getHistory("2022rkhondak", "English11_eharris1") diff --git a/Website/api/migrations/0007_auto_20200611_0831.py b/Website/api/migrations/0007_auto_20200611_0831.py new file mode 100644 index 0000000..801cbeb --- /dev/null +++ b/Website/api/migrations/0007_auto_20200611_0831.py @@ -0,0 +1,22 @@ +# Generated by Django 3.0.7 on 2020-06-11 08:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0006_auto_20200610_0631'), + ] + + operations = [ + migrations.RemoveField( + model_name='classes', + name='id', + ), + migrations.AlterField( + model_name='classes', + name='name', + field=models.CharField(max_length=100, primary_key=True, serialize=False), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index e75fddd..d80266d 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -19,7 +19,7 @@ class Assignment(models.Model): return '%s' % (self.name) class Classes(models.Model): - name = models.CharField(max_length=100) + name = models.CharField(primary_key=True, max_length=100) repo=models.URLField(default="") path=models.CharField(max_length=100, default="") teacher=models.CharField(max_length=100, default="") diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 6eb0f21..4ce5b91 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -20,7 +20,7 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer): # default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Classes - fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id', 'confirmed', 'unconfirmed'] + fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed'] class StudentSerializer(serializers.HyperlinkedModelSerializer): # classes = ClassesSerializer(many=True, read_only=True,allow_null=True) diff --git a/eharris1/English11_eharris1/Journal1/instructions.txt b/eharris1/English11_eharris1/Entry1/rubric.txt similarity index 100% rename from eharris1/English11_eharris1/Journal1/instructions.txt rename to eharris1/English11_eharris1/Entry1/rubric.txt diff --git a/mlauerbach/Math5_mlauerbach/README.md b/eharris1/English11_eharris1/Entry1/sample_entry.txt similarity index 100% rename from mlauerbach/Math5_mlauerbach/README.md rename to eharris1/English11_eharris1/Entry1/sample_entry.txt diff --git a/mlauerbach/Math5_mlauerbach/Test1/instructions.txt b/eharris1/English11_eharris1/Entry2/instruct.txt similarity index 100% rename from mlauerbach/Math5_mlauerbach/Test1/instructions.txt rename to eharris1/English11_eharris1/Entry2/instruct.txt diff --git a/mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt b/mlauerbach/Math5_mlauerbach/Week1_HW/instructions.txt deleted file mode 100644 index e69de29..0000000 diff --git a/sjfrank/APBiology_sjfrank/Lab1/instructions.txt b/sjfrank/APBiology_sjfrank/Lab1/instructions.txt deleted file mode 100644 index e69de29..0000000 diff --git a/sjfrank/APBiology_sjfrank/README.md b/sjfrank/APBiology_sjfrank/README.md deleted file mode 100644 index e69de29..0000000 From 444c5a94f070239f22b3a766d3795c4ca32939e1 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 11 Jun 2020 20:29:06 -0400 Subject: [PATCH 12/13] assignments --- CLI/t-git.py | 90 ++++++++++++++++--- .../api/migrations/0002_auto_20200609_0358.py | 18 ---- .../api/migrations/0002_auto_20200612_0010.py | 89 ++++++++++++++++++ .../api/migrations/0003_auto_20200609_2206.py | 40 --------- .../api/migrations/0003_auto_20200612_0012.py | 24 +++++ .../api/migrations/0004_student_added_to.py | 18 ---- .../api/migrations/0005_student_completed.py | 18 ---- .../api/migrations/0006_auto_20200610_0631.py | 28 ------ .../api/migrations/0007_auto_20200611_0831.py | 22 ----- Website/api/models.py | 4 +- Website/api/serializers.py | 4 +- Website/skoolsite/urls.py | 13 ++- .../{Entry1 => Entry1_English11}/rubric.txt | 0 .../sample_entry.txt | 0 .../{Entry2 => Entry2_English11}/instruct.txt | 0 15 files changed, 207 insertions(+), 161 deletions(-) delete mode 100644 Website/api/migrations/0002_auto_20200609_0358.py create mode 100644 Website/api/migrations/0002_auto_20200612_0010.py delete mode 100644 Website/api/migrations/0003_auto_20200609_2206.py create mode 100644 Website/api/migrations/0003_auto_20200612_0012.py delete mode 100644 Website/api/migrations/0004_student_added_to.py delete mode 100644 Website/api/migrations/0005_student_completed.py delete mode 100644 Website/api/migrations/0006_auto_20200610_0631.py delete mode 100644 Website/api/migrations/0007_auto_20200611_0831.py rename eharris1/English11_eharris1/{Entry1 => Entry1_English11}/rubric.txt (100%) rename eharris1/English11_eharris1/{Entry1 => Entry1_English11}/sample_entry.txt (100%) rename eharris1/English11_eharris1/{Entry2 => Entry2_English11}/instruct.txt (100%) diff --git a/CLI/t-git.py b/CLI/t-git.py index e6dfb7e..1582129 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -8,7 +8,7 @@ import shutil import time import pyperclip from distutils.dir_util import copy_tree - +from datetime import datetime #git clone student directory ==> /classes/assignments @@ -213,11 +213,12 @@ class Teacher: 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) + # for a in assignments: + + # os.mkdir(a) + # f=open(a + "/instructions.txt", "w") + # f.close() + # os.chdir(cdir) data = self.addClass(path) return data @@ -382,7 +383,7 @@ class Teacher: } print(putDB(cinfo, course['url'])) - def addAssignment(self, path, course): + def addAssignment(self, path, course, due): parts = path.split("/") aname = parts[len(parts)-1] if(os.path.isdir(path) == 0 or len(parts) < 3) or aname in self.sclass: @@ -397,6 +398,14 @@ class Teacher: if len(folder) == 0: print("Assignment is completely empty, need a file.") return + + ass = { + 'name': parts[len(parts)-1], + 'path':path, + 'classes':course, + 'teacher':self.username, + 'due_date':due + } course = getDB("http://127.0.0.1:8000/classes/" + course) slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name']) cdir = os.getcwd() @@ -426,11 +435,70 @@ class Teacher: except: print("class does not exist") return + + cdir = os.getcwd() os.chdir(self.username + "/Students/" + course['name'] + "/" + student) - process = subprocess.Popen(['git', 'log', course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process = subprocess.Popen(['git', 'log', '-30', course['name']], stdout=subprocess.PIPE,stderr=subprocess.PIPE) p=process.poll() - output = process.communicate()[0].decode('utf-8') - print(output) + output = process.communicate()[0].decode('utf-8').split('\n\n') + months = ['Jan', 'Feb', 'Mar', "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"] + for i in range(len(output)): + if("Date" in output[i]): + c = output[i].split("\n") + for k in range(len(c)): + temp = [] + if('commit' in c[k]): + c[k] = c[k].replace('commit', '').strip() + elif('Date:' in c[k]): + c[k] = c[k].replace('Date:', '').strip() + date = c[2].split(" ") + times = date[3].split(":") + mon = -1 + for m in range(len(months)): + 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') + output[i] = [c[0], d1] + os.chdir(cdir) + return output + + ''' + assignment = { + 'name': English11_eharris1, + 'due_date': 2020-06-11 16:58:33.383124 + } + ''' + #check if assignment changed after due date + def afterSubmit(self, course, assignment, student): + ''' + assignment = getDB() + ''' + assignment = { + 'name': assignment, + 'due_date': "2020-04-11 16:58:33.383124", + 'classes':course + } + log = self.getHistory(student, course) + assignment['due_date'] = datetime.strptime(assignment['due_date'], '%Y-%m-%d %H:%M:%S.%f') + late = False + 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() + output = process.communicate()[0].decode('utf-8') + if(assignment['name'] in output): + print(l[1]) + print(assignment['due_date']) + print("--------------") + if(l[1] > assignment['due_date']): + print("LATE") + os.chdir(cdir) + return True + print("On time") + os.chdir(cdir) + return False def comment(self): print("heheheh") @@ -440,4 +508,4 @@ class Teacher: data = getTeacher("eharris1") t = Teacher(data) -t.getHistory("2022rkhondak", "English11_eharris1") +t.addAssignment("English11_eharris1", "Entry1", '2022rkhondak',"2020-05-11 12:25:00") diff --git a/Website/api/migrations/0002_auto_20200609_0358.py b/Website/api/migrations/0002_auto_20200609_0358.py deleted file mode 100644 index bb2af02..0000000 --- a/Website/api/migrations/0002_auto_20200609_0358.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-09 03:58 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='teacher', - name='classes', - field=models.CharField(blank=True, default='', max_length=100), - ), - ] diff --git a/Website/api/migrations/0002_auto_20200612_0010.py b/Website/api/migrations/0002_auto_20200612_0010.py new file mode 100644 index 0000000..0746e20 --- /dev/null +++ b/Website/api/migrations/0002_auto_20200612_0010.py @@ -0,0 +1,89 @@ +# Generated by Django 3.0.7 on 2020-06-12 00:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='id', + ), + migrations.RemoveField( + model_name='classes', + name='id', + ), + migrations.RemoveField( + model_name='student', + name='webmail', + ), + migrations.AddField( + model_name='classes', + name='confirmed', + field=models.TextField(blank=True, default=''), + ), + migrations.AddField( + model_name='classes', + name='unconfirmed', + field=models.TextField(blank=True, default=''), + ), + migrations.AddField( + model_name='student', + name='added_to', + field=models.CharField(blank=True, default='', max_length=100), + ), + migrations.AddField( + model_name='student', + name='completed', + field=models.TextField(blank=True, default=''), + ), + migrations.AddField( + model_name='student', + name='email', + field=models.CharField(blank=True, default='', max_length=100), + ), + migrations.AddField( + model_name='teacher', + name='email', + field=models.CharField(blank=True, default='', max_length=100), + ), + migrations.AlterField( + model_name='assignment', + name='files', + field=models.CharField(blank=True, default='', max_length=100), + ), + migrations.AlterField( + model_name='assignment', + name='name', + field=models.CharField(max_length=100, primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='classes', + name='name', + field=models.CharField(max_length=100, primary_key=True, serialize=False), + ), + migrations.RemoveField( + model_name='student', + name='classes', + ), + migrations.AddField( + model_name='student', + name='classes', + field=models.CharField(blank=True, default='', max_length=100), + ), + migrations.AlterField( + model_name='student', + name='repo', + field=models.URLField(blank=True, default=''), + ), + migrations.AlterField( + model_name='teacher', + name='classes', + field=models.CharField(blank=True, default='', max_length=100), + ), + ] diff --git a/Website/api/migrations/0003_auto_20200609_2206.py b/Website/api/migrations/0003_auto_20200609_2206.py deleted file mode 100644 index d33709f..0000000 --- a/Website/api/migrations/0003_auto_20200609_2206.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-09 22:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0002_auto_20200609_0358'), - ] - - operations = [ - migrations.RemoveField( - model_name='student', - name='repo', - ), - migrations.RemoveField( - model_name='student', - name='webmail', - ), - migrations.AddField( - model_name='student', - name='email', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AddField( - model_name='teacher', - name='email', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.RemoveField( - model_name='student', - name='classes', - ), - migrations.AddField( - model_name='student', - name='classes', - field=models.CharField(blank=True, default='', max_length=100), - ), - ] diff --git a/Website/api/migrations/0003_auto_20200612_0012.py b/Website/api/migrations/0003_auto_20200612_0012.py new file mode 100644 index 0000000..465ea03 --- /dev/null +++ b/Website/api/migrations/0003_auto_20200612_0012.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-12 00:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_auto_20200612_0010'), + ] + + operations = [ + migrations.AddField( + model_name='assignment', + name='id', + field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'), + preserve_default=False, + ), + migrations.AlterField( + model_name='assignment', + name='name', + field=models.CharField(max_length=100), + ), + ] diff --git a/Website/api/migrations/0004_student_added_to.py b/Website/api/migrations/0004_student_added_to.py deleted file mode 100644 index 71ed04f..0000000 --- a/Website/api/migrations/0004_student_added_to.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-09 22:27 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0003_auto_20200609_2206'), - ] - - operations = [ - migrations.AddField( - model_name='student', - name='added_to', - field=models.CharField(blank=True, default='', max_length=100), - ), - ] diff --git a/Website/api/migrations/0005_student_completed.py b/Website/api/migrations/0005_student_completed.py deleted file mode 100644 index 28d0f9b..0000000 --- a/Website/api/migrations/0005_student_completed.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-10 01:10 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0004_student_added_to'), - ] - - operations = [ - migrations.AddField( - model_name='student', - name='completed', - field=models.TextField(blank=True, default=''), - ), - ] diff --git a/Website/api/migrations/0006_auto_20200610_0631.py b/Website/api/migrations/0006_auto_20200610_0631.py deleted file mode 100644 index 2083d0e..0000000 --- a/Website/api/migrations/0006_auto_20200610_0631.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-10 06:31 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0005_student_completed'), - ] - - operations = [ - migrations.AddField( - model_name='classes', - name='confirmed', - field=models.TextField(blank=True, default=''), - ), - migrations.AddField( - model_name='classes', - name='unconfirmed', - field=models.TextField(blank=True, default=''), - ), - migrations.AddField( - model_name='student', - name='repo', - field=models.URLField(blank=True, default=''), - ), - ] diff --git a/Website/api/migrations/0007_auto_20200611_0831.py b/Website/api/migrations/0007_auto_20200611_0831.py deleted file mode 100644 index 801cbeb..0000000 --- a/Website/api/migrations/0007_auto_20200611_0831.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-11 08:31 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0006_auto_20200610_0631'), - ] - - operations = [ - migrations.RemoveField( - model_name='classes', - name='id', - ), - migrations.AlterField( - model_name='classes', - name='name', - field=models.CharField(max_length=100, primary_key=True, serialize=False), - ), - ] diff --git a/Website/api/models.py b/Website/api/models.py index d80266d..06b9015 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -8,10 +8,10 @@ class DefFiles(models.Model): teacher=models.CharField(max_length=100) class Assignment(models.Model): - name=models.CharField(max_length=100) + name=models.CharField(max_length=100, primary_key=True) due_date=models.DateTimeField() # files = models.ManyToManyField(DefFiles) - files=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) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 4ce5b91..0ff5ae6 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -9,11 +9,11 @@ class DefFilesSerializer(serializers.HyperlinkedModelSerializer): fields = ['name', 'path','assignment','classes', "teacher",'url', 'id'] class AssignmentSerializer(serializers.HyperlinkedModelSerializer): - permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + #permissions_classes = [permissions.IsAuthenticatedOrReadOnly] # files = DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Assignment - fields = ['name', 'due_date', 'url', 'path' , "classes","teacher",'files', 'id'] + fields = ['url','name', 'due_date', 'path' , "classes","teacher"] class ClassesSerializer(serializers.HyperlinkedModelSerializer): # assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) diff --git a/Website/skoolsite/urls.py b/Website/skoolsite/urls.py index 1c8f9f2..e5b2c2b 100644 --- a/Website/skoolsite/urls.py +++ b/Website/skoolsite/urls.py @@ -15,8 +15,17 @@ router.register(r'files', views.DefFilesViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [ - path('', include(router.urls)), + path('api/', include(router.urls)), path('api-auth/', include('rest_framework.urls')), path('admin/', admin.site.urls), -] \ No newline at end of file +] +''' +{ + "name": "Entry1", + "due_date": "2020-05-11 12:25:00", + "path": "", + "classes": "", + "teacher": "" +} +''' \ No newline at end of file diff --git a/eharris1/English11_eharris1/Entry1/rubric.txt b/eharris1/English11_eharris1/Entry1_English11/rubric.txt similarity index 100% rename from eharris1/English11_eharris1/Entry1/rubric.txt rename to eharris1/English11_eharris1/Entry1_English11/rubric.txt diff --git a/eharris1/English11_eharris1/Entry1/sample_entry.txt b/eharris1/English11_eharris1/Entry1_English11/sample_entry.txt similarity index 100% rename from eharris1/English11_eharris1/Entry1/sample_entry.txt rename to eharris1/English11_eharris1/Entry1_English11/sample_entry.txt diff --git a/eharris1/English11_eharris1/Entry2/instruct.txt b/eharris1/English11_eharris1/Entry2_English11/instruct.txt similarity index 100% rename from eharris1/English11_eharris1/Entry2/instruct.txt rename to eharris1/English11_eharris1/Entry2_English11/instruct.txt From 8b4010c66bb24f800b2ef8b2e678709602b558c1 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Thu, 11 Jun 2020 22:17:03 -0400 Subject: [PATCH 13/13] getStudents() --- CLI/s-git.py | 31 +++--- CLI/t-git.py | 101 ++++++++++++++---- Website/api/migrations/0001_initial.py | 43 ++++---- .../api/migrations/0002_auto_20200612_0010.py | 89 --------------- ...612_0012.py => 0002_auto_20200612_0135.py} | 15 ++- .../api/migrations/0003_auto_20200612_0135.py | 23 ++++ 6 files changed, 153 insertions(+), 149 deletions(-) delete mode 100644 Website/api/migrations/0002_auto_20200612_0010.py rename Website/api/migrations/{0003_auto_20200612_0012.py => 0002_auto_20200612_0135.py} (53%) create mode 100644 Website/api/migrations/0003_auto_20200612_0135.py diff --git a/CLI/s-git.py b/CLI/s-git.py index 2720a4a..19ca26c 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -12,7 +12,7 @@ import pyperclip #get teacher info from api def getStudent(ion_user): - URL = "http://127.0.0.1:8000/students/" + 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() @@ -69,7 +69,7 @@ class Student: 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.url= "http://127.0.0.1:8000/api/students/" + self.username + "/" self.email = data['email'] self.grade = data['grade'] self.student_id=data['student_id'] @@ -87,7 +87,7 @@ class Student: pass classes=[] for c in cid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" + url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" classes.append(getDB(url)) self.classes = classes @@ -105,7 +105,7 @@ class Student: pass nclasses=[] for c in nid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" + url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" nclasses.append(getDB(url)) self.new = nclasses @@ -154,8 +154,8 @@ class Student: os.chdir(self.username) for c in self.classes: print("UPDATING CLASS: " + str(c['name'])) - data = getDB("http://127.0.0.1:8000/classes/" + str(c['name'])) - command("git checkout master") + data = getDB("http://127.0.0.1:8000/api/classes/" + str(c['name'])) + # command("git checkout master") command("git checkout " + data['name']) command("git add .") command("git commit -m " + data['name']) @@ -173,7 +173,7 @@ class Student: #add classes from 'new' field def addClass(self, cid): - data = getDB('http://127.0.0.1:8000/classes/'+ str(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'])): print("Already enrolled in this class.") return None @@ -184,7 +184,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/teachers/" + data['teacher'] + "/")['git'] + 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 + "'" print(url) os.system(url) @@ -215,7 +215,7 @@ class Student: # if(data['confirmed'][0] == ','): # data['confirmed'] = data['confirmed'][1:] # print(data['confirmed']) - # print(putDB(data, 'http://127.0.0.1:8000/classes/'+ str(cid) + "/")) + # 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' @@ -236,7 +236,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/classes/" + str(cid))) + new.append(getDB("http://127.0.0.1:8000/api/classes/" + str(cid))) self.snew=snew self.new=new break @@ -298,9 +298,10 @@ class Student: 'grade':self.grade, 'completed':self.completed } - #print(putDB(data, "http://127.0.0.1:8000/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() os.chdir(self.username) for c in self.classes: @@ -311,6 +312,10 @@ class Student: os.chdir(cdir) print("Class not found") return + + def exitCLI(self): + self.update() + command("git checkout master") def submit(self, course, assignment): cdir = os.getcwd() @@ -342,5 +347,5 @@ class Student: data = getStudent("2022rkhondak") s = Student(data) -#s.viewClass("English11_eharris1") -s.submit("English11_eharris1", "Entry1") \ No newline at end of file +# s.viewClass("English11_eharris1") +s.exitCLI() diff --git a/CLI/t-git.py b/CLI/t-git.py index 1582129..a82da40 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -1,5 +1,5 @@ -import subprocess import os +import subprocess import requests import webbrowser import pprint @@ -14,7 +14,7 @@ from datetime import datetime #get teacher info from api def getTeacher(ion_user): - URL = "http://127.0.0.1:8000/teachers/" + 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() @@ -70,7 +70,7 @@ class Teacher: 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.url= "http://127.0.0.1:8000/api/teachers/" + self.username + "/" self.email = data['email'] #classes in id form (Example: 4,5) @@ -85,7 +85,7 @@ class Teacher: pass classes=[] for c in cid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" + url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" classes.append(getDB(url)) self.classes = classes @@ -95,6 +95,10 @@ class Teacher: else: os.makedirs(self.username + "/Students") + #2020-05-11 12:25:00 + + + #class name format: _ #turn existing directory into class, Pre-condition: directory exists @@ -162,7 +166,7 @@ class Teacher: "unconfirmed": "" } #make class instance in db - data = postDB(data, 'http://127.0.0.1:8000/classes/') + data = postDB(data, 'http://127.0.0.1:8000/api/classes/') #add to instance #upate self.classes self.classes.append(data) @@ -193,7 +197,7 @@ class Teacher: #check if class exists path = self.username + "/" + cname isclass = False - acourses = getDB("http://127.0.0.1:8000/classes/")['results'] + acourses = getDB("http://127.0.0.1:8000/api/classes/")['results'] for c in acourses: if c['name'] == cname: isclass=True @@ -255,7 +259,7 @@ class Teacher: 'email':self.email } print(putDB(data, self.url)) - delDB("http://127.0.0.1:8000/classes/" + cname + "/") + delDB("http://127.0.0.1:8000/api/classes/" + cname + "/") break #remove locally @@ -268,7 +272,7 @@ class Teacher: def isStudent(self, student): - r = requests.get(url = "http://127.0.0.1:8000/students/" + student + "/", auth=('raffukhondaker','hackgroup1')) + 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 @@ -277,7 +281,7 @@ class Teacher: if(self.isStudent(sname) == False): print(sname + " does not exist.") return - course = getDB("http://127.0.0.1:8000/classes/" + cname) + course = getDB("http://127.0.0.1:8000/api/classes/" + cname) if(sname in course['unconfirmed']): print (sname + " already requested.") return @@ -285,7 +289,7 @@ class Teacher: print (sname + " alredy enrolled.") return - student = getDB("http://127.0.0.1:8000/students/" + sname) + student = getDB("http://127.0.0.1:8000/api/students/" + sname) try: if(student['added_to']==""): student['added_to']=course['name'] @@ -333,8 +337,8 @@ class Teacher: print(sname + " does not exist.") return - student = getDB("http://127.0.0.1:8000/students/" + sname) - course = getDB("http://127.0.0.1:8000/classes/" + cname) + student = getDB("http://127.0.0.1:8000/api/students/" + sname) + course = getDB("http://127.0.0.1:8000/api/classes/" + cname) if((student['ion_user'] in course['unconfirmed']) == False): print("Student has not been requested to join yet.") @@ -383,6 +387,7 @@ class Teacher: } print(putDB(cinfo, course['url'])) + #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] @@ -398,15 +403,61 @@ class Teacher: if len(folder) == 0: print("Assignment is completely empty, need a file.") return + aname = parts[len(parts)-1] + p1 = course.split("_")[0] + if(p1 in aname == False): + print(aname + "incorrectly formated: must be " + aname + "_" + p1 + ".") + return + try: + datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + except: + print("Due-date format is incorrect") + return ass = { - 'name': parts[len(parts)-1], + 'name': aname, 'path':path, 'classes':course, 'teacher':self.username, 'due_date':due } - course = getDB("http://127.0.0.1:8000/classes/" + course) + postDB(ass, 'http://127.0.0.1:8000/api/assignments/' + aname + "/") + course = getDB("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: + if st in 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) + print(st) + print(copy_tree(path, spath + "/" + aname)) + os.chdir(spath) + command('git checkout ' + course['name']) + command('git pull origin ' + course['name']) + command('git add .') + command('git commit -m Hello') + command('git push -u origin ' + course['name']) + os.chdir(cdir) + else: + print(st + " already has assignment") + + #try to avoid + #copy modified assignments to student directories + def updateAssignment(self, path, course, due): + if(os.path.isdir(path) == False): + print(path + " is not an assignment.") + return + try: + if(due != None or due == ""): + datetime.strptime(due, '%Y-%m-%d %H:%M:%S.%f') + except: + print("Due-date format is incorrect") + return + input() + parts = path.split("/") + aname = parts[len(parts)-1] + course = getDB("http://127.0.0.1:8000/api/classes/" + course) slist = os.listdir(os.getcwd() + "/" + self.username + "/Students/" + course['name']) cdir = os.getcwd() for st in slist: @@ -426,8 +477,22 @@ class Teacher: else: print(st + " already has assignment") + #pull student's work, no modifications + def getStudents(self, course): + if((course in self.sclass) == False): + print(course + " not a class.") + return + path = self.username + "/Students/" + course + slist = os.listdir(path) + cdir = os.getcwd() + for st in slist: + os.chdir(path + "/" + st) + command('git checkout ' + course) + command('git pull origin ' + course) + os.chdir(cdir) + def getHistory(self, student, course): - course = getDB("http://127.0.0.1:8000/classes/" + course) + course = getDB("http://127.0.0.1:8000/api/classes/" + course) try: if((student in course['confirmed']) == False): print("Student not in class") @@ -502,10 +567,8 @@ class Teacher: def comment(self): print("heheheh") - - def updateAssignnment(): - print() + data = getTeacher("eharris1") t = Teacher(data) -t.addAssignment("English11_eharris1", "Entry1", '2022rkhondak',"2020-05-11 12:25:00") +t.getStudents("English11_eharris1") diff --git a/Website/api/migrations/0001_initial.py b/Website/api/migrations/0001_initial.py index 11b47e4..056367b 100644 --- a/Website/api/migrations/0001_initial.py +++ b/Website/api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2020-06-09 02:03 +# Generated by Django 3.0.7 on 2020-06-12 01:34 from django.db import migrations, models @@ -14,10 +14,9 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Assignment', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ('name', models.CharField(max_length=100, primary_key=True, serialize=False)), ('due_date', models.DateTimeField()), - ('files', models.CharField(max_length=100)), + ('files', models.CharField(blank=True, default='', max_length=100)), ('path', models.CharField(max_length=100)), ('classes', models.CharField(max_length=100)), ('teacher', models.CharField(max_length=100)), @@ -26,13 +25,14 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Classes', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), + ('name', models.CharField(max_length=100, primary_key=True, serialize=False)), ('repo', models.URLField(default='')), ('path', models.CharField(default='', max_length=100)), ('teacher', models.CharField(default='', max_length=100)), ('assignments', models.CharField(default='', max_length=100)), ('default_file', models.CharField(default='', max_length=100)), + ('confirmed', models.TextField(blank=True, default='')), + ('unconfirmed', models.TextField(blank=True, default='')), ], ), migrations.CreateModel( @@ -46,17 +46,6 @@ class Migration(migrations.Migration): ('teacher', models.CharField(max_length=100)), ], ), - migrations.CreateModel( - name='Teacher', - fields=[ - ('created', models.DateTimeField(auto_now_add=True)), - ('first_name', models.CharField(max_length=100)), - ('last_name', models.CharField(max_length=100)), - ('classes', models.CharField(default='', max_length=100)), - ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), - ('git', models.CharField(max_length=100)), - ], - ), migrations.CreateModel( name='Student', fields=[ @@ -65,11 +54,25 @@ class Migration(migrations.Migration): ('last_name', models.CharField(max_length=100)), ('student_id', models.IntegerField()), ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), - ('webmail', models.EmailField(blank=True, max_length=254)), + ('email', models.CharField(blank=True, default='', max_length=100)), ('grade', models.IntegerField()), ('git', models.CharField(max_length=100)), - ('repo', models.URLField(default='')), - ('classes', models.ManyToManyField(default='', to='api.Classes')), + ('repo', models.URLField(blank=True, default='')), + ('classes', models.CharField(blank=True, default='', max_length=100)), + ('added_to', models.CharField(blank=True, default='', max_length=100)), + ('completed', models.TextField(blank=True, default='')), + ], + ), + migrations.CreateModel( + name='Teacher', + fields=[ + ('created', models.DateTimeField(auto_now_add=True)), + ('first_name', models.CharField(max_length=100)), + ('last_name', models.CharField(max_length=100)), + ('classes', models.CharField(blank=True, default='', max_length=100)), + ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), + ('git', models.CharField(max_length=100)), + ('email', models.CharField(blank=True, default='', max_length=100)), ], ), ] diff --git a/Website/api/migrations/0002_auto_20200612_0010.py b/Website/api/migrations/0002_auto_20200612_0010.py deleted file mode 100644 index 0746e20..0000000 --- a/Website/api/migrations/0002_auto_20200612_0010.py +++ /dev/null @@ -1,89 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-12 00:10 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='assignment', - name='id', - ), - migrations.RemoveField( - model_name='classes', - name='id', - ), - migrations.RemoveField( - model_name='student', - name='webmail', - ), - migrations.AddField( - model_name='classes', - name='confirmed', - field=models.TextField(blank=True, default=''), - ), - migrations.AddField( - model_name='classes', - name='unconfirmed', - field=models.TextField(blank=True, default=''), - ), - migrations.AddField( - model_name='student', - name='added_to', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AddField( - model_name='student', - name='completed', - field=models.TextField(blank=True, default=''), - ), - migrations.AddField( - model_name='student', - name='email', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AddField( - model_name='teacher', - name='email', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AlterField( - model_name='assignment', - name='files', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AlterField( - model_name='assignment', - name='name', - field=models.CharField(max_length=100, primary_key=True, serialize=False), - ), - migrations.AlterField( - model_name='classes', - name='name', - field=models.CharField(max_length=100, primary_key=True, serialize=False), - ), - migrations.RemoveField( - model_name='student', - name='classes', - ), - migrations.AddField( - model_name='student', - name='classes', - field=models.CharField(blank=True, default='', max_length=100), - ), - migrations.AlterField( - model_name='student', - name='repo', - field=models.URLField(blank=True, default=''), - ), - migrations.AlterField( - model_name='teacher', - name='classes', - field=models.CharField(blank=True, default='', max_length=100), - ), - ] diff --git a/Website/api/migrations/0003_auto_20200612_0012.py b/Website/api/migrations/0002_auto_20200612_0135.py similarity index 53% rename from Website/api/migrations/0003_auto_20200612_0012.py rename to Website/api/migrations/0002_auto_20200612_0135.py index 465ea03..652eea2 100644 --- a/Website/api/migrations/0003_auto_20200612_0012.py +++ b/Website/api/migrations/0002_auto_20200612_0135.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2020-06-12 00:12 +# Generated by Django 3.0.7 on 2020-06-12 01:35 from django.db import migrations, models @@ -6,19 +6,18 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('api', '0002_auto_20200612_0010'), + ('api', '0001_initial'), ] operations = [ - migrations.AddField( - model_name='assignment', - name='id', - field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'), - preserve_default=False, - ), migrations.AlterField( model_name='assignment', name='name', field=models.CharField(max_length=100), ), + migrations.AlterField( + model_name='assignment', + name='path', + field=models.CharField(max_length=100, primary_key=True, serialize=False), + ), ] diff --git a/Website/api/migrations/0003_auto_20200612_0135.py b/Website/api/migrations/0003_auto_20200612_0135.py new file mode 100644 index 0000000..5b95bdd --- /dev/null +++ b/Website/api/migrations/0003_auto_20200612_0135.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-06-12 01:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_auto_20200612_0135'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='name', + field=models.CharField(max_length=100, primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='assignment', + name='path', + field=models.CharField(max_length=100), + ), + ]