teacher cli

This commit is contained in:
Raffu Khondaker 2020-06-14 23:43:49 -04:00
parent 5fe9863677
commit b31f6146d2
2 changed files with 35 additions and 18 deletions

View File

@ -66,8 +66,6 @@ class Teacher:
def __init__(self, data): def __init__(self, data):
# teacher info already stored in API # teacher info already stored in API
# intitialze fields after GET request # intitialze fields after GET request
self.first_name=data['first_name']
self.last_name=data['last_name']
self.git=data['git'] self.git=data['git']
self.username=data['ion_user'] self.username=data['ion_user']
self.url= "http://127.0.0.1:8000/api/teachers/" + self.username + "/" self.url= "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
@ -177,13 +175,10 @@ class Teacher:
#update teacher instance in db, classes field #update teacher instance in db, classes field
teacher={ teacher={
'first_name':self.first_name,
'last_name':self.last_name,
'git':self.git, 'git':self.git,
'ion_user':self.username, 'ion_user':self.username,
'url':self.url, 'url':self.url,
'classes':self.sclass, 'classes':self.sclass,
'email':self.email
} }
putDB(teacher, self.url) putDB(teacher, self.url)
@ -250,13 +245,10 @@ class Teacher:
s = s[:-1] s = s[:-1]
print(s) print(s)
data={ data={
'first_name':self.first_name,
'last_name':self.last_name,
'git':self.git, 'git':self.git,
'ion_user':self.username, 'ion_user':self.username,
'url':self.url, 'url':self.url,
'classes':s, 'classes':s,
'email':self.email
} }
print(putDB(data, self.url)) print(putDB(data, self.url))
delDB("http://127.0.0.1:8000/api/classes/" + cname + "/") delDB("http://127.0.0.1:8000/api/classes/" + cname + "/")
@ -300,14 +292,10 @@ class Teacher:
return False return False
print(student['added_to']) print(student['added_to'])
s={ s={
'first_name':student["first_name"],
'last_name':student["last_name"],
'git':student["git"], 'git':student["git"],
'ion_user':student["ion_user"], 'ion_user':student["ion_user"],
'student_id':student["student_id"],
'added_to':student['added_to'], 'added_to':student['added_to'],
'classes':student["classes"], 'classes':student["classes"],
'email':student["email"],
'grade':student["grade"], 'grade':student["grade"],
'completed':student["completed"], 'completed':student["completed"],
'repo':student["repo"] 'repo':student["repo"]

View File

@ -55,7 +55,7 @@ def main():
if(data['is_student']): if(data['is_student']):
studentCLI(USER, PWD) studentCLI(USER, PWD)
else: else:
teacherCLI() teacherCLI(USER, PWD)
@ -63,7 +63,7 @@ def main():
# pass # pass
def studentCLI(user, password): def studentCLI(user, password):
from CLI import student from CLI import student
data = getStudent(user, password) data = getUser(user, password)
student = student.Student(data) student = student.Student(data)
choices = ['1) View Class','2) Exit SkoolOS'] choices = ['1) View Class','2) Exit SkoolOS']
questions = [ questions = [
@ -92,12 +92,41 @@ def studentCLI(user, password):
course = prompt(courses) course = prompt(courses)
if(choice == 2): if(choice == 2):
student.exitCLI() student.exitCLI()
def teacherCLI(): def teacherCLI(user, password):
from CLI.teacher import Teacher from CLI import teacher
print("fail") data = getUser(user, password)
teacher = teacher.Teacher(data)
choices = ['1) View Class','2) Exit SkoolOS']
questions = [
{
'type': 'list',
'name': 'choice',
'choices':choices,
'message': 'Select class: ',
},
]
choice = prompt(questions)
choice = int(choice['choice'].split(")")[0])
if(choice == 1):
carray = student.sclass.split(",")
if(len(carray) == 1 and carray[0] == ""):
print("No classes")
return
courses = [
{
'type': 'list',
'name': 'course',
'choices':carray,
'message': 'Select class: ',
},
]
course = prompt(courses)
if(choice == 2):
student.exitCLI()
def getStudent(ion_user, password): def getUser(ion_user, password):
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
r = requests.get(url = URL, auth=(ion_user,password)) r = requests.get(url = URL, auth=(ion_user,password))
if(r.status_code == 200): if(r.status_code == 200):