diff --git a/CLI/student.py b/CLI/student.py index b44d3a6..f587230 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -14,22 +14,28 @@ import datetime # get teacher info from api def getStudent(ion_user, password): + """ + Get's student information from the api + :param ion_user: a student + :return: student information or error + """ URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" r = requests.get(url=URL, auth=(ion_user, password)) if (r.status_code == 200): data = r.json() return data - elif (r.status_code == 404): + elif r.status_code == 404: return None print("Make new account!") - elif (r.status_code == 403): + elif r.status_code == 403: return None print("Invalid username/password") else: return None print(r.status_code) -#makes a GET request to given url, returns dict + +# makes a GET request to given url, returns dict def getDB(user, pwd, url): """ Sends a GET request to the URL @@ -37,9 +43,10 @@ def getDB(user, pwd, url): """ r = requests.get(url=url, auth=(user, pwd)) print("GET:" + str(r.status_code)) - return(r.json()) + return r.json() -#makes a PATCH (updates instance) request to given url, returns dict + +# makes a PATCH (updates instance) request to given url, returns dict def patchDB(user, pwd, data, url): """ Sends a PATCH request to the URL @@ -51,7 +58,7 @@ def patchDB(user, pwd, data, url): return r.json() -#makes a POST (makes new instance) request to given url, returns dict +# makes a POST (makes new instance) request to given url, returns dict def postDB(user, pwd, data, url): """ Sends a POST request to the URL @@ -63,7 +70,7 @@ def postDB(user, pwd, data, url): return r.json() -#makes a PUT (overwrites instance) request to given url, returns dict +# makes a PUT (overwrites instance) request to given url, returns dict def putDB(user, pwd, data, url): """ Sends a PUT request to the URL @@ -75,7 +82,7 @@ def putDB(user, pwd, data, url): return r.json() -#makes a DELETE (delete instance) request to given url, returns dict +# makes a DELETE (delete instance) request to given url, returns dict def delDB(user, pwd, url): """ Sends a DELETE request to the URL @@ -87,6 +94,10 @@ def delDB(user, pwd, url): def command(command): + """ + Runs a shell command + :param command: shell command + """ ar = [] command = command.split(" ") for c in command: @@ -105,6 +116,10 @@ class Student: def __init__(self, data, password): # teacher info already stored in API # intitialze fields after GET request + """ + Initializes a Student with data from the api + :param data: api data + """ self.git = data['git'] self.username = data['ion_user'] self.url = "http://127.0.0.1:8000/api/students/" + self.username + "/" @@ -151,8 +166,8 @@ class Student: self.snew = str(data['added_to']) self.repo = data['repo'] - if (os.path.isdir(self.username) == False): - if (self.repo == ""): + if os.path.isdir(self.username) == False: + if self.repo == "": user = self.git pwd = input("Enter Github password: ") # curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos @@ -176,11 +191,18 @@ class Student: print("Synced to " + self.username) def getClasses(self): + """ + Gets a lists of classes the student is enrolled in + """ classes = self.classes for c in classes: print(c['name']) - def getAssignments(self, course, span): + def getAssignments(self, span): + """ + Gets a list of assignments the student has + :param span: time span to check + """ span = datetime.timedelta(span, 0) classes = self.classes for c in classes: @@ -195,7 +217,7 @@ class Student: diff = now - due zero = datetime.timedelta(0, 0) # check due ddate is in span range is now past date (- timdelta) - if (diff < span and diff > zero): + if diff < span and diff > zero: print(a + " due in:" + str(now - due)) except Exception as e: @@ -204,6 +226,9 @@ class Student: # update API and Github, all assignments / classes def update(self): + """ + Updates the api, github, and all assignments and classes with new information + """ cdir = os.getcwd() os.chdir(self.username) command("git checkout master") @@ -226,7 +251,11 @@ class Student: # updates 1 class, does not switch to master def updateClass(self, course): - if ((course in self.sclass) == False): + """ + Updates a class with new information + :param course: class name in the format _ + """ + if (course in self.sclass) == False: print("Class not found") return cdir = os.getcwd() @@ -241,16 +270,20 @@ class Student: # add classes from 'new' field def addClass(self, cid): - + """ + Add student to a class + :param cid: the id number of the class + :return: data from the class, None if an error occures + """ data = getDB(self.username, self.password,'http://127.0.0.1:8000/api/classes/' + str(cid)) if ((cid in self.snew) == False or (self.username in data['confirmed'])): print("Already enrolled in this class.") return None - if ((cid in self.sclass) or (self.username in data['unconfirmed']) == False): + if (cid in self.sclass) or not (self.username in data['unconfirmed']): print("Not added by teacher yet.") return None - # add class teacher as cocllaborator to student repo + # add class teacher as collaborator to student repo print(os.getcwd()) pwd = input("Enter Github password: ") tgit = getDB(self.username, self.password,"http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git'] @@ -270,7 +303,7 @@ class Student: # os.chdir(self.username) # push to git, start at master - #os.chdir(self.username) + # os.chdir(self.username) command("git checkout master") command("git branch " + data['name']) command("git commit -m initial") @@ -292,7 +325,7 @@ class Student: user = self.git self.classes.append(data) - if (len(self.sclass) == 0): + if len(self.sclass) == 0: self.sclass = data['name'] else: self.sclass = self.sclass + "," + str(data['name']) @@ -301,7 +334,7 @@ class Student: snew = "" new = [] for i in range(len(self.new)): - if (self.new[i]['name'] == data['name']): + if self.new[i]['name'] == data['name']: del self.new[i] # recreate sclass field, using ids for c in self.new: @@ -321,46 +354,12 @@ class Student: print(patchDB(self.username, self.password,data, self.url)) return data - def submit(self, path): - # 2022rkhondak/English11_eharris1/Essay1 - # check if valid assignment - parts = path.split("/") - if (len(parts) != 3): - print("Assignment path too short") - return - isclass = False - for c in self.classes: - if (c['name'] == parts[1]): - isclass == True - break - if (parts[0] != self.username and isclass and os.path.isdir(path) == False): - print("Not valid assignment") - return - if ((parts[1] + "/" + parts[2]) in self.completed): - print(parts[2] + " already submited. ") - # return - resp = input("Are you sure you want to submit? You cannot do this again.(y/N) ") - if (resp == 'y'): - os.chdir(self.username + "/" + parts[1]) - command("git add .") - command("git commit -m submit") - command("git tag " + parts[1] + "-final") - command("git push -u origin " + self.username + " --tags") - self.completed = self.completed + "," + parts[1] + "/" + parts[2] - data = { - 'user': self.user, - 'git': self.git, - 'ion_user': self.username, - 'student_id': self.student_id, - 'added_to': self.snew, - 'url': self.url, - 'classes': self.sclass, - 'grade': self.grade, - 'completed': self.completed - } - # print(putDB(data, "http://127.0.0.1:8000/api/students/" + self.username + "/")) - def viewClass(self, courses): + """ + Sets the current git branch to view each class in courses + :param courses: a list of classes + :return: + """ self.update() cdir = os.getcwd() os.chdir(self.username) @@ -375,11 +374,20 @@ class Student: return def exitCLI(self): + """ + Exits the cli + """ print(os.getcwd()) self.update() command("git checkout master") def submit(self, course, assignment): + """ + Submits an assignment + :param course: the class the assignment belongs to + :param assignment: the assignment + :return: + """ cdir = os.getcwd() os.chdir(self.username) print(os.getcwd()) @@ -394,7 +402,7 @@ class Student: inclass = True oname = a + "_" + course break - if (inclass == False): + if inclass == False: print(assignment + " not an assignment of " + course) command('git checkout master') os.chdir(cdir) diff --git a/CLI/teacher.py b/CLI/teacher.py index 88c0608..cde7e7f 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -96,7 +96,7 @@ def putDB(user, pwd, data, url): :param user: a string :param password: a string :param url: URL for request - """ + """ r = requests.put(url=url, data=data, auth=(user, pwd)) print("PUT:" + str(r.status_code)) return r.json() diff --git a/Website/skoolos/forms.py b/Website/skoolos/forms.py index 2f498c0..f314f54 100644 --- a/Website/skoolos/forms.py +++ b/Website/skoolos/forms.py @@ -53,20 +53,6 @@ class ClassCreationForm (forms.ModelForm): # a list of primary key for the selected data. initial['unconfirmed'] = [t.pk for t in kwargs['instance'].unconfirmed.all()] - # Overriding save allows us to process the value of 'unconfirmed' field - def save(self, username=""): - cleaned_data = self.cleaned_data - print(self) - - # Get the unsave Class instance - instance = forms.ModelForm.save(self) - instance.unconfirmed.clear() - instance.unconfirmed.add(*cleaned_data['unconfirmed']) - instance.name = cleaned_data['subject'] + str(cleaned_data['period']) + "_" + username - print("Class name: " + instance.name) - - return instance - class Meta: model = Class fields = ['subject', 'period', 'description', 'unconfirmed'] diff --git a/Website/skoolos/static/skoolos/styles.css b/Website/skoolos/static/skoolos/styles.css index 0f86d92..db1e636 100644 --- a/Website/skoolos/static/skoolos/styles.css +++ b/Website/skoolos/static/skoolos/styles.css @@ -92,3 +92,13 @@ a.article-title:hover { .account-heading { font-size: 2.5rem; } + +.class-card { + text-decoration: none; + color: gray; +} + +.class-card:hover { + text-decoration: none; + color: black; +} diff --git a/Website/skoolos/templates/skoolos/base.html b/Website/skoolos/templates/skoolos/base.html index fa2f42c..65c0801 100644 --- a/Website/skoolos/templates/skoolos/base.html +++ b/Website/skoolos/templates/skoolos/base.html @@ -35,7 +35,6 @@