mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
config api
This commit is contained in:
parent
c50c305b86
commit
e151acabfb
457
CLI/t-git-old.py
Normal file
457
CLI/t-git-old.py
Normal file
|
@ -0,0 +1,457 @@
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import webbrowser
|
||||||
|
import pprint
|
||||||
|
import json
|
||||||
|
|
||||||
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
|
'''
|
||||||
|
{
|
||||||
|
"url": "http://127.0.0.1:8000/teachers/eharris1/",
|
||||||
|
"first_name": "Errin",
|
||||||
|
"last_name": "Harris",
|
||||||
|
"classes": [
|
||||||
|
{
|
||||||
|
"url": "http://127.0.0.1:8000/classes/1/",
|
||||||
|
"name": "Math5",
|
||||||
|
"assignments": [
|
||||||
|
{
|
||||||
|
"name": "Week1_HW",
|
||||||
|
"due_date": "2020-06-07T07:46:30.537197Z",
|
||||||
|
"url": "http://127.0.0.1:8000/assignments/1/",
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"name": "instructions.txt"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Week2_HW",
|
||||||
|
"due_date": "2020-06-07T07:46:30.548596Z",
|
||||||
|
"url": "http://127.0.0.1:8000/assignments/2/",
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"name": "instructions.txt"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repo": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"git": "therealraffi",
|
||||||
|
"ion_user": "eharris1"
|
||||||
|
},
|
||||||
|
'''
|
||||||
|
#get teacher info from api
|
||||||
|
def getTeacher(ion_user):
|
||||||
|
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
||||||
|
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
if(r.status_code == 200):
|
||||||
|
data = r.json()
|
||||||
|
return data
|
||||||
|
elif(r.status_code == 404):
|
||||||
|
return None
|
||||||
|
print("Make new account!")
|
||||||
|
elif(r.status_code == 403):
|
||||||
|
return None
|
||||||
|
print("Invalid username/password")
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
print(r.status_code)
|
||||||
|
|
||||||
|
def getDB(url):
|
||||||
|
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
class Teacher:
|
||||||
|
def __init__(self, data):
|
||||||
|
# teacher info already stored in API
|
||||||
|
# intitialze fields after GET request
|
||||||
|
self.first_name=data['first_name']
|
||||||
|
self.last_name=data['last_name']
|
||||||
|
self.git=data['git']
|
||||||
|
self.username=data['ion_user']
|
||||||
|
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
||||||
|
|
||||||
|
classes=data['classes'].split(",")
|
||||||
|
cdict = []
|
||||||
|
for cid in classes:
|
||||||
|
adict=[]
|
||||||
|
c = getDB("http://127.0.0.1:8000/classes/" + cid + "/")
|
||||||
|
name=c['name']
|
||||||
|
repo=c['repo']
|
||||||
|
path=c['path']
|
||||||
|
teacher=c['teacher']
|
||||||
|
id=c['id']
|
||||||
|
assignments=c['assignments'].split(",")
|
||||||
|
dfs = c['default_file'].split(' ')
|
||||||
|
dfdict=[]
|
||||||
|
for fid in dfs:
|
||||||
|
f = getDB("http://127.0.0.1:8000/files/" + fid + "/")
|
||||||
|
fname=f['name']
|
||||||
|
fpath=f['path']
|
||||||
|
dfdict.append({
|
||||||
|
'name':fname,
|
||||||
|
'path':fpath,
|
||||||
|
'classes':classes,
|
||||||
|
'assignment':"none",
|
||||||
|
'id':fid,
|
||||||
|
})
|
||||||
|
for aid in assignments:
|
||||||
|
fdict=[]
|
||||||
|
a = getDB("http://127.0.0.1:8000/assignments/" + aid + "/")
|
||||||
|
aname= a['name']
|
||||||
|
due_date = a['due_date']
|
||||||
|
apath=a['path']
|
||||||
|
classes=a['classes']
|
||||||
|
files = a['files'].split(' ')
|
||||||
|
for fid in files:
|
||||||
|
f = getDB("http://127.0.0.1:8000/files/" + fid + "/")
|
||||||
|
fname=f['name']
|
||||||
|
fpath=f['path']
|
||||||
|
fdict.append({
|
||||||
|
'name':fname,
|
||||||
|
'path':fpath,
|
||||||
|
'classes':classes,
|
||||||
|
'assignment':aname,
|
||||||
|
'id':fid,
|
||||||
|
})
|
||||||
|
adict.append({
|
||||||
|
'name':aname,
|
||||||
|
'due_date':due_date,
|
||||||
|
'path':apath,
|
||||||
|
'classes':classes,
|
||||||
|
'teacher':teacher,
|
||||||
|
'files':fdict,
|
||||||
|
})
|
||||||
|
cdict.append({
|
||||||
|
'name':name,
|
||||||
|
'path':path,
|
||||||
|
'teacher':teacher,
|
||||||
|
'assignments':adict,
|
||||||
|
'default_file':adict,
|
||||||
|
})
|
||||||
|
|
||||||
|
self.classes = cdict
|
||||||
|
|
||||||
|
def command(self,command):
|
||||||
|
ar = []
|
||||||
|
command = command.split(" ")
|
||||||
|
for c in command:
|
||||||
|
ar.append(c)
|
||||||
|
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
|
p=process.poll()
|
||||||
|
output = process.communicate()[0]
|
||||||
|
#print(output.decode('utf-8'))
|
||||||
|
|
||||||
|
def initTeacher(self):
|
||||||
|
if(os.path.exists(self.username )):
|
||||||
|
print("Already synced to: " + str(self.username))
|
||||||
|
return
|
||||||
|
os.mkdir(self.username)
|
||||||
|
classes = self.classes
|
||||||
|
# make classes directory
|
||||||
|
for c in classes:
|
||||||
|
cname= c['name']
|
||||||
|
cpath = self.username + "/" + cname
|
||||||
|
|
||||||
|
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
||||||
|
webbrowser.open('https://github.com/new')
|
||||||
|
input("Repo created? (Press any key to continue)\n")
|
||||||
|
|
||||||
|
url='https://github.com/' + self.git + "/" + cname
|
||||||
|
print(url)
|
||||||
|
while(requests.get(url).status_code != 200):
|
||||||
|
print(requests.get(url))
|
||||||
|
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
||||||
|
if(r=="N" or r=="No"):
|
||||||
|
return
|
||||||
|
cdir = os.getcwd()
|
||||||
|
os.chdir(self.username)
|
||||||
|
self.command('git clone ' + url)
|
||||||
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
#make class directory
|
||||||
|
#make default files for each class
|
||||||
|
for filename in c['default_file']:
|
||||||
|
f=open(cpath+"/"+filename['name'], "w")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
#make assignments directory
|
||||||
|
for a in c['assignments']:
|
||||||
|
path = cpath + "/" + a['name']
|
||||||
|
if(os.path.exists(path)):
|
||||||
|
print(path + " already exists...")
|
||||||
|
else:
|
||||||
|
os.mkdir(path)
|
||||||
|
f=open(path + "/instructions.txt", "w")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
#push to remote repo
|
||||||
|
os.chdir(cpath)
|
||||||
|
print(cpath)
|
||||||
|
self.command('git add .')
|
||||||
|
self.command('git commit -m Hello_Class')
|
||||||
|
self.command('git push -u origin master')
|
||||||
|
|
||||||
|
def checkGit(self, ass):
|
||||||
|
for a in ass:
|
||||||
|
if a =='.git':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def compareDB(self, fdict, url):
|
||||||
|
URL = url
|
||||||
|
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
data = r.json()['results']
|
||||||
|
allfiles = data
|
||||||
|
# far = []
|
||||||
|
# for f in allfiles:
|
||||||
|
# far.append(f['path'])
|
||||||
|
|
||||||
|
for f in fdict:
|
||||||
|
URL = url
|
||||||
|
in_db = False
|
||||||
|
pid=None
|
||||||
|
for dbf in allfiles:
|
||||||
|
if(dbf['path'] == f['path']):
|
||||||
|
in_db=True
|
||||||
|
break
|
||||||
|
if(in_db==False):
|
||||||
|
r = requests.post(url = URL, data=f , auth=('raffukhondaker','hackgroup1'))
|
||||||
|
print("POST: (" + URL + "): " + f['path'])
|
||||||
|
f['url']=r.json()['url']
|
||||||
|
print(r.status_code)
|
||||||
|
else:
|
||||||
|
URL = URL + str(dbf['id']) + "/"
|
||||||
|
r = requests.put(url = URL, data=f , auth=('raffukhondaker','hackgroup1'))
|
||||||
|
print(r.status_code)
|
||||||
|
print("UPDATED: (" + URL + "): " + f['path'])
|
||||||
|
f['url']=r.json()['url']
|
||||||
|
f['id']=dbf['id']
|
||||||
|
print(f)
|
||||||
|
|
||||||
|
return fdict
|
||||||
|
|
||||||
|
#update API and Github, all assignments / classes
|
||||||
|
def update(self):
|
||||||
|
#lists all classes
|
||||||
|
classes = os.listdir(self.username)
|
||||||
|
|
||||||
|
#checks all class directories first
|
||||||
|
for c in classes:
|
||||||
|
path = self.username + "/" + c
|
||||||
|
if(self.checkClass(path) == False):
|
||||||
|
return
|
||||||
|
cdict = []
|
||||||
|
for c in classes:
|
||||||
|
path = self.username + "/" + c
|
||||||
|
#lists all assignments and default files
|
||||||
|
ass = os.listdir(path)
|
||||||
|
#if no .git, directory not synced to git or API
|
||||||
|
if (self.checkGit(ass)==False):
|
||||||
|
self.addClass(path)
|
||||||
|
else:
|
||||||
|
#push to git
|
||||||
|
loc = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
self.command('git add .')
|
||||||
|
self.command('git commit -m "Update"')
|
||||||
|
self.command('git push -u origin master')
|
||||||
|
os.chdir(loc)
|
||||||
|
ass.remove('.git')
|
||||||
|
|
||||||
|
loc = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
repo = self.command('git config --get remote.origin.url')
|
||||||
|
os.chdir(loc)
|
||||||
|
|
||||||
|
#assignments
|
||||||
|
adict = []
|
||||||
|
#default files for classes
|
||||||
|
fdict=[]
|
||||||
|
#default files for assignments
|
||||||
|
afdict=[]
|
||||||
|
for a in ass:
|
||||||
|
aname=a
|
||||||
|
path = self.username + "/" + c + "/" + a
|
||||||
|
#need to add option
|
||||||
|
due_date= '2020-06-07T07:46:30.537197Z',
|
||||||
|
#check for default file
|
||||||
|
if(os.path.isfile(path)):
|
||||||
|
fdict.append({
|
||||||
|
'name':a,
|
||||||
|
'path':path
|
||||||
|
})
|
||||||
|
elif(os.path.isdir(path)):
|
||||||
|
for af in os.listdir(path):
|
||||||
|
path = path+ "/" + af
|
||||||
|
if(os.path.isfile(path)):
|
||||||
|
afdict.append({
|
||||||
|
'name':af,
|
||||||
|
'path':path
|
||||||
|
})
|
||||||
|
path = self.username + "/" + c + "/" + a
|
||||||
|
adict.append({
|
||||||
|
'name':aname,
|
||||||
|
'due_date': due_date[0],
|
||||||
|
'path':path,
|
||||||
|
'files':afdict
|
||||||
|
})
|
||||||
|
|
||||||
|
fdict=self.compareDB(fdict, "http://127.0.0.1:8000/files/")
|
||||||
|
afdict=self.compareDB(afdict,"http://127.0.0.1:8000/files/")
|
||||||
|
|
||||||
|
adict=self.compareDB(adict, 'http://127.0.0.1:8000/assignments/')
|
||||||
|
|
||||||
|
path = self.username + "/" + c
|
||||||
|
cdict.append({
|
||||||
|
'name':c,
|
||||||
|
'repo': repo,
|
||||||
|
'path':path,
|
||||||
|
'assignments':adict,
|
||||||
|
'default_file':fdict,
|
||||||
|
})
|
||||||
|
cdict=self.compareDB(cdict,'http://127.0.0.1:8000/classes/')
|
||||||
|
|
||||||
|
mdict= {
|
||||||
|
'first_name':self.first_name,
|
||||||
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'classes':cdict,
|
||||||
|
}
|
||||||
|
|
||||||
|
data = json.dumps(mdict)
|
||||||
|
# r = requests.put(url = 'http://127.0.0.1:8000/teachers/eharris1/', data=data, headers={'Content-type': 'application/json'} , auth=('raffukhondaker','hackgroup1'))
|
||||||
|
# print(print(r.json()))
|
||||||
|
|
||||||
|
|
||||||
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
|
#turn existing directory into class, Pre-condition: directory exists
|
||||||
|
#relative path to class: 2022rkhondak/Math4
|
||||||
|
def checkClass(self,path):
|
||||||
|
cname = path.split("/")
|
||||||
|
cname = cname[len(cname)-1]
|
||||||
|
if(("_" + self.username) in cname) == False:
|
||||||
|
print("Incorrect class name: Must be in the format: <course-name>_<ion_user>")
|
||||||
|
return False
|
||||||
|
dirs = os.listdir(path)
|
||||||
|
#checks if there is a file (not within Assignments) in class, need at least 1
|
||||||
|
deffile = False
|
||||||
|
#checks if there is a file in an Assignment, need at least 1 (default True in case no assignments)
|
||||||
|
as_file = True
|
||||||
|
as_bad = ""
|
||||||
|
|
||||||
|
for d in dirs:
|
||||||
|
if(os.path.isfile(d)):
|
||||||
|
deffile=True
|
||||||
|
if(os.path.isdir(d)) and d != '.git':
|
||||||
|
#checks if there is a file in an Assignment, need at least 1
|
||||||
|
as_file = False
|
||||||
|
asdir = os.listdir(d)
|
||||||
|
for a in asdir:
|
||||||
|
if(os.path.isfile(a)):
|
||||||
|
as_file=True
|
||||||
|
if(as_file==False):
|
||||||
|
as_bad = a
|
||||||
|
break
|
||||||
|
if(as_file==False):
|
||||||
|
print("Assignment '" + as_bad + "' does not have a default file!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if(deffile):
|
||||||
|
print("Need a default file in the " + path + " Directory!")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
#adds class to git, not API
|
||||||
|
def addClasstoGit(self, path):
|
||||||
|
cname = path.split("/")
|
||||||
|
cname = cname[len(cname)-1]
|
||||||
|
#push to remote repo
|
||||||
|
if(self.checkClass(path)):
|
||||||
|
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
||||||
|
webbrowser.open('https://github.com/new')
|
||||||
|
input("Repo created? (Press any key to continue)\n")
|
||||||
|
|
||||||
|
url='https://github.com/' + self.git + "/" + cname
|
||||||
|
print(url)
|
||||||
|
while(requests.get(url).status_code != 200):
|
||||||
|
print(requests.get(url))
|
||||||
|
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
||||||
|
if(r=="N" or r=="No"):
|
||||||
|
return None
|
||||||
|
cdir = os.getcwd()
|
||||||
|
os.chdir(path)
|
||||||
|
self.command('git init')
|
||||||
|
self.command('git add .')
|
||||||
|
self.command('git commit -m Hello_Class')
|
||||||
|
self.command('git remote add origin ' + url + '.git')
|
||||||
|
self.command('git push -u origin master')
|
||||||
|
os.chdir(cdir)
|
||||||
|
|
||||||
|
|
||||||
|
#make a new class from scratch
|
||||||
|
def makeClass(self, subject):
|
||||||
|
cname = subject + "_" + self.username
|
||||||
|
os.chdir(self.username)
|
||||||
|
#check if class exists
|
||||||
|
if(os.path.exists(cname)):
|
||||||
|
print("Already synced to: " + str(self.username))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
os.mkdir(cname)
|
||||||
|
f=open(cname + "/README.md", "w")
|
||||||
|
f.close()
|
||||||
|
#push to remote repo
|
||||||
|
os.chdir(cname)
|
||||||
|
command(self, 'git init')
|
||||||
|
command(self, 'git add .')
|
||||||
|
command(self, 'git commit -m "Hello Class!"')
|
||||||
|
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
||||||
|
command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git")
|
||||||
|
command(self, 'git push -u origin master')
|
||||||
|
|
||||||
|
cinfo=[
|
||||||
|
{
|
||||||
|
"name":cname,
|
||||||
|
"assignments":[],
|
||||||
|
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
||||||
|
"default_file": [
|
||||||
|
{
|
||||||
|
"name":"README.md"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
#update rest API
|
||||||
|
self.classes.append(cinfo)
|
||||||
|
update(self)
|
||||||
|
data = {
|
||||||
|
"url": self.url,
|
||||||
|
"first_name": self.first_name,
|
||||||
|
"last_name": self.first_name,
|
||||||
|
"classes": self.classes,
|
||||||
|
"git": self.git,
|
||||||
|
"ion_user": self.username
|
||||||
|
},
|
||||||
|
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
||||||
|
|
||||||
|
#make student repo by student id
|
||||||
|
def addStudent(self,stid):
|
||||||
|
print(stid)
|
||||||
|
|
||||||
|
def comment(self):
|
||||||
|
print("heheheh")
|
||||||
|
|
||||||
|
# data = getData("eharris1")
|
||||||
|
data={'url': 'http://127.0.0.1:8000/teachers/eharris1/', 'first_name': 'Errin', 'last_name': 'Harris', 'git': 'therealraffi', 'ion_user': 'eharris1', 'classes': [{'url': 'http://127.0.0.1:8000/classes/1/', 'name': 'Math5_eharris1', 'repo': 'http://127.0.0.1:8000/assignments/3/', 'assignments': [{'name': 'Week1_HW', 'due_date': '2020-06-07T07:46:30.537197Z', 'url': 'http://127.0.0.1:8000/assignments/1/', 'files': [{'name': 'instructions.txt'}]}, {'name': 'Week2_HW', 'due_date': '2020-06-07T07:46:30.548596Z', 'url': 'http://127.0.0.1:8000/assignments/2/', 'files': [{'name': 'instructions.txt'}]}], 'default_file': [{'name': 'instructions.txt'}]}]}
|
||||||
|
t = Teacher(data)
|
||||||
|
t.update()
|
||||||
|
|
||||||
|
|
336
CLI/t-git.py
336
CLI/t-git.py
|
@ -6,44 +6,7 @@ import pprint
|
||||||
import json
|
import json
|
||||||
|
|
||||||
#git clone student directory ==> <student-id>/classes/assignments
|
#git clone student directory ==> <student-id>/classes/assignments
|
||||||
'''
|
|
||||||
{
|
|
||||||
"url": "http://127.0.0.1:8000/teachers/eharris1/",
|
|
||||||
"first_name": "Errin",
|
|
||||||
"last_name": "Harris",
|
|
||||||
"classes": [
|
|
||||||
{
|
|
||||||
"url": "http://127.0.0.1:8000/classes/1/",
|
|
||||||
"name": "Math5",
|
|
||||||
"assignments": [
|
|
||||||
{
|
|
||||||
"name": "Week1_HW",
|
|
||||||
"due_date": "2020-06-07T07:46:30.537197Z",
|
|
||||||
"url": "http://127.0.0.1:8000/assignments/1/",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"name": "instructions.txt"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Week2_HW",
|
|
||||||
"due_date": "2020-06-07T07:46:30.548596Z",
|
|
||||||
"url": "http://127.0.0.1:8000/assignments/2/",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"name": "instructions.txt"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"repo": ""
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"git": "therealraffi",
|
|
||||||
"ion_user": "eharris1"
|
|
||||||
},
|
|
||||||
'''
|
|
||||||
#get teacher info from api
|
#get teacher info from api
|
||||||
def getTeacher(ion_user):
|
def getTeacher(ion_user):
|
||||||
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
URL = "http://127.0.0.1:8000/teachers/" + ion_user + "/"
|
||||||
|
@ -59,7 +22,28 @@ def getTeacher(ion_user):
|
||||||
print("Invalid username/password")
|
print("Invalid username/password")
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
print(r.status_code)
|
print(r.status_code)
|
||||||
|
|
||||||
|
def getDB(url):
|
||||||
|
r = requests.get(url = url, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def postDB(data, url):
|
||||||
|
r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
return(r.status_code)
|
||||||
|
def putDB(data, url):
|
||||||
|
r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
|
||||||
|
return(r.status_code)
|
||||||
|
|
||||||
|
def command(command):
|
||||||
|
ar = []
|
||||||
|
command = command.split(" ")
|
||||||
|
for c in command:
|
||||||
|
ar.append(c)
|
||||||
|
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
||||||
|
p=process.poll()
|
||||||
|
output = process.communicate()[0]
|
||||||
|
#print(output.decode('utf-8'))
|
||||||
|
|
||||||
class Teacher:
|
class Teacher:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
|
@ -67,71 +51,15 @@ class Teacher:
|
||||||
# intitialze fields after GET request
|
# intitialze fields after GET request
|
||||||
self.first_name=data['first_name']
|
self.first_name=data['first_name']
|
||||||
self.last_name=data['last_name']
|
self.last_name=data['last_name']
|
||||||
self.classes=data['classes']
|
|
||||||
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/teachers/" + self.username + "/"
|
self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/"
|
||||||
self.data=data
|
self.classes=data['classes'].split(" ")
|
||||||
|
self.sclass=data['classes']
|
||||||
def command(self,command):
|
if(os.path.isdir(self.username)):
|
||||||
ar = []
|
print("Already synced to " + self.username)
|
||||||
command = command.split(" ")
|
else:
|
||||||
for c in command:
|
os.mkdir(self.username)
|
||||||
ar.append(c)
|
|
||||||
process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
||||||
p=process.poll()
|
|
||||||
output = process.communicate()[0]
|
|
||||||
#print(output.decode('utf-8'))
|
|
||||||
|
|
||||||
def initTeacher(self):
|
|
||||||
if(os.path.exists(self.username )):
|
|
||||||
print("Already synced to: " + str(self.username))
|
|
||||||
return
|
|
||||||
os.mkdir(self.username)
|
|
||||||
classes = self.classes
|
|
||||||
# make classes directory
|
|
||||||
for c in classes:
|
|
||||||
cname= c['name']
|
|
||||||
cpath = self.username + "/" + cname
|
|
||||||
|
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
|
||||||
webbrowser.open('https://github.com/new')
|
|
||||||
input("Repo created? (Press any key to continue)\n")
|
|
||||||
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
|
||||||
print(url)
|
|
||||||
while(requests.get(url).status_code != 200):
|
|
||||||
print(requests.get(url))
|
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
|
||||||
if(r=="N" or r=="No"):
|
|
||||||
return
|
|
||||||
cdir = os.getcwd()
|
|
||||||
os.chdir(self.username)
|
|
||||||
self.command('git clone ' + url)
|
|
||||||
os.chdir(cdir)
|
|
||||||
|
|
||||||
#make class directory
|
|
||||||
#make default files for each class
|
|
||||||
for filename in c['default_file']:
|
|
||||||
f=open(cpath+"/"+filename['name'], "w")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
#make assignments directory
|
|
||||||
for a in c['assignments']:
|
|
||||||
path = cpath + "/" + a['name']
|
|
||||||
if(os.path.exists(path)):
|
|
||||||
print(path + " already exists...")
|
|
||||||
else:
|
|
||||||
os.mkdir(path)
|
|
||||||
f=open(path + "/instructions.txt", "w")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
#push to remote repo
|
|
||||||
os.chdir(cpath)
|
|
||||||
print(cpath)
|
|
||||||
self.command('git add .')
|
|
||||||
self.command('git commit -m Hello_Class')
|
|
||||||
self.command('git push -u origin master')
|
|
||||||
|
|
||||||
def checkGit(self, ass):
|
def checkGit(self, ass):
|
||||||
for a in ass:
|
for a in ass:
|
||||||
|
@ -139,26 +67,6 @@ class Teacher:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def compareDB(self, fdict, url):
|
|
||||||
URL = url
|
|
||||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
|
||||||
data = r.json()['results']
|
|
||||||
allfiles = data
|
|
||||||
far = []
|
|
||||||
for f in allfiles:
|
|
||||||
far.append(f['path'])
|
|
||||||
|
|
||||||
for f in fdict:
|
|
||||||
in_db = False
|
|
||||||
for dbf in far:
|
|
||||||
if(dbf == f['path']):
|
|
||||||
in_db=True
|
|
||||||
break
|
|
||||||
if(in_db==False):
|
|
||||||
r = requests.post(url = URL, data=f , auth=('raffukhondaker','hackgroup1'))
|
|
||||||
print("POST: (" + url + "): " + f['path'])
|
|
||||||
print(r.status_code)
|
|
||||||
|
|
||||||
#update API and Github, all assignments / classes
|
#update API and Github, all assignments / classes
|
||||||
def update(self):
|
def update(self):
|
||||||
#lists all classes
|
#lists all classes
|
||||||
|
@ -176,83 +84,16 @@ class Teacher:
|
||||||
ass = os.listdir(path)
|
ass = os.listdir(path)
|
||||||
#if no .git, directory not synced to git or API
|
#if no .git, directory not synced to git or API
|
||||||
if (self.checkGit(ass)==False):
|
if (self.checkGit(ass)==False):
|
||||||
self.addClass(path)
|
data = self.addClasstoGit(path)
|
||||||
|
postDB(data, 'http://127.0.0.1:8000/classes/')
|
||||||
else:
|
else:
|
||||||
#push to git
|
#push to git
|
||||||
loc = os.getcwd()
|
loc = os.getcwd()
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
self.command('git add .')
|
command('git add .')
|
||||||
self.command('git commit -m "Update"')
|
command('git commit -m "Update"')
|
||||||
self.command('git push -u origin master')
|
command('git push -u origin master')
|
||||||
os.chdir(loc)
|
os.chdir(loc)
|
||||||
ass.remove('.git')
|
|
||||||
|
|
||||||
loc = os.getcwd()
|
|
||||||
os.chdir(path)
|
|
||||||
repo = self.command('git config --get remote.origin.url')
|
|
||||||
os.chdir(loc)
|
|
||||||
|
|
||||||
#assignments
|
|
||||||
adict = []
|
|
||||||
#default files for classes
|
|
||||||
fdict=[]
|
|
||||||
#default files for assignments
|
|
||||||
afdict=[]
|
|
||||||
for a in ass:
|
|
||||||
aname=a
|
|
||||||
path = self.username + "/" + c + "/" + a
|
|
||||||
#need to add option
|
|
||||||
due_date= '2020-06-07T07:46:30.537197Z',
|
|
||||||
#check for default file
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
fdict.append({
|
|
||||||
'name':a,
|
|
||||||
'path':path
|
|
||||||
})
|
|
||||||
elif(os.path.isdir(path)):
|
|
||||||
for af in os.listdir(path):
|
|
||||||
path = path+ "/" + af
|
|
||||||
if(os.path.isfile(path)):
|
|
||||||
afdict.append({
|
|
||||||
'name':af,
|
|
||||||
'path':path
|
|
||||||
})
|
|
||||||
path = self.username + "/" + c + "/" + a
|
|
||||||
adict.append({
|
|
||||||
'name':aname,
|
|
||||||
'due_date': due_date[0],
|
|
||||||
'path':path,
|
|
||||||
'files':afdict
|
|
||||||
})
|
|
||||||
|
|
||||||
self.compareDB(fdict, "http://127.0.0.1:8000/files/")
|
|
||||||
self.compareDB(afdict,"http://127.0.0.1:8000/files/")
|
|
||||||
|
|
||||||
self.compareDB(adict, 'http://127.0.0.1:8000/files/')
|
|
||||||
|
|
||||||
path = self.username + "/" + c
|
|
||||||
print(fdict)
|
|
||||||
cdict.append({
|
|
||||||
'name':c,
|
|
||||||
'repo': repo,
|
|
||||||
'path':path,
|
|
||||||
'assignments':adict,
|
|
||||||
'default_file':fdict,
|
|
||||||
})
|
|
||||||
self.compareDB(cdict,'http://127.0.0.1:8000/classes/')
|
|
||||||
|
|
||||||
mdict= {
|
|
||||||
'first_name':self.first_name,
|
|
||||||
'last_name':self.last_name,
|
|
||||||
'git':self.git,
|
|
||||||
'ion_user':self.username,
|
|
||||||
'classes':cdict,
|
|
||||||
}
|
|
||||||
|
|
||||||
data = json.dumps(mdict)
|
|
||||||
# r = requests.put(url = 'http://127.0.0.1:8000/teachers/eharris1/', data=data, headers={'Content-type': 'application/json'} , auth=('raffukhondaker','hackgroup1'))
|
|
||||||
# print(print(r.json()))
|
|
||||||
|
|
||||||
|
|
||||||
#class name format: <course-name>_<ion_user>
|
#class name format: <course-name>_<ion_user>
|
||||||
|
|
||||||
|
@ -288,7 +129,7 @@ class Teacher:
|
||||||
print("Assignment '" + as_bad + "' does not have a default file!")
|
print("Assignment '" + as_bad + "' does not have a default file!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if(deffile):
|
if(deffile==False):
|
||||||
print("Need a default file in the " + path + " Directory!")
|
print("Need a default file in the " + path + " Directory!")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -298,74 +139,80 @@ class Teacher:
|
||||||
cname = path.split("/")
|
cname = path.split("/")
|
||||||
cname = cname[len(cname)-1]
|
cname = cname[len(cname)-1]
|
||||||
#push to remote repo
|
#push to remote repo
|
||||||
|
url='https://github.com/' + self.git + "/" + cname
|
||||||
if(self.checkClass(path)):
|
if(self.checkClass(path)):
|
||||||
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
if(requests.get(url).status_code != 200):
|
||||||
webbrowser.open('https://github.com/new')
|
input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n")
|
||||||
input("Repo created? (Press any key to continue)\n")
|
webbrowser.open('https://github.com/new')
|
||||||
|
input("Repo created? (Press any key to continue)\n")
|
||||||
|
|
||||||
url='https://github.com/' + self.git + "/" + cname
|
print(url)
|
||||||
print(url)
|
while(requests.get(url).status_code != 200):
|
||||||
while(requests.get(url).status_code != 200):
|
print(requests.get(url))
|
||||||
print(requests.get(url))
|
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
||||||
r = input("Repo not created yet. (Press any key to continue after repo created, or 'N' to exit)\n")
|
if(r=="N" or r=="No"):
|
||||||
if(r=="N" or r=="No"):
|
return None
|
||||||
return None
|
|
||||||
cdir = os.getcwd()
|
cdir = os.getcwd()
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
self.command('git init')
|
command('git init')
|
||||||
self.command('git add .')
|
command('git add .')
|
||||||
self.command('git commit -m Hello_Class')
|
command('git commit -m Hello_Class')
|
||||||
self.command('git remote add origin ' + url + '.git')
|
command('git remote add origin ' + url + '.git')
|
||||||
self.command('git push -u origin master')
|
command('git push -u origin master')
|
||||||
os.chdir(cdir)
|
os.chdir(cdir)
|
||||||
|
data={
|
||||||
|
'name':cname,
|
||||||
|
'repo':url,
|
||||||
|
'path':path,
|
||||||
|
'teacher':self.username
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
#make a new class from scratch
|
#make a new class from scratch
|
||||||
def makeClass(self, subject):
|
#subject: string, assignments: list
|
||||||
cname = subject + "_" + self.username
|
#class name must be: <subject>_<ion_user>
|
||||||
|
def makeClass(self, cname, assignments):
|
||||||
|
cdir = os.getcwd()
|
||||||
os.chdir(self.username)
|
os.chdir(self.username)
|
||||||
#check if class exists
|
#check if class exists
|
||||||
if(os.path.exists(cname)):
|
if(os.path.exists(cname)):
|
||||||
print("Already synced to: " + str(self.username))
|
print("Class already exists: " + cname)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
if((("_" + self.username) in cname) == False):
|
||||||
|
print("class name must be: "+ cname + "_" + self.username)
|
||||||
|
return
|
||||||
|
path = self.username + "/" + cname
|
||||||
os.mkdir(cname)
|
os.mkdir(cname)
|
||||||
f=open(cname + "/README.md", "w")
|
f=open(cname + "/README.md", "w")
|
||||||
f.close()
|
f.close()
|
||||||
#push to remote repo
|
#push to remote repo
|
||||||
os.chdir(cname)
|
os.chdir(cname)
|
||||||
command(self, 'git init')
|
for a in assignments:
|
||||||
command(self, 'git add .')
|
os.mkdir(a)
|
||||||
command(self, 'git commit -m "Hello Class!"')
|
f=open(a + "/instructions.txt", "w")
|
||||||
#git remote add origin git@github.com:alexpchin/<reponame>.git
|
f.close()
|
||||||
command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git")
|
os.chdir(cdir)
|
||||||
command(self, 'git push -u origin master')
|
|
||||||
|
|
||||||
cinfo=[
|
data = self.addClasstoGit(path)
|
||||||
{
|
print(postDB(data, 'http://127.0.0.1:8000/classes/'))
|
||||||
"name":cname,
|
if(len(self.sclass)==0):
|
||||||
"assignments":[],
|
classes = cname
|
||||||
"repo": "https://github.com:" + self.git + "/" + cname + ".git",
|
else:
|
||||||
"default_file": [
|
classes = self.sclass + "," + cname
|
||||||
{
|
|
||||||
"name":"README.md"
|
data={
|
||||||
}
|
'first_name':self.first_name,
|
||||||
]
|
'last_name':self.last_name,
|
||||||
|
'git':self.git,
|
||||||
|
'ion_user':self.username,
|
||||||
|
'url':self.url,
|
||||||
|
'classes':classes
|
||||||
}
|
}
|
||||||
]
|
print(putDB(data, self.url))
|
||||||
|
return data
|
||||||
#update rest API
|
|
||||||
self.classes.append(cinfo)
|
|
||||||
update(self)
|
|
||||||
data = {
|
|
||||||
"url": self.url,
|
|
||||||
"first_name": self.first_name,
|
|
||||||
"last_name": self.first_name,
|
|
||||||
"classes": self.classes,
|
|
||||||
"git": self.git,
|
|
||||||
"ion_user": self.username
|
|
||||||
},
|
|
||||||
r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1'))
|
|
||||||
|
|
||||||
#make student repo by student id
|
#make student repo by student id
|
||||||
def addStudent(self,stid):
|
def addStudent(self,stid):
|
||||||
|
@ -374,9 +221,8 @@ class Teacher:
|
||||||
def comment(self):
|
def comment(self):
|
||||||
print("heheheh")
|
print("heheheh")
|
||||||
|
|
||||||
# data = getData("eharris1")
|
data = getTeacher("eharris1")
|
||||||
data={'url': 'http://127.0.0.1:8000/teachers/eharris1/', 'first_name': 'Errin', 'last_name': 'Harris', 'git': 'therealraffi', 'ion_user': 'eharris1', 'classes': [{'url': 'http://127.0.0.1:8000/classes/1/', 'name': 'Math5_eharris1', 'repo': 'http://127.0.0.1:8000/assignments/3/', 'assignments': [{'name': 'Week1_HW', 'due_date': '2020-06-07T07:46:30.537197Z', 'url': 'http://127.0.0.1:8000/assignments/1/', 'files': [{'name': 'instructions.txt'}]}, {'name': 'Week2_HW', 'due_date': '2020-06-07T07:46:30.548596Z', 'url': 'http://127.0.0.1:8000/assignments/2/', 'files': [{'name': 'instructions.txt'}]}], 'default_file': [{'name': 'instructions.txt'}]}]}
|
|
||||||
t = Teacher(data)
|
t = Teacher(data)
|
||||||
t.update()
|
t.makeClass('Math4_eharris1', ['Week1_HW', 'Week2_HW'])
|
||||||
|
|
||||||
|
|
||||||
|
|
2
CLI/text.py
Normal file
2
CLI/text.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import textract
|
||||||
|
text = textract.process('test.py')
|
|
@ -1 +0,0 @@
|
||||||
[{"first_name": "Raffu", "last_name": "Khondaker", "password": "password", "webmail": "2022rkhondak@tjhsst.edu", "classes": {"Math": ["week1_hw", "week2_hw", "week3_hw", "unit3_quiz"], "English": ["journal1", "journal2", "journal3"]}}]
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-07 07:45
|
# Generated by Django 3.0.7 on 2020-06-09 02:03
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
@ -17,6 +17,10 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('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)),
|
||||||
('due_date', models.DateTimeField()),
|
('due_date', models.DateTimeField()),
|
||||||
|
('files', models.CharField(max_length=100)),
|
||||||
|
('path', models.CharField(max_length=100)),
|
||||||
|
('classes', models.CharField(max_length=100)),
|
||||||
|
('teacher', models.CharField(max_length=100)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -24,7 +28,11 @@ class Migration(migrations.Migration):
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('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)),
|
||||||
('assignments', models.ManyToManyField(default='', to='api.Assignment')),
|
('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)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -32,6 +40,10 @@ class Migration(migrations.Migration):
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('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)),
|
||||||
|
('path', models.CharField(max_length=100)),
|
||||||
|
('assignment', models.CharField(default='', max_length=100)),
|
||||||
|
('classes', models.CharField(max_length=100)),
|
||||||
|
('teacher', models.CharField(max_length=100)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -40,9 +52,9 @@ class Migration(migrations.Migration):
|
||||||
('created', models.DateTimeField(auto_now_add=True)),
|
('created', models.DateTimeField(auto_now_add=True)),
|
||||||
('first_name', models.CharField(max_length=100)),
|
('first_name', models.CharField(max_length=100)),
|
||||||
('last_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)),
|
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
||||||
('git', models.URLField(default='')),
|
('git', models.CharField(max_length=100)),
|
||||||
('classes', models.ManyToManyField(default='', to='api.Classes')),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
|
@ -55,14 +67,9 @@ class Migration(migrations.Migration):
|
||||||
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
||||||
('webmail', models.EmailField(blank=True, max_length=254)),
|
('webmail', models.EmailField(blank=True, max_length=254)),
|
||||||
('grade', models.IntegerField()),
|
('grade', models.IntegerField()),
|
||||||
('git', models.URLField()),
|
('git', models.CharField(max_length=100)),
|
||||||
('repo', models.URLField(default='')),
|
('repo', models.URLField(default='')),
|
||||||
('classes', models.ManyToManyField(default='', to='api.Classes')),
|
('classes', models.ManyToManyField(default='', to='api.Classes')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='files',
|
|
||||||
field=models.ManyToManyField(default='instructions.txt', to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-07 07:51
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='files',
|
|
||||||
field=models.ManyToManyField(to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,23 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-07 15:19
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0002_auto_20200607_0751'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='classes',
|
|
||||||
name='repo',
|
|
||||||
field=models.URLField(default=''),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='files',
|
|
||||||
field=models.ManyToManyField(default='', to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 02:20
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0003_auto_20200607_1519'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='teacher',
|
|
||||||
name='git',
|
|
||||||
field=models.CharField(default='', max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 02:22
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0004_auto_20200608_0220'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='teacher',
|
|
||||||
name='git',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 02:23
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0005_auto_20200608_0222'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='student',
|
|
||||||
name='git',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,19 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 03:18
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0006_auto_20200608_0223'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='classes',
|
|
||||||
name='default_file',
|
|
||||||
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 03:41
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0007_classes_default_file'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RemoveField(
|
|
||||||
model_name='classes',
|
|
||||||
name='default_file',
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='classes',
|
|
||||||
name='default_file',
|
|
||||||
field=models.ManyToManyField(to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 05:02
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0008_auto_20200608_0341'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='classes',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(max_length=100, primary_key=False, serialize=False),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 05:10
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0009_auto_20200608_0502'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='classes',
|
|
||||||
name='name',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 18:53
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0010_auto_20200608_0510'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='files',
|
|
||||||
field=models.ManyToManyField(to='api.DefFiles'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 21:15
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0011_auto_20200608_1853'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='deffiles',
|
|
||||||
name='path',
|
|
||||||
field=models.FilePathField(default=''),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 21:17
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0012_deffiles_path'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='deffiles',
|
|
||||||
name='path',
|
|
||||||
field=models.CharField(default='', max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 21:22
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0013_auto_20200608_2117'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='deffiles',
|
|
||||||
name='path',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 22:02
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0014_auto_20200608_2122'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='path',
|
|
||||||
field=models.CharField(default='', max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 22:03
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0015_assignment_path'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='path',
|
|
||||||
field=models.CharField(max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0.7 on 2020-06-08 22:23
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('api', '0016_auto_20200608_2203'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='classes',
|
|
||||||
name='path',
|
|
||||||
field=models.CharField(default='', max_length=100),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -3,12 +3,18 @@ from django.db import models
|
||||||
class DefFiles(models.Model):
|
class DefFiles(models.Model):
|
||||||
name=models.CharField(max_length=100)
|
name=models.CharField(max_length=100)
|
||||||
path=models.CharField(max_length=100)
|
path=models.CharField(max_length=100)
|
||||||
|
assignment=models.CharField(max_length=100, default="")
|
||||||
|
classes=models.CharField(max_length=100)
|
||||||
|
teacher=models.CharField(max_length=100)
|
||||||
|
|
||||||
class Assignment(models.Model):
|
class Assignment(models.Model):
|
||||||
name=models.CharField(max_length=100)
|
name=models.CharField(max_length=100)
|
||||||
due_date=models.DateTimeField()
|
due_date=models.DateTimeField()
|
||||||
files = models.ManyToManyField(DefFiles)
|
# files = models.ManyToManyField(DefFiles)
|
||||||
|
files=models.CharField(max_length=100)
|
||||||
path=models.CharField(max_length=100)
|
path=models.CharField(max_length=100)
|
||||||
|
classes=models.CharField(max_length=100)
|
||||||
|
teacher=models.CharField(max_length=100)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s' % (self.name)
|
return '%s' % (self.name)
|
||||||
|
|
||||||
|
@ -16,8 +22,12 @@ class Classes(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
repo=models.URLField(default="")
|
repo=models.URLField(default="")
|
||||||
path=models.CharField(max_length=100, default="")
|
path=models.CharField(max_length=100, default="")
|
||||||
assignments = models.ManyToManyField(Assignment, default="")
|
teacher=models.CharField(max_length=100, default="")
|
||||||
default_file = models.ManyToManyField(DefFiles)
|
assignments=models.CharField(max_length=100, default="")
|
||||||
|
default_file=models.CharField(max_length=100, default="")
|
||||||
|
|
||||||
|
# assignments = models.ManyToManyField(Assignment, default="")
|
||||||
|
# default_file = models.ManyToManyField(DefFiles)
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
return super(Classes, self).save(*args, **kwargs)
|
return super(Classes, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -25,7 +35,8 @@ class Teacher(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
first_name = models.CharField(max_length=100)
|
first_name = models.CharField(max_length=100)
|
||||||
last_name = models.CharField(max_length=100)
|
last_name = models.CharField(max_length=100)
|
||||||
classes = models.ManyToManyField(Classes, default="")
|
# classes = models.ManyToManyField(Classes, default="")
|
||||||
|
classes=models.CharField(max_length=100, default="")
|
||||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||||
git=models.CharField(max_length=100)
|
git=models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,21 @@ class DefFilesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DefFiles
|
model = DefFiles
|
||||||
fields = ['name', 'path','url']
|
fields = ['name', 'path','assignment','classes', "teacher",'url', 'id']
|
||||||
|
|
||||||
class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
|
class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||||
files = DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
# files = DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Assignment
|
model = Assignment
|
||||||
fields = ['name', 'due_date', 'url', 'path' ,'files']
|
fields = ['name', 'due_date', 'url', 'path' , "classes","teacher",'files', 'id']
|
||||||
|
|
||||||
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
# assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
||||||
default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
# default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classes
|
model = Classes
|
||||||
fields = ['url', 'name', 'repo','path', 'assignments',"default_file"]
|
fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id']
|
||||||
|
|
||||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
|
@ -29,9 +29,9 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id', 'git','repo','ion_user','classes']
|
fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id', 'git','repo','ion_user','classes']
|
||||||
|
|
||||||
class TeacherSerializer(serializers.ModelSerializer):
|
class TeacherSerializer(serializers.ModelSerializer):
|
||||||
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Teacher
|
model = Teacher
|
||||||
fields = ['url', 'first_name', 'last_name','git','ion_user','classes' ]
|
fields = ['url', 'first_name', 'last_name','git','ion_user','classes']
|
||||||
|
|
||||||
|
|
||||||
|
|
0
eharris1/Math4_eharris1/Week2_HW/instructions.txt
Normal file
0
eharris1/Math4_eharris1/Week2_HW/instructions.txt
Normal file
0
eharris1/Math5_eharris1/README.md
Normal file
0
eharris1/Math5_eharris1/README.md
Normal file
Loading…
Reference in New Issue
Block a user