cli update

This commit is contained in:
Raffu Khondaker 2020-06-15 18:31:18 -04:00
parent b31f6146d2
commit 06e56352ee
12 changed files with 217 additions and 165 deletions

1
.profiles Normal file
View File

@ -0,0 +1 @@
{"username": "2022rkhondak", "grade": 10, "is_student": true, "password": "hackgroup1"}

View File

@ -43,6 +43,11 @@ def putDB(data, url):
print("PUT:" + str(r.status_code))
return(r.json())
def patchDB(data, url):
r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1'))
print("PATH:" + str(r.status_code))
return(r.json())
def delDB(url):
r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1'))
print("DELETE:" + str(r.status_code))
@ -129,17 +134,9 @@ class Student:
os.chdir(cdir)
self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git'
data={
'user':self.user,
'git':self.git,
'ion_user':self.username,
'added_to':self.snew,
'url':self.url,
'classes':self.sclass,
'grade':self.grade,
'completed':self.completed,
'repo':self.repo
}
print(putDB(data, self.url))
print(patchDB(data, self.url))
print("Synced to " + self.username)
def getClasses(self):
@ -279,17 +276,10 @@ class Student:
#update teacher instance in db, classes field
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(self.url)
print(putDB(data, self.url))
print(patchDB(data, self.url))
return data
def submit(self, path):

View File

@ -1,4 +1,4 @@
# Generated by Django 3.0.7 on 2020-06-14 23:00
# Generated by Django 3.0.7 on 2020-06-15 19:24
from django.conf import settings
from django.db import migrations, models
@ -23,8 +23,6 @@ class Migration(migrations.Migration):
('path', models.CharField(default='', max_length=100)),
('assignments', models.TextField(blank=True, default='')),
('default_file', models.CharField(blank=True, default='', max_length=100)),
('confirmed', models.TextField(blank=True, default='')),
('unconfirmed', models.TextField(blank=True, default='')),
],
),
migrations.CreateModel(
@ -43,23 +41,33 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('git', models.CharField(blank=True, default='', max_length=100)),
('classes', models.ManyToManyField(to='api.Class')),
('classes', models.ManyToManyField(blank=True, related_name='classes', to='api.Class')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Student',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('grade', models.IntegerField(blank=True, default=0)),
('git', models.CharField(blank=True, default='', max_length=100)),
('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='')),
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='class',
name='confirmed',
field=models.ManyToManyField(blank=True, related_name='confirmed', to='api.Student'),
),
migrations.AddField(
model_name='class',
name='unconfirmed',
field=models.ManyToManyField(blank=True, related_name='unconfirmed', to='api.Student'),
),
migrations.CreateModel(
name='Assignment',
fields=[

View File

@ -1,31 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-15 00:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='class',
name='confirmed',
),
migrations.AddField(
model_name='class',
name='confirmed',
field=models.ManyToManyField(blank=True, related_name='confirmed', to='api.Student'),
),
migrations.RemoveField(
model_name='class',
name='unconfirmed',
),
migrations.AddField(
model_name='class',
name='unconfirmed',
field=models.ManyToManyField(blank=True, related_name='unconfirmed', to='api.Student'),
),
]

View File

@ -1,4 +1,4 @@
# Generated by Django 3.0.7 on 2020-06-15 00:48
# Generated by Django 3.0.7 on 2020-06-15 20:19
from django.db import migrations, models
@ -6,18 +6,18 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0004_auto_20200614_2107'),
('api', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='student',
model_name='teacher',
name='id',
),
migrations.AddField(
model_name='student',
model_name='teacher',
name='ion_user',
field=models.CharField(default='2022rkhondak', max_length=100, primary_key=True, serialize=False),
field=models.CharField(default='eharris1', max_length=100, primary_key=True, serialize=False),
preserve_default=False,
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-15 02:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0002_auto_20200615_0046'),
]
operations = [
migrations.AlterField(
model_name='teacher',
name='classes',
field=models.ManyToManyField(blank=True, related_name='teacher', to='api.Class'),
),
]

View File

@ -1,22 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-15 02:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20200615_0233'),
]
operations = [
migrations.RemoveField(
model_name='teacher',
name='classes',
),
migrations.AddField(
model_name='class',
name='teachers',
field=models.ManyToManyField(blank=True, related_name='teachers', to='api.Teacher'),
),
]

View File

@ -11,6 +11,7 @@ class Student(models.Model):
classes=models.CharField(max_length=100, default="", blank=True)
added_to=models.CharField(max_length=100, default="", blank=True)
completed=models.TextField(default="", blank=True)
ion_user=models.CharField(primary_key=True, max_length=100)
def save(self, *args, **kwargs):
super(Student, self).save(*args, **kwargs)
@ -40,7 +41,7 @@ class Teacher(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
classes=models.ManyToManyField(Class, blank=True, related_name='classes')
git=models.CharField(max_length=100, default="", blank=True)
ion_user=models.CharField(primary_key=True, max_length=100)
def __str__(self):
return f"{self.user.username}'s Profile"
@ -48,15 +49,15 @@ class Teacher(models.Model):
def save(self, *args, **kwargs):
super(Teacher, self).save(*args, **kwargs)
class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
ion_user=models.CharField(primary_key=True, max_length=100)
grade = models.IntegerField(default=0, blank=True)
git=models.CharField(default="", max_length=100, blank=True)
repo=models.URLField(default="", blank=True)
classes=models.CharField(max_length=100, default="", blank=True)
added_to=models.CharField(max_length=100, default="", blank=True)
completed=models.TextField(default="", blank=True)
# class Student(models.Model):
# user = models.OneToOneField(User, on_delete=models.CASCADE)
# ion_user=models.CharField(primary_key=True, max_length=100)
# grade = models.IntegerField(default=0, blank=True)
# git=models.CharField(default="", max_length=100, blank=True)
# repo=models.URLField(default="", blank=True)
# classes=models.CharField(max_length=100, default="", blank=True)
# added_to=models.CharField(max_length=100, default="", blank=True)
# completed=models.TextField(default="", blank=True)

View File

@ -1,5 +1,5 @@
from django.contrib.auth.models import User, Group
from .models import Student, Teacher, Classes, Assignment, DefFiles
from .models import Student, Teacher, Class, Assignment, DefFiles
from rest_framework import serializers, permissions
from django.contrib.auth.models import User
from .permissions import IsOwnerOrReadOnly,isTeacher
@ -30,11 +30,11 @@ class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
# assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
# default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
owner = serializers.ReadOnlyField(source='owner.username')
#owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = Classes
model = Class
# fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
fields = ['name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
fields = ['name', 'repo','path','assignments',"default_file", 'confirmed', 'unconfirmed']
class StudentSerializer(serializers.HyperlinkedModelSerializer):
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
@ -43,12 +43,12 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
# fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo','owner']
fields = ['url','grade', 'ion_user','git','user','classes','added_to','completed', 'repo']
class TeacherSerializer(serializers.ModelSerializer):
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
owner = serializers.ReadOnlyField(source='owner.username')
class TeacherSerializer(serializers.HyperlinkedModelSerializer):
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
#owner = serializers.ReadOnlyField(source='owner.username')
class Meta:
model = Teacher
# fields = ['url','first_name', 'last_name','git','ion_user', 'email','classes','owner']
fields = ['first_name', 'last_name','git','ion_user', 'email','classes','owner']
fields = ['git','classes','user', 'url']

View File

@ -1,5 +1,5 @@
from .models import Student, Teacher, Class, Assignment, DefFiles
from .serializers import StudentSerializer, TeacherSerializer, ClassSerializer, AssignmentSerializer, UserSerializer
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, UserSerializer
from rest_framework import generics, viewsets, permissions, response, status
from django.http import Http404
from rest_framework.views import APIView
@ -10,7 +10,6 @@ from rest_framework.parsers import JSONParser
from rest_framework.response import Response
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
@ -26,7 +25,7 @@ class StudentViewSet(viewsets.ModelViewSet):
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
serializer.save(user=self.request.user)
class TeacherViewSet(viewsets.ModelViewSet):
"""
@ -37,22 +36,22 @@ class TeacherViewSet(viewsets.ModelViewSet):
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
serializer.save(user=self.request.user)
class ClassViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = Class.objects.all()
serializer_class = ClassSerializer
serializer_class = ClassesSerializer
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
def perform_create(self, serializer):
if(self.request.user.groups.filter(name__in=['teachers']).exists() or self.request.user.is_superuser):
serializer.save(owner=self.request.user)
else:
print("UNAUTHORIZED POST")
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# def perform_create(self, serializer):
# if(self.request.user.groups.filter(name__in=['teachers']).exists() or self.request.user.is_superuser):
# serializer.save(owner=self.request.user)
# else:
# print("UNAUTHORIZED POST")
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class AssignmentViewSet(viewsets.ModelViewSet):

View File

@ -65,66 +65,91 @@ def studentCLI(user, password):
from CLI import student
data = getUser(user, password)
student = student.Student(data)
choices = ['1) View Class','2) Exit SkoolOS']
questions = [
carray = student.sclass.split(",")
if(len(carray) == 1 and carray[0] == ""):
print("No classes")
return
carray.append("Exit SkoolOS")
courses = [
{
'type': 'list',
'name': 'choice',
'choices':choices,
'name': 'course',
'choices':carray,
'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):
course = prompt(courses)
if course == "Exit SkoolOS":
student.exitCLI()
else:
student.viewClass(course)
def teacherCLI(user, password):
from CLI import teacher
data = getUser(user, password)
teacher = teacher.Teacher(data)
choices = ['1) View Class','2) Exit SkoolOS']
questions = [
# 1. make a class
# 2. add studeents to an existing class
# 3. Get progress logs on a student
# 2. make an assignment for a class
# 3. view student submissions for an assignment
carray = teacher.sclass.split(",")
carray.remove("")
carray.append("Exit SkoolOS")
carray.append("Make New Class")
courses = [
{
'type': 'list',
'name': 'choice',
'choices':choices,
'name': 'course',
'choices':carray,
'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 = [
course = prompt(courses)
if course == "Exit SkoolOS":
teacher.exitCLI()
if course == "Make New Class":
questions = [
{
'type': 'input',
'name': 'cname',
'message': 'Class Name: ',
},
]
cname = prompt(questions)
teacher.makeClass(cname)
soption = ["1) Add individual student", "2) Add list of students through path", "3) Exit"]
questions = [
{
'type': 'list',
'choices':soption,
'name': 'students',
'message': 'Add list of students (input path): ',
},
]
choice = prompt(questions).split(")")
if("1" == choice):
s = input("Student name: ")
teacher.addStudent(s, cname)
if("2" == choice):
p = input("Relativee Path: ")
if(os.path.exists(p)):
print(p + " does not exist.")
else:
print("Class: " + cname)
options = ['1) Add student', "2) Add assignment", "3) View student information"]
questions = [
{
'type': 'list',
'name': 'course',
'choices':carray,
'message': 'Select class: ',
'choices':options,
'message': 'Select option: ',
},
]
course = prompt(courses)
if(choice == 2):
student.exitCLI()
option = prompt(questions)
def getUser(ion_user, password):
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"

99
snew.py Normal file
View File

@ -0,0 +1,99 @@
import sys
from urllib.parse import urlparse
import requests
from requests_oauthlib import OAuth2Session
from selenium import webdriver
import os.path
import time
import http.server
import socketserver
from threading import Thread
from werkzeug.urls import url_decode
import pprint
from PyInquirer import prompt, print_json
import json
import os
import argparse
import webbrowser
import subprocess
from django.conf import settings
import django
from Website.config.settings import DATABASES, INSTALLED_APPS
INSTALLED_APPS.remove('users.apps.UsersConfig')
INSTALLED_APPS.remove('api')
INSTALLED_APPS.remove('skoolos.apps.SkoolosConfig')
INSTALLED_APPS.append('Website.api')
settings.configure(DATABASES=DATABASES, INSTALLED_APPS=INSTALLED_APPS)
django.setup()
from Website.api.models import *
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'))
return output.decode('utf-8')
class Students:
def __init__(self, username):
self.student = Student.objects.get(ion_user = username)
#ion id: student.user
if(os.path.isdir(self.student.user) == False):
if(self.student.repo == ""):
user= self.student.git
pwd= input("Enter Github password: ")
#curl -i -u USER:PASSWORD -d '{"name":"REPO"}' https://api.github.com/user/repos
url= "curl -i -u " + user + ":" + pwd + " -d '" + '{"name":"' + self.username + '"}' + "' " + "https://api.github.com/user/repos"
print(url)
os.system(url)
cdir = os.getcwd()
command('git clone https://github.com/' + self.git + '/' + self.username + '.git')
os.chdir(self.username)
command('git checkout master')
command('touch README.md')
command('git add README.md')
command('git commit -m "Hello"')
command('git push -u origin master')
os.chdir(cdir)
self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git'
data={
'user':self.user,
'git':self.git,
'ion_user':self.username,
'added_to':self.snew,
'url':self.url,
'classes':self.sclass,
'grade':self.grade,
'completed':self.completed,
'repo':self.repo
}
print(putDB(data, self.url))
print("Synced to " + self.username)
# c = {
# 'name':'Math5'
# }
# c = Class.objects.get(name='Math5')
data = requests.get(url = "http://localhost:8000/api/classes/Math5", auth=('raffukhondaker','hackgroup1')).json()
c = Class(
name="data['name']"
)
# print("POST:" + str(r.status_code))
# print(r.json())
c = {
'classes':"http://localhost:8000/api/classes/Math5/"
}
# print(c)
r = requests.patch(url = "http://localhost:8000/api/teachers/2/", data=c, auth=('raffukhondaker','hackgroup1'))
print(r.json())