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 1/4] 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 2/4] 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 3/4] 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 4/4] 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), + ), + ]