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] 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), + ), + ]