From 4f9bc55a238a9796490d781ec35c0c7aed1194b0 Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Fri, 5 Jun 2020 01:06:57 -0400 Subject: [PATCH 01/22] added vscode --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2e3cb3b..5a28dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -128,5 +128,11 @@ dmypy.json # Pyre type checker .pyre/ +# VSCode +.vscode/ + # PyCharm Files -.idea/ \ No newline at end of file +.idea/ + +# Mac lmao +.DS_Store From ceebd64651948f924e524426af45c8ed4a948a4f Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Fri, 5 Jun 2020 01:09:58 -0400 Subject: [PATCH 02/22] added requirements.txt --- requirements.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e8928be --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +certifi==2020.4.5.1 +chardet==3.0.4 +idna==2.9 +oauthlib==3.1.0 +prompt-toolkit==1.0.14 +Pygments==2.6.1 +PyInquirer==1.0.3 +regex==2020.5.14 +requests==2.23.0 +requests-oauthlib==1.3.0 +selenium==3.141.0 +six==1.15.0 +urllib3==1.25.9 +wcwidth==0.2.3 From 41c8edfdbb44e373ad743dcc76f5b62f0a25faea Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Fri, 5 Jun 2020 22:40:56 -0400 Subject: [PATCH 03/22] git file --- CLI/commands.py | 130 ------------------------------------------------ CLI/git.py | 38 ++++++++++++++ CLI/run.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 165 insertions(+), 131 deletions(-) create mode 100644 CLI/git.py diff --git a/CLI/commands.py b/CLI/commands.py index 1780d32..ed1c1f3 100644 --- a/CLI/commands.py +++ b/CLI/commands.py @@ -5,134 +5,4 @@ import os import argparse -#already ccrerrated account through website, has to login -def update(): - #get data from database - return - -def yesorno(question): - questions = [ - { - 'type': 'input', - 'name': 'response', - 'message': question, - }, - ] - answers = prompt(questions) - if(answers["response"] == "y"): - return True - return False - -def login(): - #enter username - #enter password - questions = [ - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s TJ Webmail', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - #reading from json of users (replace w GET to database) to check if user is registered - with open('users.json', 'r') as json_file: - data = json.load(json_file) - for i in range(len(data)): - if user["webmail"] == data[i]["webmail"]: - if(user["password"] == data[i]["password"]): - print("Logged in!") - return data[i] - else: - print("Password incorrect. Try again.") - return None - print("User not found. Please Try again") - return None - -#did not create account through website, has to signup/login -def signup(): - questions = [ - { - 'type': 'input', - 'name': 'first-name', - 'message': 'What\'s your first name', - }, - { - 'type': 'input', - 'name': 'last-name', - 'message': 'What\'s your last name?', - }, - { - 'type': 'list', - 'name': 'grade', - 'message': 'Grade?', - 'choices':["9","10","11","12"] - }, - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s your TJ Webmail?', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - for i in user: - if user[i] == "": - print("Some forms were left blank. Try again.\n") - return None - if len(user["password"]) < 6: - print("Password is too short. Try again.") - return None - if (("@tjhsst.edu" in user['webmail']) == False): - print("Webmail entered was not a @tjhhsst.edu. Try again.") - return None - - user["classes"] = [] - with open('users.json', 'r') as json_file: - data = json.load(json_file) - data.append(user) - open("users.json", "w").write(str(json.dumps(data))) - return user - -def relogin(): - questions = [ - { - 'type': 'list', - 'name': 'choice', - 'message': '', - 'choices':["Continue as current user","Login into new user","Sign up into new account"] - }, - ] - answer = prompt(questions) - - -def setup(user): - #Read classes/assignenments and setup directory: - #SkoolOS/Math/Week1 - for c in user["classes"]: - os.makedirs("../" + c) - for a in user["classes"][c]: - os.makedirs("../" + c + "/" + a) - -def start(): - if(os.path.exists(".login.txt") == False): - b = yesorno("Do you have a SkoolOS account?(y/N)") - if(b): - user = login() - if(user != None): - setup(user) - open(".login.txt", "w").write(str(user)) - else: - user = signup() - if(user != None): - open(".login.txt").write(str(user)) - \ No newline at end of file diff --git a/CLI/git.py b/CLI/git.py new file mode 100644 index 0000000..b6c45fd --- /dev/null +++ b/CLI/git.py @@ -0,0 +1,38 @@ +import subprocess +import os + +#students +def initialize(repo, subject): + process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + output = process.communicate() + dirname = repo[repo.rindex('/')+1:repo.index(".git")] + os.rename(dirname, subject) + #print(output) + +#Teachers + +#make student repo by student id +def addStudent(stid, teacher): + os.mkdir(stid) + os.chdir(os.getcwd() + "/" + stid) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + +def addStudents(filename): + print(filename) + +def addAsignment(name): + print(name) + +def updateAssignment(name): + print(name) + +def comment(filename, text): + print(text) + + +initialize("https://github.com/therealraffi/1579460.git", "Math1") diff --git a/CLI/run.py b/CLI/run.py index aca8859..6a51e78 100644 --- a/CLI/run.py +++ b/CLI/run.py @@ -1,11 +1,137 @@ from __future__ import print_function, unicode_literals from PyInquirer import prompt, print_json -from commands import start, update import argparse import json import os import argparse +def yesorno(question): + questions = [ + { + 'type': 'input', + 'name': 'response', + 'message': question, + }, + ] + answers = prompt(questions) + if(answers["response"] == "y"): + return True + return False + +#already ccrerrated account through website, has to login +def login(): + #enter username + #enter password + questions = [ + { + 'type': 'input', + 'name': 'webmail', + 'message': 'What\'s TJ Webmail', + }, + { + 'type': 'password', + 'name': 'password', + 'message': 'Password?', + }, + ] + user = prompt(questions) + #reading from json of users (replace w GET to database) to check if user is registered + with open('users.json', 'r') as json_file: + data = json.load(json_file) + for i in range(len(data)): + if user["webmail"] == data[i]["webmail"]: + if(user["password"] == data[i]["password"]): + print("Logged in!") + return data[i] + else: + print("Password incorrect. Try again.") + return None + print("User not found. Please Try again") + return None + +#did not create account through website, has to signup/login +def update(): + questions = [ + { + 'type': 'input', + 'name': 'first-name', + 'message': 'What\'s your first name', + }, + { + 'type': 'input', + 'name': 'last-name', + 'message': 'What\'s your last name?', + }, + { + 'type': 'list', + 'name': 'grade', + 'message': 'Grade?', + 'choices':["9","10","11","12"] + }, + { + 'type': 'input', + 'name': 'webmail', + 'message': 'What\'s your TJ Webmail?', + }, + { + 'type': 'password', + 'name': 'password', + 'message': 'Password?', + }, + ] + user = prompt(questions) + for i in user: + if user[i] == "": + print("Some forms were left blank. Try again.\n") + return None + if len(user["password"]) < 6: + print("Password is too short. Try again.") + return None + if (("@tjhsst.edu" in user['webmail']) == False): + print("Webmail entered was not a @tjhhsst.edu. Try again.") + return None + + #post user to json, replace w POST to db + user["classes"] = [] + with open('users.json', 'r') as json_file: + data = json.load(json_file) + data.append(user) + open("users.json", "w").write(str(json.dumps(data))) + return user + +def relogin(): + questions = [ + { + 'type': 'list', + 'name': 'choice', + 'message': '', + 'choices':["Continue as current user","Login into new user","Sign up into new account"] + }, + ] + answer = prompt(questions) + + +def setup(user): + #Read classes/assignenments and setup directory: + #SkoolOS/Math/Week1 + for c in user["classes"]: + os.makedirs("../" + c) + for a in user["classes"][c]: + os.makedirs("../" + c + "/" + a) + +def start(): + if(os.path.exists(".login.txt") == False): + b = yesorno("Do you have a SkoolOS account?(y/N)") + if(b): + user = login() + if(user != None): + setup(user) + open(".login.txt", "w").write(str(user)) + else: + user = update() + if(user != None): + open(".login.txt").write(str(user)) + my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again") my_parser.add_argument('--init', action="store_true") #returns true if run argument args = my_parser.parse_args() From 60d16b9e6ae8ac703137244298dc60cdfbaa647b Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sat, 6 Jun 2020 14:44:13 -0400 Subject: [PATCH 04/22] api attempt --- Website/api/__init__.py | 0 Website/api/admin.py | 3 + Website/api/apps.py | 5 + Website/api/migrations/0001_initial.py | 61 +++++++++ .../api/migrations/0002_auto_20200606_1810.py | 24 ++++ .../api/migrations/0003_auto_20200606_1817.py | 26 ++++ .../api/migrations/0004_student_webmail.py | 18 +++ .../api/migrations/0005_auto_20200606_1822.py | 19 +++ .../api/migrations/0006_auto_20200606_1824.py | 24 ++++ .../api/migrations/0007_auto_20200606_1825.py | 21 +++ .../api/migrations/0008_auto_20200606_1839.py | 19 +++ Website/api/migrations/__init__.py | 0 Website/api/models.py | 36 +++++ Website/api/serializers.py | 32 +++++ Website/api/tests.py | 3 + Website/api/urls.py | 0 Website/api/views.py | 34 +++++ Website/manage.py | 21 +++ Website/skoolsite/__init__.py | 0 Website/skoolsite/asgi.py | 16 +++ Website/skoolsite/settings.py | 128 ++++++++++++++++++ Website/skoolsite/urls.py | 16 +++ Website/skoolsite/wsgi.py | 16 +++ requirements.txt | 11 +- 24 files changed, 527 insertions(+), 6 deletions(-) create mode 100644 Website/api/__init__.py create mode 100644 Website/api/admin.py create mode 100644 Website/api/apps.py create mode 100644 Website/api/migrations/0001_initial.py create mode 100644 Website/api/migrations/0002_auto_20200606_1810.py create mode 100644 Website/api/migrations/0003_auto_20200606_1817.py create mode 100644 Website/api/migrations/0004_student_webmail.py create mode 100644 Website/api/migrations/0005_auto_20200606_1822.py create mode 100644 Website/api/migrations/0006_auto_20200606_1824.py create mode 100644 Website/api/migrations/0007_auto_20200606_1825.py create mode 100644 Website/api/migrations/0008_auto_20200606_1839.py create mode 100644 Website/api/migrations/__init__.py create mode 100644 Website/api/models.py create mode 100644 Website/api/serializers.py create mode 100644 Website/api/tests.py create mode 100644 Website/api/urls.py create mode 100644 Website/api/views.py create mode 100755 Website/manage.py create mode 100644 Website/skoolsite/__init__.py create mode 100644 Website/skoolsite/asgi.py create mode 100644 Website/skoolsite/settings.py create mode 100644 Website/skoolsite/urls.py create mode 100644 Website/skoolsite/wsgi.py diff --git a/Website/api/__init__.py b/Website/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Website/api/admin.py b/Website/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/Website/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Website/api/apps.py b/Website/api/apps.py new file mode 100644 index 0000000..d87006d --- /dev/null +++ b/Website/api/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + name = 'api' diff --git a/Website/api/migrations/0001_initial.py b/Website/api/migrations/0001_initial.py new file mode 100644 index 0000000..dff6759 --- /dev/null +++ b/Website/api/migrations/0001_initial.py @@ -0,0 +1,61 @@ +# Generated by Django 3.0.7 on 2020-06-06 17:44 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Classes', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.URLField()), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Teacher', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.URLField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('first_name', models.CharField(max_length=100)), + ('last_name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Student', + fields=[ + ('url', models.URLField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('first_name', models.CharField(max_length=100)), + ('last_name', models.CharField(max_length=100)), + ('student_id', models.IntegerField(primary_key=True, serialize=False)), + ('grade', models.IntegerField()), + ('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')), + ], + ), + migrations.AddField( + model_name='classes', + name='teachers', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), + ), + migrations.CreateModel( + name='Assignment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.URLField()), + ('name', models.CharField(max_length=100)), + ('due_date', models.DateTimeField()), + ('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')), + ('students', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Student')), + ], + ), + ] diff --git a/Website/api/migrations/0002_auto_20200606_1810.py b/Website/api/migrations/0002_auto_20200606_1810.py new file mode 100644 index 0000000..c11d41a --- /dev/null +++ b/Website/api/migrations/0002_auto_20200606_1810.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:10 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='classes', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + migrations.AlterField( + model_name='assignment', + name='students', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), + ), + ] diff --git a/Website/api/migrations/0003_auto_20200606_1817.py b/Website/api/migrations/0003_auto_20200606_1817.py new file mode 100644 index 0000000..5296f69 --- /dev/null +++ b/Website/api/migrations/0003_auto_20200606_1817.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:17 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_auto_20200606_1810'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='classes', + field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + preserve_default=False, + ), + migrations.AlterField( + model_name='assignment', + name='students', + field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Student'), + preserve_default=False, + ), + ] diff --git a/Website/api/migrations/0004_student_webmail.py b/Website/api/migrations/0004_student_webmail.py new file mode 100644 index 0000000..3401b2a --- /dev/null +++ b/Website/api/migrations/0004_student_webmail.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0003_auto_20200606_1817'), + ] + + operations = [ + migrations.AddField( + model_name='student', + name='webmail', + field=models.EmailField(blank=True, max_length=254), + ), + ] diff --git a/Website/api/migrations/0005_auto_20200606_1822.py b/Website/api/migrations/0005_auto_20200606_1822.py new file mode 100644 index 0000000..c5f3384 --- /dev/null +++ b/Website/api/migrations/0005_auto_20200606_1822.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0004_student_webmail'), + ] + + operations = [ + migrations.AlterField( + model_name='student', + name='classes', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + ] diff --git a/Website/api/migrations/0006_auto_20200606_1824.py b/Website/api/migrations/0006_auto_20200606_1824.py new file mode 100644 index 0000000..048263b --- /dev/null +++ b/Website/api/migrations/0006_auto_20200606_1824.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0005_auto_20200606_1822'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='classes', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + migrations.AlterField( + model_name='assignment', + name='students', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), + ), + ] diff --git a/Website/api/migrations/0007_auto_20200606_1825.py b/Website/api/migrations/0007_auto_20200606_1825.py new file mode 100644 index 0000000..595ac9a --- /dev/null +++ b/Website/api/migrations/0007_auto_20200606_1825.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:25 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0006_auto_20200606_1824'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='classes', + ), + migrations.RemoveField( + model_name='assignment', + name='students', + ), + ] diff --git a/Website/api/migrations/0008_auto_20200606_1839.py b/Website/api/migrations/0008_auto_20200606_1839.py new file mode 100644 index 0000000..89e960b --- /dev/null +++ b/Website/api/migrations/0008_auto_20200606_1839.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:39 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0007_auto_20200606_1825'), + ] + + operations = [ + migrations.AlterField( + model_name='classes', + name='teachers', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), + ), + ] diff --git a/Website/api/migrations/__init__.py b/Website/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Website/api/models.py b/Website/api/models.py new file mode 100644 index 0000000..71e4135 --- /dev/null +++ b/Website/api/models.py @@ -0,0 +1,36 @@ +from django.db import models + +class Student(models.Model): + url = models.URLField() + created = models.DateTimeField(auto_now_add=True) + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + student_id = models.IntegerField(primary_key=True) + webmail = models.EmailField(blank=True) + grade = models.IntegerField() + classes = models.ForeignKey('Classes', on_delete=models.CASCADE,blank=True) + +class Teacher(models.Model): + url = models.URLField() + created = models.DateTimeField(auto_now_add=True) + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + #student_id = models.IntegerField(primary_key=True) + +class Classes(models.Model): + url = models.URLField() + name = models.CharField(max_length=100) + teachers = models.ForeignKey('Teacher', on_delete=models.CASCADE,null=True) + + def save(self, *args, **kwargs): + return super(Classes, self).save(*args, **kwargs) + +class Assignment(models.Model): + url = models.URLField() + name=models.CharField(max_length=100) + due_date=models.DateTimeField() + + def __str__(self): + return '%d' % (self.name) + + diff --git a/Website/api/serializers.py b/Website/api/serializers.py new file mode 100644 index 0000000..1c0fa80 --- /dev/null +++ b/Website/api/serializers.py @@ -0,0 +1,32 @@ +from django.contrib.auth.models import User, Group +from .models import Student, Teacher, Classes, Assignment +from rest_framework import serializers + +class AssignmentSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Assignment + fields = ['name', 'due_date', 'url'] + +class StudentSerializer(serializers.HyperlinkedModelSerializer): + assignments = AssignmentSerializer(many=True, read_only=True) + class Meta: + model = Student + fields = ['url', 'first_name', 'last_name', 'assignments'] + +class ClassesSerializer(serializers.HyperlinkedModelSerializer): + assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) + students = StudentSerializer(many=True, read_only=True, allow_null=True) + class Meta: + model = Classes + fields = ['url', 'name', 'students', 'assignments'] + + def create(self, validated_data): + return Classes.objects.create(**validated_data) + + +class TeacherSerializer(serializers.ModelSerializer): + classes = ClassesSerializer(many=True, read_only=True) + class Meta: + model = Teacher + fields = ['url', 'first_name', 'last_name', 'classes'] + diff --git a/Website/api/tests.py b/Website/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/Website/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Website/api/urls.py b/Website/api/urls.py new file mode 100644 index 0000000..e69de29 diff --git a/Website/api/views.py b/Website/api/views.py new file mode 100644 index 0000000..adb1030 --- /dev/null +++ b/Website/api/views.py @@ -0,0 +1,34 @@ +from .models import Student, Teacher, Classes, Assignment +from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer +from rest_framework import generics, viewsets + + + +class StudentViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = Student.objects.all() + serializer_class = StudentSerializer + + +class TeacherViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = Teacher.objects.all() + serializer_class = TeacherSerializer + +class ClassesViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = Classes.objects.all() + serializer_class = ClassesSerializer + +class AssignmentViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = Assignment.objects.all() + serializer_class = AssignmentSerializer diff --git a/Website/manage.py b/Website/manage.py new file mode 100755 index 0000000..063e014 --- /dev/null +++ b/Website/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skoolsite.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/Website/skoolsite/__init__.py b/Website/skoolsite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Website/skoolsite/asgi.py b/Website/skoolsite/asgi.py new file mode 100644 index 0000000..805af95 --- /dev/null +++ b/Website/skoolsite/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for skoolsite project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skoolsite.settings') + +application = get_asgi_application() diff --git a/Website/skoolsite/settings.py b/Website/skoolsite/settings.py new file mode 100644 index 0000000..82549f8 --- /dev/null +++ b/Website/skoolsite/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for skoolsite project. + +Generated by 'django-admin startproject' using Django 3.0.7. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '$v+-0wm%yys7r3&e0s&*tyh-vyc9v&twb_8yk6==290io9yq3(' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework', + 'api', + +] + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 10 +} + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'skoolsite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'skoolsite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/Website/skoolsite/urls.py b/Website/skoolsite/urls.py new file mode 100644 index 0000000..cb665d5 --- /dev/null +++ b/Website/skoolsite/urls.py @@ -0,0 +1,16 @@ +from django.urls import include, path +from rest_framework import routers +from api import views + +router = routers.DefaultRouter() +router.register(r'students', views.StudentViewSet) +router.register(r'teachers', views.TeacherViewSet) +router.register(r'assignments', views.AssignmentViewSet) +router.register(r'classes', views.ClassesViewSet) + +# Wire up our API using automatic URL routing. +# Additionally, we include login URLs for the browsable API. +urlpatterns = [ + path('', include(router.urls)), + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) +] \ No newline at end of file diff --git a/Website/skoolsite/wsgi.py b/Website/skoolsite/wsgi.py new file mode 100644 index 0000000..c3b05f8 --- /dev/null +++ b/Website/skoolsite/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for skoolsite project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'skoolsite.settings') + +application = get_wsgi_application() diff --git a/requirements.txt b/requirements.txt index e8928be..f7c0a91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,13 @@ -certifi==2020.4.5.1 -chardet==3.0.4 -idna==2.9 -oauthlib==3.1.0 +asgiref==3.2.7 +click==7.1.2 +Django==3.0.7 prompt-toolkit==1.0.14 Pygments==2.6.1 PyInquirer==1.0.3 +pytz==2020.1 regex==2020.5.14 -requests==2.23.0 -requests-oauthlib==1.3.0 selenium==3.141.0 six==1.15.0 +sqlparse==0.3.1 urllib3==1.25.9 wcwidth==0.2.3 From 2376dc74305326502cfcad97bbb4b6e26dda97ed Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sat, 6 Jun 2020 18:06:03 -0400 Subject: [PATCH 05/22] api-attemp1 --- Website/api/maker.py | 139 ++++++++++++++++++ .../api/migrations/0009_auto_20200606_1859.py | 28 ++++ .../api/migrations/0010_auto_20200606_1910.py | 40 +++++ .../migrations/0011_classes_assignments.py | 19 +++ .../0012_remove_student_assignments.py | 17 +++ .../api/migrations/0013_auto_20200606_2004.py | 27 ++++ .../api/migrations/0014_auto_20200606_2005.py | 32 ++++ .../api/migrations/0015_auto_20200606_2023.py | 32 ++++ .../api/migrations/0016_classes_teachers.py | 19 +++ .../api/migrations/0017_auto_20200606_2101.py | 35 +++++ .../api/migrations/0018_auto_20200606_2107.py | 18 +++ .../api/migrations/0019_auto_20200606_2126.py | 31 ++++ Website/api/models.py | 45 +++--- Website/api/serializers.py | 20 +-- Website/skoolsite/urls.py | 5 +- 15 files changed, 470 insertions(+), 37 deletions(-) create mode 100644 Website/api/maker.py create mode 100644 Website/api/migrations/0009_auto_20200606_1859.py create mode 100644 Website/api/migrations/0010_auto_20200606_1910.py create mode 100644 Website/api/migrations/0011_classes_assignments.py create mode 100644 Website/api/migrations/0012_remove_student_assignments.py create mode 100644 Website/api/migrations/0013_auto_20200606_2004.py create mode 100644 Website/api/migrations/0014_auto_20200606_2005.py create mode 100644 Website/api/migrations/0015_auto_20200606_2023.py create mode 100644 Website/api/migrations/0016_classes_teachers.py create mode 100644 Website/api/migrations/0017_auto_20200606_2101.py create mode 100644 Website/api/migrations/0018_auto_20200606_2107.py create mode 100644 Website/api/migrations/0019_auto_20200606_2126.py diff --git a/Website/api/maker.py b/Website/api/maker.py new file mode 100644 index 0000000..eaea2c1 --- /dev/null +++ b/Website/api/maker.py @@ -0,0 +1,139 @@ +from api.models import Assignment, Student, Classes, Teacher +from datetime import datetime + +#students +raffu = Student( + first_name = "Raffu", + last_name = "Khondaker", + student_id = 1579460, + webmail = "2022rkhondak@tjhsst.edu", + grade = 10, +) +raffu.save() + +#teachers +ng = Teacher( + first_name = "Kim", + last_name = "Ng", +) + +ng.save() + +chao = Teacher( + first_name = "Susie", + last_name = "Lebryk-Chao", +) + +chao.save() + +#Assignments +A1 = Assignment( + name='Week1_HW', + due_date=datetime.now(), + +) +A1.save() + +A2 = Assignment( + name='Week2_HW', + due_date=datetime.now(), + +) +A2.save() + +A3 = Assignment( + name='Journal1', + due_date=datetime.now(), +) +A3.save() + +#classes +C1 = Classes( + name='Math5', + +) +C1.save() + +C2 = Classes( + name='English', +) +C2.save() + +C2.teachers = chao +C2.students.add(raffu) +C2.save() + +C1.teachers = ng +C1.students.add(raffu) +C1.save() + +################################################################################################################ +from api.models import Assignment, Student, Classes, Teacher +from datetime import datetime + +A1 = Assignment( + name='Week1_HW', + due_date=datetime.now(), + +) +A1.save() + +A2 = Assignment( + name='Week2_HW', + due_date=datetime.now(), + +) +A2.save() + +A3 = Assignment( + name='Journal1', + due_date=datetime.now(), +) +A3.save() + +#classes +math = Classes( + name='Math5', + +) +math.save() +math.assignments.add(A1) +math.assignments.add(A2) +math.save() + +english = Classes( + name='English', +) +english.save() +english.assignments.add(A3) +english.save() + +#students +raffu = Student( + first_name = "Raffu", + last_name = "Khondaker", + student_id = 1579460, + webmail = "2022rkhondak@tjhsst.edu", + grade = 10, +) +raffu.save() +raffu.classes.add(math) +raffu.classes.add(english) +raffu.save() + +#teachers +ng = Teacher( + first_name = "Kim", + last_name = "Ng", +) +ng.save() +ng.classes.add(math) +ng.save() + +chao = Teacher( + first_name = "Susie", + last_name = "Lebryk-Chao", +) +chao.save() +chao.classes.add(english) +chao.save() diff --git a/Website/api/migrations/0009_auto_20200606_1859.py b/Website/api/migrations/0009_auto_20200606_1859.py new file mode 100644 index 0000000..dd679fd --- /dev/null +++ b/Website/api/migrations/0009_auto_20200606_1859.py @@ -0,0 +1,28 @@ +# Generated by Django 3.0.7 on 2020-06-06 18:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0008_auto_20200606_1839'), + ] + + operations = [ + migrations.RemoveField( + model_name='classes', + name='teachers', + ), + migrations.AddField( + model_name='student', + name='assignments', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), + ), + migrations.AlterField( + model_name='student', + name='classes', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + ] diff --git a/Website/api/migrations/0010_auto_20200606_1910.py b/Website/api/migrations/0010_auto_20200606_1910.py new file mode 100644 index 0000000..e437c74 --- /dev/null +++ b/Website/api/migrations/0010_auto_20200606_1910.py @@ -0,0 +1,40 @@ +# Generated by Django 3.0.7 on 2020-06-06 19:10 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0009_auto_20200606_1859'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='url', + ), + migrations.RemoveField( + model_name='classes', + name='url', + ), + migrations.RemoveField( + model_name='student', + name='url', + ), + migrations.RemoveField( + model_name='teacher', + name='url', + ), + migrations.AddField( + model_name='teacher', + name='classes', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + migrations.AddField( + model_name='teacher', + name='students', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), + ), + ] diff --git a/Website/api/migrations/0011_classes_assignments.py b/Website/api/migrations/0011_classes_assignments.py new file mode 100644 index 0000000..e4f45ed --- /dev/null +++ b/Website/api/migrations/0011_classes_assignments.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-06 19:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0010_auto_20200606_1910'), + ] + + operations = [ + migrations.AddField( + model_name='classes', + name='assignments', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), + ), + ] diff --git a/Website/api/migrations/0012_remove_student_assignments.py b/Website/api/migrations/0012_remove_student_assignments.py new file mode 100644 index 0000000..a3de13c --- /dev/null +++ b/Website/api/migrations/0012_remove_student_assignments.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-06-06 19:47 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0011_classes_assignments'), + ] + + operations = [ + migrations.RemoveField( + model_name='student', + name='assignments', + ), + ] diff --git a/Website/api/migrations/0013_auto_20200606_2004.py b/Website/api/migrations/0013_auto_20200606_2004.py new file mode 100644 index 0000000..42c91fa --- /dev/null +++ b/Website/api/migrations/0013_auto_20200606_2004.py @@ -0,0 +1,27 @@ +# Generated by Django 3.0.7 on 2020-06-06 20:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0012_remove_student_assignments'), + ] + + operations = [ + migrations.RemoveField( + model_name='classes', + name='assignments', + ), + migrations.RemoveField( + model_name='teacher', + name='students', + ), + migrations.AddField( + model_name='assignment', + name='classes', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), + ), + ] diff --git a/Website/api/migrations/0014_auto_20200606_2005.py b/Website/api/migrations/0014_auto_20200606_2005.py new file mode 100644 index 0000000..c292e87 --- /dev/null +++ b/Website/api/migrations/0014_auto_20200606_2005.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.7 on 2020-06-06 20:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0013_auto_20200606_2004'), + ] + + operations = [ + migrations.RemoveField( + model_name='student', + name='classes', + ), + migrations.RemoveField( + model_name='teacher', + name='classes', + ), + migrations.AddField( + model_name='classes', + name='students', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), + ), + migrations.AddField( + model_name='classes', + name='teachers', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), + ), + ] diff --git a/Website/api/migrations/0015_auto_20200606_2023.py b/Website/api/migrations/0015_auto_20200606_2023.py new file mode 100644 index 0000000..4d3c59c --- /dev/null +++ b/Website/api/migrations/0015_auto_20200606_2023.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.7 on 2020-06-06 20:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0014_auto_20200606_2005'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='classes', + ), + migrations.RemoveField( + model_name='classes', + name='teachers', + ), + migrations.AddField( + model_name='assignment', + name='students', + field=models.ManyToManyField(default='', through='api.Classes', to='api.Student'), + ), + migrations.AddField( + model_name='classes', + name='assignments', + field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), + ), + ] diff --git a/Website/api/migrations/0016_classes_teachers.py b/Website/api/migrations/0016_classes_teachers.py new file mode 100644 index 0000000..cf81601 --- /dev/null +++ b/Website/api/migrations/0016_classes_teachers.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-06 20:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0015_auto_20200606_2023'), + ] + + operations = [ + migrations.AddField( + model_name='classes', + name='teachers', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), + ), + ] diff --git a/Website/api/migrations/0017_auto_20200606_2101.py b/Website/api/migrations/0017_auto_20200606_2101.py new file mode 100644 index 0000000..eb4c1d6 --- /dev/null +++ b/Website/api/migrations/0017_auto_20200606_2101.py @@ -0,0 +1,35 @@ +# Generated by Django 3.0.7 on 2020-06-06 21:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0016_classes_teachers'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='students', + ), + migrations.RemoveField( + model_name='classes', + name='assignments', + ), + migrations.AddField( + model_name='classes', + name='assignments', + field=models.ManyToManyField(default='', to='api.Assignment'), + ), + migrations.RemoveField( + model_name='classes', + name='students', + ), + migrations.AddField( + model_name='classes', + name='students', + field=models.ManyToManyField(null=True, to='api.Student'), + ), + ] diff --git a/Website/api/migrations/0018_auto_20200606_2107.py b/Website/api/migrations/0018_auto_20200606_2107.py new file mode 100644 index 0000000..e98cde3 --- /dev/null +++ b/Website/api/migrations/0018_auto_20200606_2107.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-06 21:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0017_auto_20200606_2101'), + ] + + operations = [ + migrations.AlterField( + model_name='classes', + name='students', + field=models.ManyToManyField(default='', to='api.Student'), + ), + ] diff --git a/Website/api/migrations/0019_auto_20200606_2126.py b/Website/api/migrations/0019_auto_20200606_2126.py new file mode 100644 index 0000000..8348e92 --- /dev/null +++ b/Website/api/migrations/0019_auto_20200606_2126.py @@ -0,0 +1,31 @@ +# Generated by Django 3.0.7 on 2020-06-06 21:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0018_auto_20200606_2107'), + ] + + operations = [ + migrations.RemoveField( + model_name='classes', + name='students', + ), + migrations.RemoveField( + model_name='classes', + name='teachers', + ), + migrations.AddField( + model_name='student', + name='classes', + field=models.ManyToManyField(default='', to='api.Classes'), + ), + migrations.AddField( + model_name='teacher', + name='classes', + field=models.ManyToManyField(default='', to='api.Classes'), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index 71e4135..e49af7f 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -1,36 +1,33 @@ from django.db import models +class Assignment(models.Model): + name=models.CharField(max_length=100) + due_date=models.DateTimeField() + def __str__(self): + return '%s' % (self.name) + +class Classes(models.Model): + name = models.CharField(max_length=100) + assignments = models.ManyToManyField(Assignment, default="") + def save(self, *args, **kwargs): + return super(Classes, self).save(*args, **kwargs) + +class Teacher(models.Model): + created = models.DateTimeField(auto_now_add=True) + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + classes = models.ManyToManyField(Classes, default="") + class Student(models.Model): - url = models.URLField() created = models.DateTimeField(auto_now_add=True) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) student_id = models.IntegerField(primary_key=True) webmail = models.EmailField(blank=True) grade = models.IntegerField() - classes = models.ForeignKey('Classes', on_delete=models.CASCADE,blank=True) - -class Teacher(models.Model): - url = models.URLField() - created = models.DateTimeField(auto_now_add=True) - first_name = models.CharField(max_length=100) - last_name = models.CharField(max_length=100) - #student_id = models.IntegerField(primary_key=True) - -class Classes(models.Model): - url = models.URLField() - name = models.CharField(max_length=100) - teachers = models.ForeignKey('Teacher', on_delete=models.CASCADE,null=True) - + classes = models.ManyToManyField(Classes, default="") def save(self, *args, **kwargs): - return super(Classes, self).save(*args, **kwargs) - -class Assignment(models.Model): - url = models.URLField() - name=models.CharField(max_length=100) - due_date=models.DateTimeField() - - def __str__(self): - return '%d' % (self.name) + return super(Student, self).save(*args, **kwargs) + diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 1c0fa80..e6a3733 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -7,26 +7,22 @@ class AssignmentSerializer(serializers.HyperlinkedModelSerializer): model = Assignment fields = ['name', 'due_date', 'url'] -class StudentSerializer(serializers.HyperlinkedModelSerializer): - assignments = AssignmentSerializer(many=True, read_only=True) - class Meta: - model = Student - fields = ['url', 'first_name', 'last_name', 'assignments'] - class ClassesSerializer(serializers.HyperlinkedModelSerializer): assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) - students = StudentSerializer(many=True, read_only=True, allow_null=True) class Meta: model = Classes - fields = ['url', 'name', 'students', 'assignments'] - - def create(self, validated_data): - return Classes.objects.create(**validated_data) + fields = ['url', 'name','assignments'] +class StudentSerializer(serializers.HyperlinkedModelSerializer): + classes = ClassesSerializer(many=True, read_only=True,allow_null=True) + class Meta: + model = Student + fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes'] class TeacherSerializer(serializers.ModelSerializer): - classes = ClassesSerializer(many=True, read_only=True) + classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Teacher fields = ['url', 'first_name', 'last_name', 'classes'] + diff --git a/Website/skoolsite/urls.py b/Website/skoolsite/urls.py index cb665d5..0ca2d12 100644 --- a/Website/skoolsite/urls.py +++ b/Website/skoolsite/urls.py @@ -1,6 +1,7 @@ from django.urls import include, path from rest_framework import routers from api import views +from django.contrib import admin router = routers.DefaultRouter() router.register(r'students', views.StudentViewSet) @@ -12,5 +13,7 @@ router.register(r'classes', views.ClassesViewSet) # Additionally, we include login URLs for the browsable API. urlpatterns = [ path('', include(router.urls)), - path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), + path('admin/', admin.site.urls), + ] \ No newline at end of file From 77dcf5a1759568e6edec4a79746cd1cc13bae6e9 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sat, 6 Jun 2020 23:07:58 -0400 Subject: [PATCH 06/22] requests --- Website/api/auth.py | 0 Website/api/serializers.py | 3 +- Website/api/views.py | 8 ++-- Website/skoolsite/urls.py | 5 ++- Website/templates/base.html | 3 ++ .../templates/oauth2_provider/authorize.html | 0 .../templates/oauth2_provider/logged_out.html | 6 +++ Website/templates/oauth2_provider/login.html | 37 +++++++++++++++++++ requirements.txt | 8 ++++ 9 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 Website/api/auth.py create mode 100644 Website/templates/base.html create mode 100644 Website/templates/oauth2_provider/authorize.html create mode 100644 Website/templates/oauth2_provider/logged_out.html create mode 100644 Website/templates/oauth2_provider/login.html diff --git a/Website/api/auth.py b/Website/api/auth.py new file mode 100644 index 0000000..e69de29 diff --git a/Website/api/serializers.py b/Website/api/serializers.py index e6a3733..26719ad 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -1,8 +1,9 @@ from django.contrib.auth.models import User, Group from .models import Student, Teacher, Classes, Assignment -from rest_framework import serializers +from rest_framework import serializers, permissions class AssignmentSerializer(serializers.HyperlinkedModelSerializer): + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] class Meta: model = Assignment fields = ['name', 'due_date', 'url'] diff --git a/Website/api/views.py b/Website/api/views.py index adb1030..c5f7b70 100644 --- a/Website/api/views.py +++ b/Website/api/views.py @@ -1,8 +1,6 @@ from .models import Student, Teacher, Classes, Assignment from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer -from rest_framework import generics, viewsets - - +from rest_framework import generics, viewsets, permissions class StudentViewSet(viewsets.ModelViewSet): """ @@ -10,6 +8,7 @@ class StudentViewSet(viewsets.ModelViewSet): """ queryset = Student.objects.all() serializer_class = StudentSerializer + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] class TeacherViewSet(viewsets.ModelViewSet): @@ -30,5 +29,6 @@ class AssignmentViewSet(viewsets.ModelViewSet): """ API endpoint that allows users to be viewed or edited. """ + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] queryset = Assignment.objects.all() - serializer_class = AssignmentSerializer + serializer_class = AssignmentSerializer \ No newline at end of file diff --git a/Website/skoolsite/urls.py b/Website/skoolsite/urls.py index 0ca2d12..8d2da08 100644 --- a/Website/skoolsite/urls.py +++ b/Website/skoolsite/urls.py @@ -1,7 +1,8 @@ -from django.urls import include, path +from django.urls import path from rest_framework import routers from api import views from django.contrib import admin +from django.conf.urls import include router = routers.DefaultRouter() router.register(r'students', views.StudentViewSet) @@ -13,7 +14,7 @@ router.register(r'classes', views.ClassesViewSet) # Additionally, we include login URLs for the browsable API. urlpatterns = [ path('', include(router.urls)), - path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), + path('api-auth/', include('rest_framework.urls')), path('admin/', admin.site.urls), ] \ No newline at end of file diff --git a/Website/templates/base.html b/Website/templates/base.html new file mode 100644 index 0000000..664dcf4 --- /dev/null +++ b/Website/templates/base.html @@ -0,0 +1,3 @@ + +{% block page_content %} +{% endblock %} diff --git a/Website/templates/oauth2_provider/authorize.html b/Website/templates/oauth2_provider/authorize.html new file mode 100644 index 0000000..e69de29 diff --git a/Website/templates/oauth2_provider/logged_out.html b/Website/templates/oauth2_provider/logged_out.html new file mode 100644 index 0000000..52cdfa1 --- /dev/null +++ b/Website/templates/oauth2_provider/logged_out.html @@ -0,0 +1,6 @@ +{% extends "base.html" %} + +{% block content %} +

Logged out!

+ Click here to login again. +{% endblock %} \ No newline at end of file diff --git a/Website/templates/oauth2_provider/login.html b/Website/templates/oauth2_provider/login.html new file mode 100644 index 0000000..5018145 --- /dev/null +++ b/Website/templates/oauth2_provider/login.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block page_content %} + + {% if form.errors %} +

Your username and password didn't match. Please try again.

+ {% endif %} + + {% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} + {% endif %} + +
+ {% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + +
+ + {# Assumes you setup the password_reset view in your URLconf #} +

Lost password?

+ +{% endblock %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f7c0a91..fbc7e54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,19 @@ asgiref==3.2.7 +certifi==2020.4.5.1 +chardet==3.0.4 click==7.1.2 Django==3.0.7 +django-cors-middleware==1.5.0 +django-oauth-toolkit==1.3.2 +djangorestframework==3.11.0 +idna==2.9 +oauthlib==3.1.0 prompt-toolkit==1.0.14 Pygments==2.6.1 PyInquirer==1.0.3 pytz==2020.1 regex==2020.5.14 +requests==2.23.0 selenium==3.141.0 six==1.15.0 sqlparse==0.3.1 From ce0e143f6ed0ad9fdcbc101ae28ed351404305af Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Sat, 6 Jun 2020 19:18:02 -0400 Subject: [PATCH 07/22] updated requirements --- CLI/requirements.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CLI/requirements.txt diff --git a/CLI/requirements.txt b/CLI/requirements.txt new file mode 100644 index 0000000..fbc7e54 --- /dev/null +++ b/CLI/requirements.txt @@ -0,0 +1,21 @@ +asgiref==3.2.7 +certifi==2020.4.5.1 +chardet==3.0.4 +click==7.1.2 +Django==3.0.7 +django-cors-middleware==1.5.0 +django-oauth-toolkit==1.3.2 +djangorestframework==3.11.0 +idna==2.9 +oauthlib==3.1.0 +prompt-toolkit==1.0.14 +Pygments==2.6.1 +PyInquirer==1.0.3 +pytz==2020.1 +regex==2020.5.14 +requests==2.23.0 +selenium==3.141.0 +six==1.15.0 +sqlparse==0.3.1 +urllib3==1.25.9 +wcwidth==0.2.3 From 4fba0221cea6f12b649b0588df68fb0af35ed3bb Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Sat, 6 Jun 2020 19:29:32 -0400 Subject: [PATCH 08/22] added django --- .gitignore | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/.gitignore b/.gitignore index 5a28dbb..305e594 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,120 @@ dmypy.json # Mac lmao .DS_Store + +# Django # +*.log +*.pot +*.pyc +__pycache__ +db.sqlite3 +media + +# Backup files # +*.bak + +# If you are using PyCharm # +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/gradle.xml +.idea/**/libraries +*.iws /out/ + +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history From e2997a66520794274a649564ec2195c5cc283fb5 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sun, 7 Jun 2020 01:11:33 -0400 Subject: [PATCH 09/22] permissions --- Website/api/views.py | 9 +++++++-- Website/skoolsite/settings.py | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Website/api/views.py b/Website/api/views.py index c5f7b70..f02ade8 100644 --- a/Website/api/views.py +++ b/Website/api/views.py @@ -17,6 +17,8 @@ class TeacherViewSet(viewsets.ModelViewSet): """ queryset = Teacher.objects.all() serializer_class = TeacherSerializer + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + class ClassesViewSet(viewsets.ModelViewSet): """ @@ -24,11 +26,14 @@ class ClassesViewSet(viewsets.ModelViewSet): """ queryset = Classes.objects.all() serializer_class = ClassesSerializer + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + class AssignmentViewSet(viewsets.ModelViewSet): """ API endpoint that allows users to be viewed or edited. """ - permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + permissions_classes = [permissions.IsAdminUser] queryset = Assignment.objects.all() - serializer_class = AssignmentSerializer \ No newline at end of file + serializer_class = AssignmentSerializer + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] diff --git a/Website/skoolsite/settings.py b/Website/skoolsite/settings.py index 82549f8..b5bda98 100644 --- a/Website/skoolsite/settings.py +++ b/Website/skoolsite/settings.py @@ -44,7 +44,10 @@ INSTALLED_APPS = [ REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', - 'PAGE_SIZE': 10 + 'PAGE_SIZE': 10, + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.IsAuthenticated', + ] } MIDDLEWARE = [ From a12185aa2ea3f81e7673b9967b0aff9635b7c064 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sun, 7 Jun 2020 10:44:57 -0400 Subject: [PATCH 10/22] git methods --- CLI/git.py | 38 ----- CLI/s-git.py | 95 +++++++++++++ CLI/t-git.py | 67 +++++++++ Website/api/maker.py | 132 ++++++++---------- Website/api/migrations/0001_initial.py | 51 ++++--- .../api/migrations/0002_auto_20200606_1810.py | 24 ---- .../api/migrations/0002_auto_20200607_0751.py | 18 +++ .../api/migrations/0003_auto_20200606_1817.py | 26 ---- .../api/migrations/0004_student_webmail.py | 18 --- .../api/migrations/0005_auto_20200606_1822.py | 19 --- .../api/migrations/0006_auto_20200606_1824.py | 24 ---- .../api/migrations/0007_auto_20200606_1825.py | 21 --- .../api/migrations/0008_auto_20200606_1839.py | 19 --- .../api/migrations/0009_auto_20200606_1859.py | 28 ---- .../api/migrations/0010_auto_20200606_1910.py | 40 ------ .../migrations/0011_classes_assignments.py | 19 --- .../0012_remove_student_assignments.py | 17 --- .../api/migrations/0013_auto_20200606_2004.py | 27 ---- .../api/migrations/0014_auto_20200606_2005.py | 32 ----- .../api/migrations/0015_auto_20200606_2023.py | 32 ----- .../api/migrations/0016_classes_teachers.py | 19 --- .../api/migrations/0017_auto_20200606_2101.py | 35 ----- .../api/migrations/0018_auto_20200606_2107.py | 18 --- .../api/migrations/0019_auto_20200606_2126.py | 31 ---- Website/api/models.py | 12 +- Website/api/serializers.py | 15 +- Website/api/views.py | 13 +- Website/skoolsite/urls.py | 2 + 28 files changed, 304 insertions(+), 588 deletions(-) delete mode 100644 CLI/git.py create mode 100644 CLI/s-git.py create mode 100644 CLI/t-git.py delete mode 100644 Website/api/migrations/0002_auto_20200606_1810.py create mode 100644 Website/api/migrations/0002_auto_20200607_0751.py delete mode 100644 Website/api/migrations/0003_auto_20200606_1817.py delete mode 100644 Website/api/migrations/0004_student_webmail.py delete mode 100644 Website/api/migrations/0005_auto_20200606_1822.py delete mode 100644 Website/api/migrations/0006_auto_20200606_1824.py delete mode 100644 Website/api/migrations/0007_auto_20200606_1825.py delete mode 100644 Website/api/migrations/0008_auto_20200606_1839.py delete mode 100644 Website/api/migrations/0009_auto_20200606_1859.py delete mode 100644 Website/api/migrations/0010_auto_20200606_1910.py delete mode 100644 Website/api/migrations/0011_classes_assignments.py delete mode 100644 Website/api/migrations/0012_remove_student_assignments.py delete mode 100644 Website/api/migrations/0013_auto_20200606_2004.py delete mode 100644 Website/api/migrations/0014_auto_20200606_2005.py delete mode 100644 Website/api/migrations/0015_auto_20200606_2023.py delete mode 100644 Website/api/migrations/0016_classes_teachers.py delete mode 100644 Website/api/migrations/0017_auto_20200606_2101.py delete mode 100644 Website/api/migrations/0018_auto_20200606_2107.py delete mode 100644 Website/api/migrations/0019_auto_20200606_2126.py diff --git a/CLI/git.py b/CLI/git.py deleted file mode 100644 index b6c45fd..0000000 --- a/CLI/git.py +++ /dev/null @@ -1,38 +0,0 @@ -import subprocess -import os - -#students -def initialize(repo, subject): - process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - output = process.communicate() - dirname = repo[repo.rindex('/')+1:repo.index(".git")] - os.rename(dirname, subject) - #print(output) - -#Teachers - -#make student repo by student id -def addStudent(stid, teacher): - os.mkdir(stid) - os.chdir(os.getcwd() + "/" + stid) - process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() - process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() - process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() - -def addStudents(filename): - print(filename) - -def addAsignment(name): - print(name) - -def updateAssignment(name): - print(name) - -def comment(filename, text): - print(text) - - -initialize("https://github.com/therealraffi/1579460.git", "Math1") diff --git a/CLI/s-git.py b/CLI/s-git.py new file mode 100644 index 0000000..34c7ef1 --- /dev/null +++ b/CLI/s-git.py @@ -0,0 +1,95 @@ +import subprocess +import os +import requests + + +#git clone student directory ==> /classes/assignments +def initStudent(ion_user): + #check if git has already been initialized + if(os.path.exists(str(ion_user) +"/" + ".git")): + print("Already synced to: " + str(ion_user)) + return + + #get student repo from API + URL = "http://127.0.0.1:8000/students/" + ion_user + "/" + r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) + if(r.status_code == 200): + data = r.json() + repo = data['repo'] + classes = data['classes'] + print(data) + #git clone repo + process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + + # make classes directory + for c in classes: + cpath = str(ion_user) + "/" + c['name'] + if(os.path.exists(cpath)): + print(cpath + " already exists...") + else: + os.mkdir(str(ion_user) + "/" + c['name']) + + #make assignments directory + for a in c['assignments']: + path = str(ion_user) + "/" + c['name'] + "/" + a['name'] + print(path) + if(os.path.exists("/" +path)): + print(path + " already exists...") + else: + os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name']) + + #push to remote repo + os.chdir(ion_user) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + + elif(r.status_code == 404): + print("Make new account!") + elif(r.status_code == 403): + print("Invalid username/password") + else: + print(r.status_code) + +#Teachers + +#make student repo by student id +def addStudent(stid, teacher): + os.mkdir(stid) + os.chdir(os.getcwd() + "/" + stid) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + +def addStudents(filename): + print(filename) + +def addAsignment(name): + print(name) + +def updateAssignment(name): + print(name) + +def comment(filename, text): + print(text) + +initStudent("2022rkhondak") + +os.chdir("2022rkhondak") +process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) +process.wait() +process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) +process.wait() +process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) +process.wait() +process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) +process.wait() \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py new file mode 100644 index 0000000..1da2d06 --- /dev/null +++ b/CLI/t-git.py @@ -0,0 +1,67 @@ +import subprocess +import os +import requests + + +#git clone student directory ==> /classes/assignments +def initTeacher(student_id): + #check if git has already been initialized + if(os.path.exists(str(student_id) +"/" + ".git")): + print("Already synced to: " + str(student_id)) + return + + #get student repo from API + URL = "http://127.0.0.1:8000/students/" + str(student_id) + "/" + r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) + data = r.json() + repo = data['repo'] + classes = data['classes'] + print(classes) + #git clone repo + process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + + #make classes directory + for c in classes: + cpath = str(student_id) + "/" + c['name'] + if(os.path.exists(cpath)): + print(cpath + " already exists...") + else: + os.mkdir(str(student_id) + "/" + c['name']) + + #make assignments directory + for a in c['assignments']: + path = str(student_id) + "/" + c['name'] + "/" + a['name'] + print(path) + if(os.path.exists("/" +path)): + print(path + " already exists...") + else: + os.mkdir(str(student_id) + "/" + c['name'] + "/" + a['name']) + +#Teachers + +#make student repo by student id +def addStudent(stid, teacher): + os.mkdir(stid) + os.chdir(os.getcwd() + "/" + stid) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.communicate() + +def addStudents(filename): + print(filename) + +def addAsignment(name): + print(name) + +def updateAssignment(name): + print(name) + +def comment(filename, text): + print(text) + + +initStudent(1579460) \ No newline at end of file diff --git a/Website/api/maker.py b/Website/api/maker.py index eaea2c1..f960dba 100644 --- a/Website/api/maker.py +++ b/Website/api/maker.py @@ -1,38 +1,63 @@ -from api.models import Assignment, Student, Classes, Teacher -from datetime import datetime +from api.models import Assignment, Student, Classes, Teacher, DefFiles +from datetime import datetime -#students -raffu = Student( - first_name = "Raffu", - last_name = "Khondaker", - student_id = 1579460, - webmail = "2022rkhondak@tjhsst.edu", - grade = 10, +f1 = DefFiles( + name="instructions.txt" ) -raffu.save() - -#teachers -ng = Teacher( - first_name = "Kim", - last_name = "Ng", +f1.save() +f2 = DefFiles( + name="instructions.txt" ) - -ng.save() - -chao = Teacher( - first_name = "Susie", - last_name = "Lebryk-Chao", +f2.save() +f3 = DefFiles( + name="sample.txt" ) +f3.save() +f4 = DefFiles( + name="rubric.txt" +) +f4.save() -chao.save() +a1 = Assignment.objects.get(pk=1) +a1.files.add(f1) +a1.save() +a2 = Assignment.objects.get(pk=2) +a2.files.add(f2) +a2.save() +a3 = Assignment.objects.get(pk=3) +a3.files.add(f3) +a3.files.add(f4) +a3.save() + +#################################### + +from api.models import Assignment, Student, Classes, Teacher, DefFiles +from datetime import datetime + +f1 = DefFiles( + name="instructions.txt" +) +f1.save() +f2 = DefFiles( + name="instructions.txt" +) +f2.save() +f3 = DefFiles( + name="sample.txt" +) +f3.save() +f4 = DefFiles( + name="rubric.txt" +) +f4.save() -#Assignments A1 = Assignment( name='Week1_HW', due_date=datetime.now(), - ) A1.save() +A1.files.add(f1) +A1.save() A2 = Assignment( name='Week2_HW', @@ -40,55 +65,16 @@ A2 = Assignment( ) A2.save() +A2.files.add(f2) +A2.save() A3 = Assignment( name='Journal1', due_date=datetime.now(), ) A3.save() - -#classes -C1 = Classes( - name='Math5', - -) -C1.save() - -C2 = Classes( - name='English', -) -C2.save() - -C2.teachers = chao -C2.students.add(raffu) -C2.save() - -C1.teachers = ng -C1.students.add(raffu) -C1.save() - -################################################################################################################ -from api.models import Assignment, Student, Classes, Teacher -from datetime import datetime - -A1 = Assignment( - name='Week1_HW', - due_date=datetime.now(), - -) -A1.save() - -A2 = Assignment( - name='Week2_HW', - due_date=datetime.now(), - -) -A2.save() - -A3 = Assignment( - name='Journal1', - due_date=datetime.now(), -) +A3.files.add(f3) +A3.files.add(f4) A3.save() #classes @@ -113,8 +99,10 @@ raffu = Student( first_name = "Raffu", last_name = "Khondaker", student_id = 1579460, + ion_user="2022rkhondak", webmail = "2022rkhondak@tjhsst.edu", grade = 10, + repo="https://github.com/therealraffi/2022rkhondak.git", ) raffu.save() raffu.classes.add(math) @@ -123,16 +111,18 @@ raffu.save() #teachers ng = Teacher( - first_name = "Kim", - last_name = "Ng", + first_name = "Errin", + last_name = "Harris", + ion_user="eharris1" ) ng.save() ng.classes.add(math) ng.save() chao = Teacher( - first_name = "Susie", - last_name = "Lebryk-Chao", + first_name = "Abagail", + last_name = "Bailey", + ion_user="AKBailey" ) chao.save() chao.classes.add(english) diff --git a/Website/api/migrations/0001_initial.py b/Website/api/migrations/0001_initial.py index dff6759..476a6f2 100644 --- a/Website/api/migrations/0001_initial.py +++ b/Website/api/migrations/0001_initial.py @@ -1,7 +1,6 @@ -# Generated by Django 3.0.7 on 2020-06-06 17:44 +# Generated by Django 3.0.7 on 2020-06-07 07:45 from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): @@ -12,50 +11,58 @@ class Migration(migrations.Migration): ] operations = [ + 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)), + ('due_date', models.DateTimeField()), + ], + ), migrations.CreateModel( name='Classes', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('url', models.URLField()), + ('name', models.CharField(max_length=100)), + ('assignments', models.ManyToManyField(default='', to='api.Assignment')), + ], + ), + migrations.CreateModel( + name='DefFiles', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=100)), ], ), migrations.CreateModel( name='Teacher', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('url', models.URLField()), ('created', models.DateTimeField(auto_now_add=True)), ('first_name', models.CharField(max_length=100)), ('last_name', models.CharField(max_length=100)), + ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), + ('git', models.URLField(default='')), + ('classes', models.ManyToManyField(default='', to='api.Classes')), ], ), migrations.CreateModel( name='Student', fields=[ - ('url', models.URLField()), ('created', models.DateTimeField(auto_now_add=True)), ('first_name', models.CharField(max_length=100)), ('last_name', models.CharField(max_length=100)), - ('student_id', models.IntegerField(primary_key=True, serialize=False)), + ('student_id', models.IntegerField()), + ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), + ('webmail', models.EmailField(blank=True, max_length=254)), ('grade', models.IntegerField()), - ('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')), + ('git', models.URLField()), + ('repo', models.URLField(default='')), + ('classes', models.ManyToManyField(default='', to='api.Classes')), ], ), migrations.AddField( - model_name='classes', - name='teachers', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), - ), - migrations.CreateModel( - name='Assignment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('url', models.URLField()), - ('name', models.CharField(max_length=100)), - ('due_date', models.DateTimeField()), - ('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')), - ('students', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Student')), - ], + model_name='assignment', + name='files', + field=models.ManyToManyField(default='instructions.txt', to='api.DefFiles'), ), ] diff --git a/Website/api/migrations/0002_auto_20200606_1810.py b/Website/api/migrations/0002_auto_20200606_1810.py deleted file mode 100644 index c11d41a..0000000 --- a/Website/api/migrations/0002_auto_20200606_1810.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:10 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='assignment', - name='classes', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - migrations.AlterField( - model_name='assignment', - name='students', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), - ), - ] diff --git a/Website/api/migrations/0002_auto_20200607_0751.py b/Website/api/migrations/0002_auto_20200607_0751.py new file mode 100644 index 0000000..d78e3e1 --- /dev/null +++ b/Website/api/migrations/0002_auto_20200607_0751.py @@ -0,0 +1,18 @@ +# 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'), + ), + ] diff --git a/Website/api/migrations/0003_auto_20200606_1817.py b/Website/api/migrations/0003_auto_20200606_1817.py deleted file mode 100644 index 5296f69..0000000 --- a/Website/api/migrations/0003_auto_20200606_1817.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:17 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0002_auto_20200606_1810'), - ] - - operations = [ - migrations.AlterField( - model_name='assignment', - name='classes', - field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - preserve_default=False, - ), - migrations.AlterField( - model_name='assignment', - name='students', - field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Student'), - preserve_default=False, - ), - ] diff --git a/Website/api/migrations/0004_student_webmail.py b/Website/api/migrations/0004_student_webmail.py deleted file mode 100644 index 3401b2a..0000000 --- a/Website/api/migrations/0004_student_webmail.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:22 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0003_auto_20200606_1817'), - ] - - operations = [ - migrations.AddField( - model_name='student', - name='webmail', - field=models.EmailField(blank=True, max_length=254), - ), - ] diff --git a/Website/api/migrations/0005_auto_20200606_1822.py b/Website/api/migrations/0005_auto_20200606_1822.py deleted file mode 100644 index c5f3384..0000000 --- a/Website/api/migrations/0005_auto_20200606_1822.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:22 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0004_student_webmail'), - ] - - operations = [ - migrations.AlterField( - model_name='student', - name='classes', - field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - ] diff --git a/Website/api/migrations/0006_auto_20200606_1824.py b/Website/api/migrations/0006_auto_20200606_1824.py deleted file mode 100644 index 048263b..0000000 --- a/Website/api/migrations/0006_auto_20200606_1824.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:24 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0005_auto_20200606_1822'), - ] - - operations = [ - migrations.AlterField( - model_name='assignment', - name='classes', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - migrations.AlterField( - model_name='assignment', - name='students', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), - ), - ] diff --git a/Website/api/migrations/0007_auto_20200606_1825.py b/Website/api/migrations/0007_auto_20200606_1825.py deleted file mode 100644 index 595ac9a..0000000 --- a/Website/api/migrations/0007_auto_20200606_1825.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0006_auto_20200606_1824'), - ] - - operations = [ - migrations.RemoveField( - model_name='assignment', - name='classes', - ), - migrations.RemoveField( - model_name='assignment', - name='students', - ), - ] diff --git a/Website/api/migrations/0008_auto_20200606_1839.py b/Website/api/migrations/0008_auto_20200606_1839.py deleted file mode 100644 index 89e960b..0000000 --- a/Website/api/migrations/0008_auto_20200606_1839.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:39 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0007_auto_20200606_1825'), - ] - - operations = [ - migrations.AlterField( - model_name='classes', - name='teachers', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), - ), - ] diff --git a/Website/api/migrations/0009_auto_20200606_1859.py b/Website/api/migrations/0009_auto_20200606_1859.py deleted file mode 100644 index dd679fd..0000000 --- a/Website/api/migrations/0009_auto_20200606_1859.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 18:59 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0008_auto_20200606_1839'), - ] - - operations = [ - migrations.RemoveField( - model_name='classes', - name='teachers', - ), - migrations.AddField( - model_name='student', - name='assignments', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), - ), - migrations.AlterField( - model_name='student', - name='classes', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - ] diff --git a/Website/api/migrations/0010_auto_20200606_1910.py b/Website/api/migrations/0010_auto_20200606_1910.py deleted file mode 100644 index e437c74..0000000 --- a/Website/api/migrations/0010_auto_20200606_1910.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 19:10 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0009_auto_20200606_1859'), - ] - - operations = [ - migrations.RemoveField( - model_name='assignment', - name='url', - ), - migrations.RemoveField( - model_name='classes', - name='url', - ), - migrations.RemoveField( - model_name='student', - name='url', - ), - migrations.RemoveField( - model_name='teacher', - name='url', - ), - migrations.AddField( - model_name='teacher', - name='classes', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - migrations.AddField( - model_name='teacher', - name='students', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), - ), - ] diff --git a/Website/api/migrations/0011_classes_assignments.py b/Website/api/migrations/0011_classes_assignments.py deleted file mode 100644 index e4f45ed..0000000 --- a/Website/api/migrations/0011_classes_assignments.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 19:16 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0010_auto_20200606_1910'), - ] - - operations = [ - migrations.AddField( - model_name='classes', - name='assignments', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), - ), - ] diff --git a/Website/api/migrations/0012_remove_student_assignments.py b/Website/api/migrations/0012_remove_student_assignments.py deleted file mode 100644 index a3de13c..0000000 --- a/Website/api/migrations/0012_remove_student_assignments.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 19:47 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0011_classes_assignments'), - ] - - operations = [ - migrations.RemoveField( - model_name='student', - name='assignments', - ), - ] diff --git a/Website/api/migrations/0013_auto_20200606_2004.py b/Website/api/migrations/0013_auto_20200606_2004.py deleted file mode 100644 index 42c91fa..0000000 --- a/Website/api/migrations/0013_auto_20200606_2004.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 20:04 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0012_remove_student_assignments'), - ] - - operations = [ - migrations.RemoveField( - model_name='classes', - name='assignments', - ), - migrations.RemoveField( - model_name='teacher', - name='students', - ), - migrations.AddField( - model_name='assignment', - name='classes', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'), - ), - ] diff --git a/Website/api/migrations/0014_auto_20200606_2005.py b/Website/api/migrations/0014_auto_20200606_2005.py deleted file mode 100644 index c292e87..0000000 --- a/Website/api/migrations/0014_auto_20200606_2005.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 20:05 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0013_auto_20200606_2004'), - ] - - operations = [ - migrations.RemoveField( - model_name='student', - name='classes', - ), - migrations.RemoveField( - model_name='teacher', - name='classes', - ), - migrations.AddField( - model_name='classes', - name='students', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'), - ), - migrations.AddField( - model_name='classes', - name='teachers', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), - ), - ] diff --git a/Website/api/migrations/0015_auto_20200606_2023.py b/Website/api/migrations/0015_auto_20200606_2023.py deleted file mode 100644 index 4d3c59c..0000000 --- a/Website/api/migrations/0015_auto_20200606_2023.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 20:23 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0014_auto_20200606_2005'), - ] - - operations = [ - migrations.RemoveField( - model_name='assignment', - name='classes', - ), - migrations.RemoveField( - model_name='classes', - name='teachers', - ), - migrations.AddField( - model_name='assignment', - name='students', - field=models.ManyToManyField(default='', through='api.Classes', to='api.Student'), - ), - migrations.AddField( - model_name='classes', - name='assignments', - field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'), - ), - ] diff --git a/Website/api/migrations/0016_classes_teachers.py b/Website/api/migrations/0016_classes_teachers.py deleted file mode 100644 index cf81601..0000000 --- a/Website/api/migrations/0016_classes_teachers.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 20:24 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0015_auto_20200606_2023'), - ] - - operations = [ - migrations.AddField( - model_name='classes', - name='teachers', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'), - ), - ] diff --git a/Website/api/migrations/0017_auto_20200606_2101.py b/Website/api/migrations/0017_auto_20200606_2101.py deleted file mode 100644 index eb4c1d6..0000000 --- a/Website/api/migrations/0017_auto_20200606_2101.py +++ /dev/null @@ -1,35 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 21:01 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0016_classes_teachers'), - ] - - operations = [ - migrations.RemoveField( - model_name='assignment', - name='students', - ), - migrations.RemoveField( - model_name='classes', - name='assignments', - ), - migrations.AddField( - model_name='classes', - name='assignments', - field=models.ManyToManyField(default='', to='api.Assignment'), - ), - migrations.RemoveField( - model_name='classes', - name='students', - ), - migrations.AddField( - model_name='classes', - name='students', - field=models.ManyToManyField(null=True, to='api.Student'), - ), - ] diff --git a/Website/api/migrations/0018_auto_20200606_2107.py b/Website/api/migrations/0018_auto_20200606_2107.py deleted file mode 100644 index e98cde3..0000000 --- a/Website/api/migrations/0018_auto_20200606_2107.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 21:07 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0017_auto_20200606_2101'), - ] - - operations = [ - migrations.AlterField( - model_name='classes', - name='students', - field=models.ManyToManyField(default='', to='api.Student'), - ), - ] diff --git a/Website/api/migrations/0019_auto_20200606_2126.py b/Website/api/migrations/0019_auto_20200606_2126.py deleted file mode 100644 index 8348e92..0000000 --- a/Website/api/migrations/0019_auto_20200606_2126.py +++ /dev/null @@ -1,31 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-06 21:26 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0018_auto_20200606_2107'), - ] - - operations = [ - migrations.RemoveField( - model_name='classes', - name='students', - ), - migrations.RemoveField( - model_name='classes', - name='teachers', - ), - migrations.AddField( - model_name='student', - name='classes', - field=models.ManyToManyField(default='', to='api.Classes'), - ), - migrations.AddField( - model_name='teacher', - name='classes', - field=models.ManyToManyField(default='', to='api.Classes'), - ), - ] diff --git a/Website/api/models.py b/Website/api/models.py index e49af7f..cf31bb6 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -1,8 +1,12 @@ from django.db import models +class DefFiles(models.Model): + name=models.CharField(max_length=100) + class Assignment(models.Model): name=models.CharField(max_length=100) due_date=models.DateTimeField() + files = models.ManyToManyField(DefFiles, default="") def __str__(self): return '%s' % (self.name) @@ -17,15 +21,21 @@ class Teacher(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) classes = models.ManyToManyField(Classes, default="") + ion_user=models.CharField(primary_key=True, max_length=100) + git = models.URLField(default="") class Student(models.Model): created = models.DateTimeField(auto_now_add=True) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) - student_id = models.IntegerField(primary_key=True) + student_id = models.IntegerField() + ion_user=models.CharField(primary_key=True, max_length=100) webmail = models.EmailField(blank=True) grade = models.IntegerField() + git = models.URLField() classes = models.ManyToManyField(Classes, default="") + repo = models.URLField(default="") + def save(self, *args, **kwargs): return super(Student, self).save(*args, **kwargs) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 26719ad..46d09cc 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -1,12 +1,19 @@ from django.contrib.auth.models import User, Group -from .models import Student, Teacher, Classes, Assignment +from .models import Student, Teacher, Classes, Assignment, DefFiles from rest_framework import serializers, permissions +class DefFilesSerializer(serializers.HyperlinkedModelSerializer): + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + class Meta: + model = DefFiles + fields = ['name'] + class AssignmentSerializer(serializers.HyperlinkedModelSerializer): permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + files = DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Assignment - fields = ['name', 'due_date', 'url'] + fields = ['name', 'due_date', 'url', 'files'] class ClassesSerializer(serializers.HyperlinkedModelSerializer): assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) @@ -18,12 +25,12 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Student - fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes'] + fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes', 'git','repo','ion_user'] class TeacherSerializer(serializers.ModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Teacher - fields = ['url', 'first_name', 'last_name', 'classes'] + fields = ['url', 'first_name', 'last_name', 'classes','git','ion_user'] diff --git a/Website/api/views.py b/Website/api/views.py index f02ade8..10fe2a8 100644 --- a/Website/api/views.py +++ b/Website/api/views.py @@ -1,5 +1,5 @@ -from .models import Student, Teacher, Classes, Assignment -from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer +from .models import Student, Teacher, Classes, Assignment, DefFiles +from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, DefFilesSerializer from rest_framework import generics, viewsets, permissions class StudentViewSet(viewsets.ModelViewSet): @@ -33,7 +33,14 @@ class AssignmentViewSet(viewsets.ModelViewSet): """ API endpoint that allows users to be viewed or edited. """ - permissions_classes = [permissions.IsAdminUser] queryset = Assignment.objects.all() serializer_class = AssignmentSerializer permissions_classes = [permissions.IsAuthenticatedOrReadOnly] + +class DefFilesViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows users to be viewed or edited. + """ + queryset = DefFiles.objects.all() + serializer_class = DefFilesSerializer + permissions_classes = [permissions.IsAuthenticatedOrReadOnly] diff --git a/Website/skoolsite/urls.py b/Website/skoolsite/urls.py index 8d2da08..1c8f9f2 100644 --- a/Website/skoolsite/urls.py +++ b/Website/skoolsite/urls.py @@ -9,6 +9,8 @@ router.register(r'students', views.StudentViewSet) router.register(r'teachers', views.TeacherViewSet) router.register(r'assignments', views.AssignmentViewSet) router.register(r'classes', views.ClassesViewSet) +router.register(r'files', views.DefFilesViewSet) + # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. From c39a012fed181418b9e5104287bf021823a4f12c Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Sun, 7 Jun 2020 18:24:15 -0400 Subject: [PATCH 11/22] git updates --- CLI/run.py | 148 ------------------ CLI/s-git.py | 30 ++-- CLI/t-git.py | 74 +++++---- Website/api/maker.py | 1 - .../api/migrations/0003_auto_20200607_1519.py | 23 +++ Website/api/models.py | 1 + Website/api/serializers.py | 2 +- Website/api/views-back.py | 131 ++++++++++++++++ Website/api/views.py | 4 +- 9 files changed, 223 insertions(+), 191 deletions(-) delete mode 100644 CLI/run.py create mode 100644 Website/api/migrations/0003_auto_20200607_1519.py create mode 100644 Website/api/views-back.py diff --git a/CLI/run.py b/CLI/run.py deleted file mode 100644 index 6a51e78..0000000 --- a/CLI/run.py +++ /dev/null @@ -1,148 +0,0 @@ -from __future__ import print_function, unicode_literals -from PyInquirer import prompt, print_json -import argparse -import json -import os -import argparse - -def yesorno(question): - questions = [ - { - 'type': 'input', - 'name': 'response', - 'message': question, - }, - ] - answers = prompt(questions) - if(answers["response"] == "y"): - return True - return False - -#already ccrerrated account through website, has to login -def login(): - #enter username - #enter password - questions = [ - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s TJ Webmail', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - #reading from json of users (replace w GET to database) to check if user is registered - with open('users.json', 'r') as json_file: - data = json.load(json_file) - for i in range(len(data)): - if user["webmail"] == data[i]["webmail"]: - if(user["password"] == data[i]["password"]): - print("Logged in!") - return data[i] - else: - print("Password incorrect. Try again.") - return None - print("User not found. Please Try again") - return None - -#did not create account through website, has to signup/login -def update(): - questions = [ - { - 'type': 'input', - 'name': 'first-name', - 'message': 'What\'s your first name', - }, - { - 'type': 'input', - 'name': 'last-name', - 'message': 'What\'s your last name?', - }, - { - 'type': 'list', - 'name': 'grade', - 'message': 'Grade?', - 'choices':["9","10","11","12"] - }, - { - 'type': 'input', - 'name': 'webmail', - 'message': 'What\'s your TJ Webmail?', - }, - { - 'type': 'password', - 'name': 'password', - 'message': 'Password?', - }, - ] - user = prompt(questions) - for i in user: - if user[i] == "": - print("Some forms were left blank. Try again.\n") - return None - if len(user["password"]) < 6: - print("Password is too short. Try again.") - return None - if (("@tjhsst.edu" in user['webmail']) == False): - print("Webmail entered was not a @tjhhsst.edu. Try again.") - return None - - #post user to json, replace w POST to db - user["classes"] = [] - with open('users.json', 'r') as json_file: - data = json.load(json_file) - data.append(user) - open("users.json", "w").write(str(json.dumps(data))) - return user - -def relogin(): - questions = [ - { - 'type': 'list', - 'name': 'choice', - 'message': '', - 'choices':["Continue as current user","Login into new user","Sign up into new account"] - }, - ] - answer = prompt(questions) - - -def setup(user): - #Read classes/assignenments and setup directory: - #SkoolOS/Math/Week1 - for c in user["classes"]: - os.makedirs("../" + c) - for a in user["classes"][c]: - os.makedirs("../" + c + "/" + a) - -def start(): - if(os.path.exists(".login.txt") == False): - b = yesorno("Do you have a SkoolOS account?(y/N)") - if(b): - user = login() - if(user != None): - setup(user) - open(".login.txt", "w").write(str(user)) - else: - user = update() - if(user != None): - open(".login.txt").write(str(user)) - -my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS control your system', epilog="Try again") -my_parser.add_argument('--init', action="store_true") #returns true if run argument -args = my_parser.parse_args() - -update() -outputs = vars(args) -if(outputs['init']): - start() - - - - - - diff --git a/CLI/s-git.py b/CLI/s-git.py index 34c7ef1..1203091 100644 --- a/CLI/s-git.py +++ b/CLI/s-git.py @@ -1,7 +1,8 @@ import subprocess import os import requests - +import pprint +import json #git clone student directory ==> /classes/assignments def initStudent(ion_user): @@ -57,6 +58,8 @@ def initStudent(ion_user): else: print(r.status_code) + + #Teachers #make student repo by student id @@ -82,14 +85,17 @@ def updateAssignment(name): def comment(filename, text): print(text) -initStudent("2022rkhondak") - -os.chdir("2022rkhondak") -process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) -process.wait() -process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) -process.wait() -process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) -process.wait() -process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) -process.wait() \ No newline at end of file +#initStudent("2022rkhondak") +ion_user = "2022rkhondak" +headers = {'Content-type': 'application/json'} +data = {'first_name': 'Jeff', + 'git': 'https://github.com/', + 'grade': 10, + 'ion_user': '2022jlol1', + 'last_name': 'lol.', + 'student_id': 11111 + } +data = json.dumps(data) +URL = "http://127.0.0.1:8000/students/" + ion_user + "/" +r = requests.put(url = URL, data= data, headers=headers ,auth=('raffukhondaker','hackgroup1')) +pprint.pprint(r.json()) \ No newline at end of file diff --git a/CLI/t-git.py b/CLI/t-git.py index 1da2d06..1241390 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -4,41 +4,60 @@ import requests #git clone student directory ==> /classes/assignments -def initTeacher(student_id): +def initTeacher(ion_user): #check if git has already been initialized - if(os.path.exists(str(student_id) +"/" + ".git")): - print("Already synced to: " + str(student_id)) + if(os.path.exists(str(ion_user) +"/" + ".git")): + print("Already synced to: " + str(ion_user)) return #get student repo from API - URL = "http://127.0.0.1:8000/students/" + str(student_id) + "/" + URL = "http://127.0.0.1:8000/students/" + ion_user + "/" r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) - data = r.json() - repo = data['repo'] - classes = data['classes'] - print(classes) - #git clone repo - process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() + if(r.status_code == 200): + data = r.json() + repo = data['repo'] + classes = data['classes'] + print(data) + #git clone repo + process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() - #make classes directory - for c in classes: - cpath = str(student_id) + "/" + c['name'] - if(os.path.exists(cpath)): - print(cpath + " already exists...") - else: - os.mkdir(str(student_id) + "/" + c['name']) - - #make assignments directory - for a in c['assignments']: - path = str(student_id) + "/" + c['name'] + "/" + a['name'] - print(path) - if(os.path.exists("/" +path)): - print(path + " already exists...") + # make classes directory + for c in classes: + cpath = str(ion_user) + "/" + c['name'] + if(os.path.exists(cpath)): + print(cpath + " already exists...") else: - os.mkdir(str(student_id) + "/" + c['name'] + "/" + a['name']) + os.mkdir(str(ion_user) + "/" + c['name']) + + #make assignments directory + for a in c['assignments']: + path = str(ion_user) + "/" + c['name'] + "/" + a['name'] + print(path) + if(os.path.exists("/" +path)): + print(path + " already exists...") + else: + os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name']) + + #push to remote repo + os.chdir(ion_user) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() -#Teachers + elif(r.status_code == 404): + print("Make new account!") + elif(r.status_code == 403): + print("Invalid username/password") + else: + print(r.status_code) + +def addClass(Name) #make student repo by student id def addStudent(stid, teacher): @@ -64,4 +83,3 @@ def comment(filename, text): print(text) -initStudent(1579460) \ No newline at end of file diff --git a/Website/api/maker.py b/Website/api/maker.py index f960dba..dd31bb6 100644 --- a/Website/api/maker.py +++ b/Website/api/maker.py @@ -1,4 +1,3 @@ -from api.models import Assignment, Student, Classes, Teacher, DefFiles from datetime import datetime f1 = DefFiles( diff --git a/Website/api/migrations/0003_auto_20200607_1519.py b/Website/api/migrations/0003_auto_20200607_1519.py new file mode 100644 index 0000000..7bf2210 --- /dev/null +++ b/Website/api/migrations/0003_auto_20200607_1519.py @@ -0,0 +1,23 @@ +# 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'), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index cf31bb6..0b139e6 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -13,6 +13,7 @@ class Assignment(models.Model): class Classes(models.Model): name = models.CharField(max_length=100) assignments = models.ManyToManyField(Assignment, default="") + repo=models.URLField(default="") def save(self, *args, **kwargs): return super(Classes, self).save(*args, **kwargs) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 46d09cc..5eb1c63 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -19,7 +19,7 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer): assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Classes - fields = ['url', 'name','assignments'] + fields = ['url', 'name','assignments', 'repo'] class StudentSerializer(serializers.HyperlinkedModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) diff --git a/Website/api/views-back.py b/Website/api/views-back.py new file mode 100644 index 0000000..5c936f9 --- /dev/null +++ b/Website/api/views-back.py @@ -0,0 +1,131 @@ +# class StudentList(APIView): +# """ +# List all snippets, or create a new snippet. +# """ +# def get(self, request, format=None): +# snippets = Student.objects.all() +# serializer = StudentSerializer(snippets, many=True) +# return response.Response(serializer.data) + +# def post(self, request, format=None): +# serializer = StudentSerializer(data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data, status=status.HTTP_201_CREATED) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# class StudentDetail(APIView): +# """ +# Retrieve, update or delete a snippet instance. +# """ +# def get_object(self, pk): +# try: +# return Student.objects.get(pk=pk) +# except Student.DoesNotExist: +# raise Http404 + +# def get(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = StudentSerializer(snippet) +# return response.Response(serializer.data) + +# def put(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = StudentSerializer(snippet, data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# def delete(self, request, pk, format=None): +# snippet = self.get_object(pk) +# snippet.delete() +# return response.Response(status=status.HTTP_204_NO_CONTENT) + +# class TeacherList(APIView): +# """ +# List all snippets, or create a new snippet. +# """ +# def get(self, request, format=None): +# snippets = Teacher.objects.all() +# serializer = TeacherSerializer(snippets, many=True) +# return response.Response(serializer.data) + +# def post(self, request, format=None): +# serializer = TeacherSerializer(data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data, status=status.HTTP_201_CREATED) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# class TeacherDetail(APIView): +# """ +# Retrieve, update or delete a snippet instance. +# """ +# def get_object(self, pk): +# try: +# return Teacher.objects.get(pk=pk) +# except Teacher.DoesNotExist: +# raise Http404 + +# def get(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = TeacherSerializer(snippet) +# return response.Response(serializer.data) + +# def put(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = TeacherSerializer(snippet, data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# def delete(self, request, pk, format=None): +# snippet = self.get_object(pk) +# snippet.delete() +# return response.Response(status=status.HTTP_204_NO_CONTENT) + +# class ClassesList(APIView): +# """ +# List all snippets, or create a new snippet. +# """ +# def get(self, request, format=None): +# snippets = Classes.objects.all() +# serializer = ClassesSerializer(snippets, many=True) +# return response.Response(serializer.data) + +# def post(self, request, format=None): +# serializer = ClassesSerializer(data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data, status=status.HTTP_201_CREATED) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# class ClassesDetail(APIView): +# """ +# Retrieve, update or delete a snippet instance. +# """ +# def get_object(self, pk): +# try: +# return Classes.objects.get(pk=pk) +# except Classes.DoesNotExist: +# raise Http404 + +# def get(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = ClassesSerializer(snippet) +# return response.Response(serializer.data) + +# def put(self, request, pk, format=None): +# snippet = self.get_object(pk) +# serializer = ClassesSerializer(snippet, data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return response.Response(serializer.data) +# return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + +# def delete(self, request, pk, format=None): +# snippet = self.get_object(pk) +# snippet.delete() +# return response.Response(status=status.HTTP_204_NO_CONTENT) \ No newline at end of file diff --git a/Website/api/views.py b/Website/api/views.py index 10fe2a8..439c30b 100644 --- a/Website/api/views.py +++ b/Website/api/views.py @@ -1,6 +1,8 @@ from .models import Student, Teacher, Classes, Assignment, DefFiles from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, DefFilesSerializer -from rest_framework import generics, viewsets, permissions +from rest_framework import generics, viewsets, permissions, response, status +from django.http import Http404 +from rest_framework.views import APIView class StudentViewSet(viewsets.ModelViewSet): """ From ddea6db3fff4e0ba0e3aeccd3cf1e2c7e92e8a56 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 00:18:46 -0400 Subject: [PATCH 12/22] teacher methods --- CLI/t-git.py | 222 ++++++++++++++---- .../api/migrations/0004_auto_20200608_0220.py | 18 ++ .../api/migrations/0005_auto_20200608_0222.py | 18 ++ .../api/migrations/0006_auto_20200608_0223.py | 18 ++ .../migrations/0007_classes_default_file.py | 19 ++ .../api/migrations/0008_auto_20200608_0341.py | 22 ++ Website/api/models.py | 5 +- Website/api/serializers.py | 2 +- 8 files changed, 271 insertions(+), 53 deletions(-) create mode 100644 Website/api/migrations/0004_auto_20200608_0220.py create mode 100644 Website/api/migrations/0005_auto_20200608_0222.py create mode 100644 Website/api/migrations/0006_auto_20200608_0223.py create mode 100644 Website/api/migrations/0007_classes_default_file.py create mode 100644 Website/api/migrations/0008_auto_20200608_0341.py diff --git a/CLI/t-git.py b/CLI/t-git.py index 1241390..26b211a 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -4,60 +4,188 @@ import requests #git clone student directory ==> /classes/assignments -def initTeacher(ion_user): - #check if git has already been initialized - if(os.path.exists(str(ion_user) +"/" + ".git")): - print("Already synced to: " + str(ion_user)) - return +''' +{ + "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 getData(ion_user): + URL = "http://127.0.0.1:8000/students/" + ion_user + "/" + r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) + 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) - #get student repo from API - URL = "http://127.0.0.1:8000/students/" + ion_user + "/" - r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) - if(r.status_code == 200): - data = r.json() - repo = data['repo'] - classes = data['classes'] - print(data) - #git clone repo - process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() +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.classes=data['classes'] + self.git=data['git'] + self.username=data['ion_user'] + self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/" + self.data=data + 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: - cpath = str(ion_user) + "/" + c['name'] + cname= c['name'] + "_" + self.username + cpath = self.username + "/" + cname if(os.path.exists(cpath)): print(cpath + " already exists...") else: - os.mkdir(str(ion_user) + "/" + c['name']) - - #make assignments directory - for a in c['assignments']: - path = str(ion_user) + "/" + c['name'] + "/" + a['name'] - print(path) - if(os.path.exists("/" +path)): - print(path + " already exists...") - else: - os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name']) - - #push to remote repo - os.chdir(ion_user) - process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + #make class directory + os.mkdir(cpath) + #make default files for each class + for filename in c['default_file']: + f=open(cpath+"/"+filename, "w") + f.close() + + #make assignments directory + for a in c['assignments']: + path = cpath + "/" + a['name'] + print(path) + if(os.path.exists(path)): + print(path + " already exists...") + else: + os.mkdir(path) + f=open(path + "/README.md", "w") + f.close() + + #push to remote repo + os.chdir(cpath) + process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'commit', '-m', "Hello Class!"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + #git remote add origin git@github.com:alexpchin/.git + process = subprocess.Popen(['git', 'remote', 'add', "origin", "git@github.com:" + self.git + "/" + cname + ".git"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) + process.wait() + + #update API and Github + def 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')) + + 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) process.wait() - elif(r.status_code == 404): - print("Make new account!") - elif(r.status_code == 403): - print("Invalid username/password") - else: - print(r.status_code) -def addClass(Name) + #class name format: _ + + #turn existing directory into class + def addClas(self, path): + cname = path.split("/") + if(os.path.exists(cname)): + print("Already synced to: " + str(self.username)) + return + + + #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/.git + command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git") + command(self, 'git push -u origin master') + + cinfo=[ + { + "name":subject, + "assignments":[], + "repo": "https://github.com:" + self.git + "/" + cname + ".git", + "default_file": [ + { + "name":"README.md" + } + ] + } + ] + + #update rest API + self.classes.append(cinfo) + update(self) + + def addAsignment(self, class_name, name): + os.chdir(self.username+"/") #make student repo by student id def addStudent(stid, teacher): @@ -70,12 +198,6 @@ def addStudent(stid, teacher): process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) process.communicate() -def addStudents(filename): - print(filename) - -def addAsignment(name): - print(name) - def updateAssignment(name): print(name) diff --git a/Website/api/migrations/0004_auto_20200608_0220.py b/Website/api/migrations/0004_auto_20200608_0220.py new file mode 100644 index 0000000..948874d --- /dev/null +++ b/Website/api/migrations/0004_auto_20200608_0220.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0005_auto_20200608_0222.py b/Website/api/migrations/0005_auto_20200608_0222.py new file mode 100644 index 0000000..7d4ac8f --- /dev/null +++ b/Website/api/migrations/0005_auto_20200608_0222.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0006_auto_20200608_0223.py b/Website/api/migrations/0006_auto_20200608_0223.py new file mode 100644 index 0000000..e0f85d3 --- /dev/null +++ b/Website/api/migrations/0006_auto_20200608_0223.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0007_classes_default_file.py b/Website/api/migrations/0007_classes_default_file.py new file mode 100644 index 0000000..ef9e018 --- /dev/null +++ b/Website/api/migrations/0007_classes_default_file.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-08 03:21 + +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(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'), + ), + ] diff --git a/Website/api/migrations/0008_auto_20200608_0341.py b/Website/api/migrations/0008_auto_20200608_0341.py new file mode 100644 index 0000000..f57236c --- /dev/null +++ b/Website/api/migrations/0008_auto_20200608_0341.py @@ -0,0 +1,22 @@ +# 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'), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index 0b139e6..0f3bde3 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -14,6 +14,7 @@ class Classes(models.Model): name = models.CharField(max_length=100) assignments = models.ManyToManyField(Assignment, default="") repo=models.URLField(default="") + default_file = models.ManyToManyField(DefFiles) def save(self, *args, **kwargs): return super(Classes, self).save(*args, **kwargs) @@ -23,7 +24,7 @@ class Teacher(models.Model): last_name = models.CharField(max_length=100) classes = models.ManyToManyField(Classes, default="") ion_user=models.CharField(primary_key=True, max_length=100) - git = models.URLField(default="") + git=models.CharField(max_length=100) class Student(models.Model): created = models.DateTimeField(auto_now_add=True) @@ -33,7 +34,7 @@ class Student(models.Model): ion_user=models.CharField(primary_key=True, max_length=100) webmail = models.EmailField(blank=True) grade = models.IntegerField() - git = models.URLField() + git=models.CharField(max_length=100) classes = models.ManyToManyField(Classes, default="") repo = models.URLField(default="") diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 5eb1c63..0a48ca6 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -19,7 +19,7 @@ class ClassesSerializer(serializers.HyperlinkedModelSerializer): assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Classes - fields = ['url', 'name','assignments', 'repo'] + fields = ['url', 'name','assignments', 'repo',"default_file"] class StudentSerializer(serializers.HyperlinkedModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) From 4c8602ed4fa18326e39a409fb50841056040b049 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 03:49:33 -0400 Subject: [PATCH 13/22] initialize teacher repo --- 2022rkhondak | 1 + CLI/t-git.py | 252 ++++++++++++------ CLI/test.py | 16 ++ .../migrations/0007_classes_default_file.py | 4 +- .../api/migrations/0009_auto_20200608_0502.py | 18 ++ .../api/migrations/0010_auto_20200608_0510.py | 18 ++ Website/api/serializers.py | 1 + .../Math5_eharris1/Week1_HW/instructions.txt | 0 .../Math5_eharris1/Week2_HW/instructions.txt | 0 eharris1/Math5_eharris1/instructions.txt | 0 runtest.py | 2 + 11 files changed, 235 insertions(+), 77 deletions(-) create mode 160000 2022rkhondak create mode 100644 CLI/test.py create mode 100644 Website/api/migrations/0009_auto_20200608_0502.py create mode 100644 Website/api/migrations/0010_auto_20200608_0510.py create mode 100644 eharris1/Math5_eharris1/Week1_HW/instructions.txt create mode 100644 eharris1/Math5_eharris1/Week2_HW/instructions.txt create mode 100644 eharris1/Math5_eharris1/instructions.txt create mode 100644 runtest.py diff --git a/2022rkhondak b/2022rkhondak new file mode 160000 index 0000000..8dca8b7 --- /dev/null +++ b/2022rkhondak @@ -0,0 +1 @@ +Subproject commit 8dca8b78c03fab721e9976a4675e2996802328a7 diff --git a/CLI/t-git.py b/CLI/t-git.py index 26b211a..26c4db4 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -1,7 +1,7 @@ import subprocess import os import requests - +import webbrowser #git clone student directory ==> /classes/assignments ''' @@ -44,8 +44,8 @@ import requests ''' #get teacher info from api def getData(ion_user): - URL = "http://127.0.0.1:8000/students/" + ion_user + "/" - r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr')) + 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 @@ -71,6 +71,17 @@ class Teacher: self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/" self.data=data + 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 @@ -78,72 +89,162 @@ class Teacher: classes = self.classes # make classes directory for c in classes: - cname= c['name'] + "_" + self.username + cname= c['name'] cpath = self.username + "/" + cname - if(os.path.exists(cpath)): - print(cpath + " already exists...") - else: - #make class directory - os.mkdir(cpath) - #make default files for each class - for filename in c['default_file']: - f=open(cpath+"/"+filename, "w") + + 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') - #make assignments directory - for a in c['assignments']: - path = cpath + "/" + a['name'] - print(path) - if(os.path.exists(path)): - print(path + " already exists...") - else: - os.mkdir(path) - f=open(path + "/README.md", "w") - f.close() - - #push to remote repo - os.chdir(cpath) - process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'commit', '-m', "Hello Class!"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - #git remote add origin git@github.com:alexpchin/.git - process = subprocess.Popen(['git', 'remote', 'add', "origin", "git@github.com:" + self.git + "/" + cname + ".git"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.wait() - #update API and Github + #update API and Github, all assignments / classes def 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')) + #lists all classes + classes = os.listdir(self.username) - 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) - process.wait() + #checks all class directories first + for c in classes: + if(checkClass(self, c) == False): + return + cdict = [] + for c in classes: + #lists all assignments and default files + ass = os.listdir(c) + #if no .git, directory not synced to git or API + if '.git' in ass == False: + addClass(self, c) + else: + #push to git + loc = os.getcwd() + os.chdir(c) + command(self, 'git init') + command(self, 'git add .') + command(self, 'git commit -m "Update"') + command(self, 'git push -u origin master') + os.chdir(loc) + #assignments + adict = [] + #default files for classes + fdict=[] + #default files for assignments + afdict=[] + for a in ass: + aname=a + #need to add option + due_date="2020-06-07T07:46:30.537197Z", + if(os.path.isfile(a)): + fdict.append({ + 'name':a + }) + elif(os.path.isdir(a)): + for af in a: + if(os.path.isfile(af)): + afdict.append({ + 'name':af + }) + adict.append({ + 'name':aname, + 'due_date':due_date, + 'files':fdict + }) + cdict.append({ + 'name':c, + 'repo': 'https://github.com:"' + self.git + "/" + c + ".git", + 'assignments':adict, + 'default_file':fdict + }) + r = requests.put(url = self.url, data= cdict, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1')) #class name format: _ - #turn existing directory into class - def addClas(self, path): + #turn existing directory into class, Pre-condition: directory exists + #relative path to class: 2022rkhondak/Math4 + def checkClass(self,path): cname = path.split("/") - if(os.path.exists(cname)): - print("Already synced to: " + str(self.username)) - return + cname = cname[len(cname)-1] + if(("_" + self.username) in cname) == False: + print("Incorrect class name: Must be in the format: _") + 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)): + count=count+1 + if(os.path.isdir(d)): + #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(count == 0): + print("Need a default file in the " + path + " Directory!") + return False + return True + + def addClass(self, path): + cname = path.split("/") + cname = cname[len(cname)-1] + #push to remote repo + if(os.path.exists(path)): + print("Already synced") + return + if(checkClass(self, path)): + 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/.git + command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git") + command(self, 'git push -u origin master') #make a new class from scratch @@ -169,7 +270,7 @@ class Teacher: cinfo=[ { - "name":subject, + "name":cname, "assignments":[], "repo": "https://github.com:" + self.git + "/" + cname + ".git", "default_file": [ @@ -183,25 +284,26 @@ class Teacher: #update rest API self.classes.append(cinfo) update(self) - - def addAsignment(self, class_name, name): - os.chdir(self.username+"/") + 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(stid, teacher): - os.mkdir(stid) - os.chdir(os.getcwd() + "/" + stid) - process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() - process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() - process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE) - process.communicate() + def addStudent(self,stid): + print(stid) -def updateAssignment(name): - print(name) + def comment(self): + print("heheheh") -def comment(filename, text): - print(text) +data = getData("eharris1") +print(data) +t = Teacher(data) +t.initTeacher() diff --git a/CLI/test.py b/CLI/test.py new file mode 100644 index 0000000..11389ac --- /dev/null +++ b/CLI/test.py @@ -0,0 +1,16 @@ +import subprocess +import os +import time + +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) + +command('echo hello') +command('python runtest.py') diff --git a/Website/api/migrations/0007_classes_default_file.py b/Website/api/migrations/0007_classes_default_file.py index ef9e018..b6cb7d0 100644 --- a/Website/api/migrations/0007_classes_default_file.py +++ b/Website/api/migrations/0007_classes_default_file.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2020-06-08 03:21 +# Generated by Django 3.0.7 on 2020-06-08 03:18 from django.db import migrations, models import django.db.models.deletion @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='classes', name='default_file', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'), + field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.DefFiles'), ), ] diff --git a/Website/api/migrations/0009_auto_20200608_0502.py b/Website/api/migrations/0009_auto_20200608_0502.py new file mode 100644 index 0000000..49f518d --- /dev/null +++ b/Website/api/migrations/0009_auto_20200608_0502.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0010_auto_20200608_0510.py b/Website/api/migrations/0010_auto_20200608_0510.py new file mode 100644 index 0000000..a859d51 --- /dev/null +++ b/Website/api/migrations/0010_auto_20200608_0510.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 0a48ca6..cf9a1a1 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -17,6 +17,7 @@ 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) class Meta: model = Classes fields = ['url', 'name','assignments', 'repo',"default_file"] diff --git a/eharris1/Math5_eharris1/Week1_HW/instructions.txt b/eharris1/Math5_eharris1/Week1_HW/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/Math5_eharris1/Week2_HW/instructions.txt b/eharris1/Math5_eharris1/Week2_HW/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/Math5_eharris1/instructions.txt b/eharris1/Math5_eharris1/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/runtest.py b/runtest.py new file mode 100644 index 0000000..837cd82 --- /dev/null +++ b/runtest.py @@ -0,0 +1,2 @@ +for i in range(0, 100000): + print(i) \ No newline at end of file From d04897f0a9e1d85acdecec1d340e02ce59b4b25a Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 04:15:38 -0400 Subject: [PATCH 14/22] "Update" --- eharris1/Math4_eharris1/welcome.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 eharris1/Math4_eharris1/welcome.txt diff --git a/eharris1/Math4_eharris1/welcome.txt b/eharris1/Math4_eharris1/welcome.txt new file mode 100644 index 0000000..e69de29 From 8060fad3ecde9a009f413cb6d4d72f774f9d2668 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 13:35:16 -0400 Subject: [PATCH 15/22] api bug --- CLI/t-git.py | 110 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 35 deletions(-) diff --git a/CLI/t-git.py b/CLI/t-git.py index 26c4db4..d043e02 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -2,6 +2,8 @@ import subprocess import os import requests import webbrowser +import pprint +import json #git clone student directory ==> /classes/assignments ''' @@ -131,7 +133,12 @@ class Teacher: 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 + #update API and Github, all assignments / classes def update(self): #lists all classes @@ -139,24 +146,32 @@ class Teacher: #checks all class directories first for c in classes: - if(checkClass(self, c) == False): + path = self.username + "/" + c + if(self.checkClass(path) == False): + print(path) return cdict = [] for c in classes: + path = self.username + "/" + c #lists all assignments and default files - ass = os.listdir(c) + ass = os.listdir(path) #if no .git, directory not synced to git or API - if '.git' in ass == False: - addClass(self, c) + if (self.checkGit(ass)==False): + print(path) + self.addClass(path) else: #push to git loc = os.getcwd() - os.chdir(c) - command(self, 'git init') - command(self, 'git add .') - command(self, 'git commit -m "Update"') - command(self, 'git push -u origin master') + os.chdir(path) + print(path) + print(ass) + self.command('git add .') + self.command('git commit -m "Update"') + self.command('git push -u origin master') os.chdir(loc) + ass.remove('.git') + print(ass) + #assignments adict = [] #default files for classes @@ -165,31 +180,46 @@ class Teacher: afdict=[] for a in ass: aname=a + path = self.username + "/" + c + "/" + a #need to add option - due_date="2020-06-07T07:46:30.537197Z", - if(os.path.isfile(a)): + due_date= '2020-06-07T07:46:30.537197Z', + #check for default file + if(os.path.isfile(path)): fdict.append({ 'name':a }) - elif(os.path.isdir(a)): - for af in a: - if(os.path.isfile(af)): + elif(os.path.isdir(path)): + for af in os.listdir(path): + path = path+ "/" + af + if(os.path.isfile(path)): afdict.append({ 'name':af }) adict.append({ 'name':aname, - 'due_date':due_date, - 'files':fdict + 'due_date': due_date[0], + 'files':afdict }) cdict.append({ 'name':c, - 'repo': 'https://github.com:"' + self.git + "/" + c + ".git", + 'repo': 'https://github.com:' + self.git + "/" + c + ".git", 'assignments':adict, 'default_file':fdict }) - r = requests.put(url = self.url, data= cdict, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1')) + + mdict= { + 'first_name':self.first_name, + 'last_name':self.last_name, + 'classes':cdict, + 'git':self.git, + 'ion_user':self.username + } + data = json.dumps(mdict) + print(pprint.pprint(mdict)) + + r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1')) + print(pprint.pprint(r.json())) #class name format: _ @@ -210,8 +240,8 @@ class Teacher: for d in dirs: if(os.path.isfile(d)): - count=count+1 - if(os.path.isdir(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) @@ -225,26 +255,37 @@ class Teacher: print("Assignment '" + as_bad + "' does not have a default file!") return False - if(count == 0): + if(deffile): print("Need a default file in the " + path + " Directory!") return False return True + #adds class to git, not API def addClass(self, path): cname = path.split("/") cname = cname[len(cname)-1] #push to remote repo - if(os.path.exists(path)): - print("Already synced") - return - if(checkClass(self, path)): - 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/.git - command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git") - command(self, 'git push -u origin master') + 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 + 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 @@ -302,8 +343,7 @@ class Teacher: print("heheheh") data = getData("eharris1") -print(data) t = Teacher(data) -t.initTeacher() +t.update() From c50c305b867faa298a675f6dff3614611bc9c750 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 19:15:33 -0400 Subject: [PATCH 16/22] git update --- CLI/t-git.py | 75 +++++++++++++------ .../api/migrations/0011_auto_20200608_1853.py | 18 +++++ Website/api/migrations/0012_deffiles_path.py | 18 +++++ .../api/migrations/0013_auto_20200608_2117.py | 18 +++++ .../api/migrations/0014_auto_20200608_2122.py | 18 +++++ .../api/migrations/0015_assignment_path.py | 18 +++++ .../api/migrations/0016_auto_20200608_2203.py | 18 +++++ Website/api/migrations/0017_classes_path.py | 18 +++++ Website/api/models.py | 7 +- Website/api/serializers.py | 10 +-- 10 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 Website/api/migrations/0011_auto_20200608_1853.py create mode 100644 Website/api/migrations/0012_deffiles_path.py create mode 100644 Website/api/migrations/0013_auto_20200608_2117.py create mode 100644 Website/api/migrations/0014_auto_20200608_2122.py create mode 100644 Website/api/migrations/0015_assignment_path.py create mode 100644 Website/api/migrations/0016_auto_20200608_2203.py create mode 100644 Website/api/migrations/0017_classes_path.py diff --git a/CLI/t-git.py b/CLI/t-git.py index d043e02..b999763 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -45,7 +45,7 @@ import json }, ''' #get teacher info from api -def getData(ion_user): +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): @@ -81,7 +81,7 @@ class Teacher: process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) p=process.poll() output = process.communicate()[0] - print(output.decode('utf-8')) + #print(output.decode('utf-8')) def initTeacher(self): if(os.path.exists(self.username )): @@ -139,6 +139,26 @@ class Teacher: 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: + 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 def update(self): #lists all classes @@ -148,7 +168,6 @@ class Teacher: for c in classes: path = self.username + "/" + c if(self.checkClass(path) == False): - print(path) return cdict = [] for c in classes: @@ -157,20 +176,21 @@ class Teacher: ass = os.listdir(path) #if no .git, directory not synced to git or API if (self.checkGit(ass)==False): - print(path) self.addClass(path) else: #push to git loc = os.getcwd() os.chdir(path) - print(path) - print(ass) self.command('git add .') self.command('git commit -m "Update"') self.command('git push -u origin master') os.chdir(loc) ass.remove('.git') - print(ass) + + loc = os.getcwd() + os.chdir(path) + repo = self.command('git config --get remote.origin.url') + os.chdir(loc) #assignments adict = [] @@ -186,40 +206,53 @@ class Teacher: #check for default file if(os.path.isfile(path)): fdict.append({ - 'name':a + '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 + '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': 'https://github.com:' + self.git + "/" + c + ".git", + 'repo': repo, + 'path':path, 'assignments':adict, - 'default_file':fdict + 'default_file':fdict, }) + self.compareDB(cdict,'http://127.0.0.1:8000/classes/') mdict= { 'first_name':self.first_name, 'last_name':self.last_name, - 'classes':cdict, 'git':self.git, - 'ion_user':self.username + 'ion_user':self.username, + 'classes':cdict, } - data = json.dumps(mdict) - print(pprint.pprint(mdict)) - r = requests.put(url = self.url, data= data, headers={'Content-type': 'application/json'} ,auth=('raffukhondaker','hackgroup1')) - print(pprint.pprint(r.json())) + 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: _ @@ -261,7 +294,7 @@ class Teacher: return True #adds class to git, not API - def addClass(self, path): + def addClasstoGit(self, path): cname = path.split("/") cname = cname[len(cname)-1] #push to remote repo @@ -276,7 +309,7 @@ class Teacher: 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 + return None cdir = os.getcwd() os.chdir(path) self.command('git init') @@ -287,7 +320,6 @@ class Teacher: os.chdir(cdir) - #make a new class from scratch def makeClass(self, subject): cname = subject + "_" + self.username @@ -342,7 +374,8 @@ class Teacher: def comment(self): print("heheheh") -data = getData("eharris1") +# 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() diff --git a/Website/api/migrations/0011_auto_20200608_1853.py b/Website/api/migrations/0011_auto_20200608_1853.py new file mode 100644 index 0000000..bf35506 --- /dev/null +++ b/Website/api/migrations/0011_auto_20200608_1853.py @@ -0,0 +1,18 @@ +# 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'), + ), + ] diff --git a/Website/api/migrations/0012_deffiles_path.py b/Website/api/migrations/0012_deffiles_path.py new file mode 100644 index 0000000..6a65c83 --- /dev/null +++ b/Website/api/migrations/0012_deffiles_path.py @@ -0,0 +1,18 @@ +# 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=''), + ), + ] diff --git a/Website/api/migrations/0013_auto_20200608_2117.py b/Website/api/migrations/0013_auto_20200608_2117.py new file mode 100644 index 0000000..f74a401 --- /dev/null +++ b/Website/api/migrations/0013_auto_20200608_2117.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0014_auto_20200608_2122.py b/Website/api/migrations/0014_auto_20200608_2122.py new file mode 100644 index 0000000..b9acec6 --- /dev/null +++ b/Website/api/migrations/0014_auto_20200608_2122.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0015_assignment_path.py b/Website/api/migrations/0015_assignment_path.py new file mode 100644 index 0000000..ff345b8 --- /dev/null +++ b/Website/api/migrations/0015_assignment_path.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0016_auto_20200608_2203.py b/Website/api/migrations/0016_auto_20200608_2203.py new file mode 100644 index 0000000..7dc5728 --- /dev/null +++ b/Website/api/migrations/0016_auto_20200608_2203.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/migrations/0017_classes_path.py b/Website/api/migrations/0017_classes_path.py new file mode 100644 index 0000000..fa6cd4b --- /dev/null +++ b/Website/api/migrations/0017_classes_path.py @@ -0,0 +1,18 @@ +# 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), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index 0f3bde3..d34c077 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -2,18 +2,21 @@ from django.db import models class DefFiles(models.Model): name=models.CharField(max_length=100) + path=models.CharField(max_length=100) class Assignment(models.Model): name=models.CharField(max_length=100) due_date=models.DateTimeField() - files = models.ManyToManyField(DefFiles, default="") + files = models.ManyToManyField(DefFiles) + path=models.CharField(max_length=100) def __str__(self): return '%s' % (self.name) class Classes(models.Model): name = models.CharField(max_length=100) - assignments = models.ManyToManyField(Assignment, default="") repo=models.URLField(default="") + path=models.CharField(max_length=100, default="") + assignments = models.ManyToManyField(Assignment, default="") default_file = models.ManyToManyField(DefFiles) def save(self, *args, **kwargs): return super(Classes, self).save(*args, **kwargs) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index cf9a1a1..7c8317b 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -6,32 +6,32 @@ class DefFilesSerializer(serializers.HyperlinkedModelSerializer): permissions_classes = [permissions.IsAuthenticatedOrReadOnly] class Meta: model = DefFiles - fields = ['name'] + fields = ['name', 'path','url'] class AssignmentSerializer(serializers.HyperlinkedModelSerializer): permissions_classes = [permissions.IsAuthenticatedOrReadOnly] files = DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Assignment - fields = ['name', 'due_date', 'url', 'files'] + fields = ['name', 'due_date', 'url', 'path' ,'files'] 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) class Meta: model = Classes - fields = ['url', 'name','assignments', 'repo',"default_file"] + fields = ['url', 'name', 'repo','path', 'assignments',"default_file"] class StudentSerializer(serializers.HyperlinkedModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Student - fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes', 'git','repo','ion_user'] + fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id', 'git','repo','ion_user','classes'] class TeacherSerializer(serializers.ModelSerializer): classes = ClassesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Teacher - fields = ['url', 'first_name', 'last_name', 'classes','git','ion_user'] + fields = ['url', 'first_name', 'last_name','git','ion_user','classes' ] From e151acabfb4e18b8ad121bbedd5e2649ffdcba77 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Mon, 8 Jun 2020 23:33:44 -0400 Subject: [PATCH 17/22] config api --- CLI/t-git-old.py | 457 ++++++++++++++++++ CLI/t-git.py | 336 ++++--------- CLI/text.py | 2 + CLI/users.json | 1 - Website/api/migrations/0001_initial.py | 27 +- .../api/migrations/0002_auto_20200607_0751.py | 18 - .../api/migrations/0003_auto_20200607_1519.py | 23 - .../api/migrations/0004_auto_20200608_0220.py | 18 - .../api/migrations/0005_auto_20200608_0222.py | 18 - .../api/migrations/0006_auto_20200608_0223.py | 18 - .../migrations/0007_classes_default_file.py | 19 - .../api/migrations/0008_auto_20200608_0341.py | 22 - .../api/migrations/0009_auto_20200608_0502.py | 18 - .../api/migrations/0010_auto_20200608_0510.py | 18 - .../api/migrations/0011_auto_20200608_1853.py | 18 - Website/api/migrations/0012_deffiles_path.py | 18 - .../api/migrations/0013_auto_20200608_2117.py | 18 - .../api/migrations/0014_auto_20200608_2122.py | 18 - .../api/migrations/0015_assignment_path.py | 18 - .../api/migrations/0016_auto_20200608_2203.py | 18 - Website/api/migrations/0017_classes_path.py | 18 - Website/api/models.py | 19 +- Website/api/serializers.py | 16 +- .../Math4_eharris1/{welcome.txt => README.md} | 0 .../Week1_HW}/instructions.txt | 0 .../Math4_eharris1/Week2_HW/instructions.txt | 0 eharris1/Math5_eharris1/README.md | 0 27 files changed, 590 insertions(+), 566 deletions(-) create mode 100644 CLI/t-git-old.py create mode 100644 CLI/text.py delete mode 100644 CLI/users.json delete mode 100644 Website/api/migrations/0002_auto_20200607_0751.py delete mode 100644 Website/api/migrations/0003_auto_20200607_1519.py delete mode 100644 Website/api/migrations/0004_auto_20200608_0220.py delete mode 100644 Website/api/migrations/0005_auto_20200608_0222.py delete mode 100644 Website/api/migrations/0006_auto_20200608_0223.py delete mode 100644 Website/api/migrations/0007_classes_default_file.py delete mode 100644 Website/api/migrations/0008_auto_20200608_0341.py delete mode 100644 Website/api/migrations/0009_auto_20200608_0502.py delete mode 100644 Website/api/migrations/0010_auto_20200608_0510.py delete mode 100644 Website/api/migrations/0011_auto_20200608_1853.py delete mode 100644 Website/api/migrations/0012_deffiles_path.py delete mode 100644 Website/api/migrations/0013_auto_20200608_2117.py delete mode 100644 Website/api/migrations/0014_auto_20200608_2122.py delete mode 100644 Website/api/migrations/0015_assignment_path.py delete mode 100644 Website/api/migrations/0016_auto_20200608_2203.py delete mode 100644 Website/api/migrations/0017_classes_path.py rename eharris1/Math4_eharris1/{welcome.txt => README.md} (100%) rename eharris1/{Math5_eharris1 => Math4_eharris1/Week1_HW}/instructions.txt (100%) create mode 100644 eharris1/Math4_eharris1/Week2_HW/instructions.txt create mode 100644 eharris1/Math5_eharris1/README.md diff --git a/CLI/t-git-old.py b/CLI/t-git-old.py new file mode 100644 index 0000000..d2a3316 --- /dev/null +++ b/CLI/t-git-old.py @@ -0,0 +1,457 @@ +import subprocess +import os +import requests +import webbrowser +import pprint +import json + +#git clone student directory ==> /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: _ + + #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: _") + 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/.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() + + diff --git a/CLI/t-git.py b/CLI/t-git.py index b999763..e97a0c6 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -6,44 +6,7 @@ import pprint import json #git clone student directory ==> /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 + "/" @@ -59,7 +22,28 @@ def getTeacher(ion_user): print("Invalid username/password") else: 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: def __init__(self, data): @@ -67,71 +51,15 @@ class Teacher: # intitialze fields after GET request self.first_name=data['first_name'] self.last_name=data['last_name'] - self.classes=data['classes'] self.git=data['git'] self.username=data['ion_user'] self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/" - self.data=data - - 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') + self.classes=data['classes'].split(" ") + self.sclass=data['classes'] + if(os.path.isdir(self.username)): + print("Already synced to " + self.username) + else: + os.mkdir(self.username) def checkGit(self, ass): for a in ass: @@ -139,26 +67,6 @@ class Teacher: 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: - 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 def update(self): #lists all classes @@ -176,83 +84,16 @@ class Teacher: ass = os.listdir(path) #if no .git, directory not synced to git or API if (self.checkGit(ass)==False): - self.addClass(path) + data = self.addClasstoGit(path) + postDB(data, 'http://127.0.0.1:8000/classes/') 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') + command('git add .') + command('git commit -m "Update"') + 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 - }) - - 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: _ @@ -288,7 +129,7 @@ class Teacher: print("Assignment '" + as_bad + "' does not have a default file!") return False - if(deffile): + if(deffile==False): print("Need a default file in the " + path + " Directory!") return False return True @@ -298,74 +139,80 @@ class Teacher: cname = path.split("/") cname = cname[len(cname)-1] #push to remote repo + url='https://github.com/' + self.git + "/" + cname 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") + if(requests.get(url).status_code != 200): + 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 + 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') + command('git init') + command('git add .') + command('git commit -m Hello_Class') + command('git remote add origin ' + url + '.git') + command('git push -u origin master') os.chdir(cdir) + data={ + 'name':cname, + 'repo':url, + 'path':path, + 'teacher':self.username + } + return data + return None #make a new class from scratch - def makeClass(self, subject): - cname = subject + "_" + self.username + #subject: string, assignments: list + #class name must be: _ + def makeClass(self, cname, assignments): + cdir = os.getcwd() os.chdir(self.username) #check if class exists if(os.path.exists(cname)): - print("Already synced to: " + str(self.username)) + print("Class already exists: " + cname) return else: + if((("_" + self.username) in cname) == False): + print("class name must be: "+ cname + "_" + self.username) + return + path = self.username + "/" + cname 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/.git - command(self, 'git remote add origin git@github.com:'+ self.git + "/" + cname + ".git") - command(self, 'git push -u origin master') + for a in assignments: + os.mkdir(a) + f=open(a + "/instructions.txt", "w") + f.close() + os.chdir(cdir) - cinfo=[ - { - "name":cname, - "assignments":[], - "repo": "https://github.com:" + self.git + "/" + cname + ".git", - "default_file": [ - { - "name":"README.md" - } - ] + data = self.addClasstoGit(path) + print(postDB(data, 'http://127.0.0.1:8000/classes/')) + if(len(self.sclass)==0): + classes = cname + else: + classes = self.sclass + "," + cname + + data={ + 'first_name':self.first_name, + 'last_name':self.last_name, + 'git':self.git, + 'ion_user':self.username, + 'url':self.url, + 'classes':classes } - ] - - #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')) + print(putDB(data, self.url)) + return data #make student repo by student id def addStudent(self,stid): @@ -374,9 +221,8 @@ class Teacher: 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'}]}]} +data = getTeacher("eharris1") t = Teacher(data) -t.update() +t.makeClass('Math4_eharris1', ['Week1_HW', 'Week2_HW']) diff --git a/CLI/text.py b/CLI/text.py new file mode 100644 index 0000000..60b8cca --- /dev/null +++ b/CLI/text.py @@ -0,0 +1,2 @@ +import textract +text = textract.process('test.py') \ No newline at end of file diff --git a/CLI/users.json b/CLI/users.json deleted file mode 100644 index bf1713e..0000000 --- a/CLI/users.json +++ /dev/null @@ -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"]}}] \ No newline at end of file diff --git a/Website/api/migrations/0001_initial.py b/Website/api/migrations/0001_initial.py index 476a6f2..11b47e4 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-07 07:45 +# Generated by Django 3.0.7 on 2020-06-09 02:03 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')), ('name', models.CharField(max_length=100)), ('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( @@ -24,7 +28,11 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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( @@ -32,6 +40,10 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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( @@ -40,9 +52,9 @@ class Migration(migrations.Migration): ('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.URLField(default='')), - ('classes', models.ManyToManyField(default='', to='api.Classes')), + ('git', models.CharField(max_length=100)), ], ), migrations.CreateModel( @@ -55,14 +67,9 @@ class Migration(migrations.Migration): ('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)), ('webmail', models.EmailField(blank=True, max_length=254)), ('grade', models.IntegerField()), - ('git', models.URLField()), + ('git', models.CharField(max_length=100)), ('repo', models.URLField(default='')), ('classes', models.ManyToManyField(default='', to='api.Classes')), ], ), - migrations.AddField( - model_name='assignment', - name='files', - field=models.ManyToManyField(default='instructions.txt', to='api.DefFiles'), - ), ] diff --git a/Website/api/migrations/0002_auto_20200607_0751.py b/Website/api/migrations/0002_auto_20200607_0751.py deleted file mode 100644 index d78e3e1..0000000 --- a/Website/api/migrations/0002_auto_20200607_0751.py +++ /dev/null @@ -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'), - ), - ] diff --git a/Website/api/migrations/0003_auto_20200607_1519.py b/Website/api/migrations/0003_auto_20200607_1519.py deleted file mode 100644 index 7bf2210..0000000 --- a/Website/api/migrations/0003_auto_20200607_1519.py +++ /dev/null @@ -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'), - ), - ] diff --git a/Website/api/migrations/0004_auto_20200608_0220.py b/Website/api/migrations/0004_auto_20200608_0220.py deleted file mode 100644 index 948874d..0000000 --- a/Website/api/migrations/0004_auto_20200608_0220.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0005_auto_20200608_0222.py b/Website/api/migrations/0005_auto_20200608_0222.py deleted file mode 100644 index 7d4ac8f..0000000 --- a/Website/api/migrations/0005_auto_20200608_0222.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0006_auto_20200608_0223.py b/Website/api/migrations/0006_auto_20200608_0223.py deleted file mode 100644 index e0f85d3..0000000 --- a/Website/api/migrations/0006_auto_20200608_0223.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0007_classes_default_file.py b/Website/api/migrations/0007_classes_default_file.py deleted file mode 100644 index b6cb7d0..0000000 --- a/Website/api/migrations/0007_classes_default_file.py +++ /dev/null @@ -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'), - ), - ] diff --git a/Website/api/migrations/0008_auto_20200608_0341.py b/Website/api/migrations/0008_auto_20200608_0341.py deleted file mode 100644 index f57236c..0000000 --- a/Website/api/migrations/0008_auto_20200608_0341.py +++ /dev/null @@ -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'), - ), - ] diff --git a/Website/api/migrations/0009_auto_20200608_0502.py b/Website/api/migrations/0009_auto_20200608_0502.py deleted file mode 100644 index 49f518d..0000000 --- a/Website/api/migrations/0009_auto_20200608_0502.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0010_auto_20200608_0510.py b/Website/api/migrations/0010_auto_20200608_0510.py deleted file mode 100644 index a859d51..0000000 --- a/Website/api/migrations/0010_auto_20200608_0510.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0011_auto_20200608_1853.py b/Website/api/migrations/0011_auto_20200608_1853.py deleted file mode 100644 index bf35506..0000000 --- a/Website/api/migrations/0011_auto_20200608_1853.py +++ /dev/null @@ -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'), - ), - ] diff --git a/Website/api/migrations/0012_deffiles_path.py b/Website/api/migrations/0012_deffiles_path.py deleted file mode 100644 index 6a65c83..0000000 --- a/Website/api/migrations/0012_deffiles_path.py +++ /dev/null @@ -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=''), - ), - ] diff --git a/Website/api/migrations/0013_auto_20200608_2117.py b/Website/api/migrations/0013_auto_20200608_2117.py deleted file mode 100644 index f74a401..0000000 --- a/Website/api/migrations/0013_auto_20200608_2117.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0014_auto_20200608_2122.py b/Website/api/migrations/0014_auto_20200608_2122.py deleted file mode 100644 index b9acec6..0000000 --- a/Website/api/migrations/0014_auto_20200608_2122.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0015_assignment_path.py b/Website/api/migrations/0015_assignment_path.py deleted file mode 100644 index ff345b8..0000000 --- a/Website/api/migrations/0015_assignment_path.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0016_auto_20200608_2203.py b/Website/api/migrations/0016_auto_20200608_2203.py deleted file mode 100644 index 7dc5728..0000000 --- a/Website/api/migrations/0016_auto_20200608_2203.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/migrations/0017_classes_path.py b/Website/api/migrations/0017_classes_path.py deleted file mode 100644 index fa6cd4b..0000000 --- a/Website/api/migrations/0017_classes_path.py +++ /dev/null @@ -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), - ), - ] diff --git a/Website/api/models.py b/Website/api/models.py index d34c077..c7881aa 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -3,12 +3,18 @@ from django.db import models class DefFiles(models.Model): name=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): name=models.CharField(max_length=100) due_date=models.DateTimeField() - files = models.ManyToManyField(DefFiles) + # files = models.ManyToManyField(DefFiles) + files=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): return '%s' % (self.name) @@ -16,8 +22,12 @@ class Classes(models.Model): name = models.CharField(max_length=100) repo=models.URLField(default="") path=models.CharField(max_length=100, default="") - assignments = models.ManyToManyField(Assignment, default="") - default_file = models.ManyToManyField(DefFiles) + teacher=models.CharField(max_length=100, default="") + 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): return super(Classes, self).save(*args, **kwargs) @@ -25,7 +35,8 @@ class Teacher(models.Model): created = models.DateTimeField(auto_now_add=True) first_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) git=models.CharField(max_length=100) diff --git a/Website/api/serializers.py b/Website/api/serializers.py index 7c8317b..ca13238 100644 --- a/Website/api/serializers.py +++ b/Website/api/serializers.py @@ -6,21 +6,21 @@ class DefFilesSerializer(serializers.HyperlinkedModelSerializer): permissions_classes = [permissions.IsAuthenticatedOrReadOnly] class Meta: model = DefFiles - fields = ['name', 'path','url'] + fields = ['name', 'path','assignment','classes', "teacher",'url', 'id'] class AssignmentSerializer(serializers.HyperlinkedModelSerializer): 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: model = Assignment - fields = ['name', 'due_date', 'url', 'path' ,'files'] + fields = ['name', 'due_date', 'url', 'path' , "classes","teacher",'files', 'id'] 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) + # assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True) + # default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True) class Meta: model = Classes - fields = ['url', 'name', 'repo','path', 'assignments',"default_file"] + fields = ['url', 'name', 'repo','path', "teacher",'assignments',"default_file",'id'] class StudentSerializer(serializers.HyperlinkedModelSerializer): 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'] 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: model = Teacher - fields = ['url', 'first_name', 'last_name','git','ion_user','classes' ] + fields = ['url', 'first_name', 'last_name','git','ion_user','classes'] diff --git a/eharris1/Math4_eharris1/welcome.txt b/eharris1/Math4_eharris1/README.md similarity index 100% rename from eharris1/Math4_eharris1/welcome.txt rename to eharris1/Math4_eharris1/README.md diff --git a/eharris1/Math5_eharris1/instructions.txt b/eharris1/Math4_eharris1/Week1_HW/instructions.txt similarity index 100% rename from eharris1/Math5_eharris1/instructions.txt rename to eharris1/Math4_eharris1/Week1_HW/instructions.txt diff --git a/eharris1/Math4_eharris1/Week2_HW/instructions.txt b/eharris1/Math4_eharris1/Week2_HW/instructions.txt new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/Math5_eharris1/README.md b/eharris1/Math5_eharris1/README.md new file mode 100644 index 0000000..e69de29 From 6b031bbd3f025f8a43fc5378ae365f8039d05cf2 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 9 Jun 2020 13:54:15 -0400 Subject: [PATCH 18/22] Hello_Class --- eharris1/CalculusBS_eharris1/README.md | 0 eharris1/CalculusBS_eharris1/Week1/worksheet1.txt | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 eharris1/CalculusBS_eharris1/README.md create mode 100644 eharris1/CalculusBS_eharris1/Week1/worksheet1.txt diff --git a/eharris1/CalculusBS_eharris1/README.md b/eharris1/CalculusBS_eharris1/README.md new file mode 100644 index 0000000..e69de29 diff --git a/eharris1/CalculusBS_eharris1/Week1/worksheet1.txt b/eharris1/CalculusBS_eharris1/Week1/worksheet1.txt new file mode 100644 index 0000000..e69de29 From 45c6c78b5200c601ba7ea063f50ee5fb081d3e6a Mon Sep 17 00:00:00 2001 From: rushilwiz Date: Tue, 9 Jun 2020 14:48:00 -0400 Subject: [PATCH 19/22] CLI OAUTH POG --- CLI/index.html | 9 +++++++++ CLI/oauth/index.html | 23 +++++++++++++++++++++ CLI/oauth/template.html | 23 +++++++++++++++++++++ CLI/server.py | 23 +++++++++++++++++++++ CLI/skoolos.py | 45 ++++++++++++++++++++++++++++++++++++----- 5 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 CLI/index.html create mode 100644 CLI/oauth/index.html create mode 100644 CLI/oauth/template.html create mode 100644 CLI/server.py diff --git a/CLI/index.html b/CLI/index.html new file mode 100644 index 0000000..a21b847 --- /dev/null +++ b/CLI/index.html @@ -0,0 +1,9 @@ + + + + Sign in with Ion + + + Sign in with + + \ No newline at end of file diff --git a/CLI/oauth/index.html b/CLI/oauth/index.html new file mode 100644 index 0000000..7afe9a9 --- /dev/null +++ b/CLI/oauth/index.html @@ -0,0 +1,23 @@ + + + Sign into Ion + + + + + + + + + \ No newline at end of file diff --git a/CLI/oauth/template.html b/CLI/oauth/template.html new file mode 100644 index 0000000..6452ea8 --- /dev/null +++ b/CLI/oauth/template.html @@ -0,0 +1,23 @@ + + + Sign into Ion + + + + + + + + + \ No newline at end of file diff --git a/CLI/server.py b/CLI/server.py new file mode 100644 index 0000000..0aef4c5 --- /dev/null +++ b/CLI/server.py @@ -0,0 +1,23 @@ +from socket import * +from selenium import webdriver +import http.server +import socketserver +import threading + + +def create_server(): + port = 8000 + handler = http.server.SimpleHTTPRequestHandler + httpd = socketserver.TCPServer(("", port), handler) + print("serving at port:" + str(port)) + httpd.serve_forever() + + +threading.Thread(target=create_server).start() + +print("Server has started. Continuing..") + +browser = webdriver.Chrome() +browser.get("http://localhost:8000") + +assert "" in browser.page_source diff --git a/CLI/skoolos.py b/CLI/skoolos.py index bf46ef4..ae4f1f1 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -3,15 +3,19 @@ from urllib.parse import urlparse import requests from requests_oauthlib import OAuth2Session -from selenium import webdriver; +from selenium import webdriver import os.path import time +import http.server +import socketserver +import threading +from werkzeug.urls import url_decode client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' redirect_uri = 'http://localhost:8000/' token_url = 'https://ion.tjhsst.edu/oauth/token/' -scope=["read"] +scope = ["read"] def main(): @@ -28,20 +32,45 @@ def main(): else: print(open(".profile", "r").read()) + while True: + pass def authenticate(): oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") + + web_dir = os.path.join(os.path.dirname(__file__), 'oauth') + os.chdir(web_dir) + if os.path.exists("index.html"): + os.remove("index.html") + + template = open("template.html", "rt") + index = open("index.html", "wt") + for line in template: + index.write(line.replace('AUTH_URL', authorization_url)) + template.close() + index.close() + + threading.Thread(target=create_server).start() + browser = webdriver.Chrome() - browser.get(authorization_url) + browser.get("localhost:8000/") while "http://localhost:8000/?code" not in browser.current_url: time.sleep(0.25) - code = urlparse(browser.current_url).query[5:] + url = browser.current_url + gets = url_decode(url.replace("http://localhost:8000/?", "")) + code = gets.get("code") + if state == gets.get("state"): + state = gets.get("state") + print("states good") browser.quit() + print(code) + print(state) + payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id, 'client_secret': client_secret, 'csrfmiddlewaretoken': state} token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json() @@ -55,8 +84,14 @@ def authenticate(): # first_name = profile['first_name'] # last_name = profile['last_name'] - #print(profile) + # print(profile) +def create_server(): + port = 8000 + handler = http.server.SimpleHTTPRequestHandler + httpd = socketserver.TCPServer(("", port), handler) + print("serving at port:" + str(port)) + httpd.serve_forever() if __name__ == "__main__": main() From 266ed360f13e6ca66fd70edf326c3c4522f0ef6b Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 9 Jun 2020 15:39:27 -0400 Subject: [PATCH 20/22] bug fix --- CLI/t-git.py | 277 +++++++++++++----- .../api/migrations/0002_auto_20200609_0358.py | 18 ++ Website/api/models.py | 2 +- eharris1/CalculusBS_eharris1/README.md | 0 .../CalculusBS_eharris1/Week1/worksheet1.txt | 0 eharris1/Math4_eharris1/README.md | 0 .../Math4_eharris1/Week1_HW/instructions.txt | 0 .../Math4_eharris1/Week2_HW/instructions.txt | 0 eharris1/Math5_eharris1/README.md | 0 .../Math5_eharris1/Week1_HW/instructions.txt | 0 .../Math5_eharris1/Week2_HW/instructions.txt | 0 11 files changed, 230 insertions(+), 67 deletions(-) create mode 100644 Website/api/migrations/0002_auto_20200609_0358.py delete mode 100644 eharris1/CalculusBS_eharris1/README.md delete mode 100644 eharris1/CalculusBS_eharris1/Week1/worksheet1.txt delete mode 100644 eharris1/Math4_eharris1/README.md delete mode 100644 eharris1/Math4_eharris1/Week1_HW/instructions.txt delete mode 100644 eharris1/Math4_eharris1/Week2_HW/instructions.txt delete mode 100644 eharris1/Math5_eharris1/README.md delete mode 100644 eharris1/Math5_eharris1/Week1_HW/instructions.txt delete mode 100644 eharris1/Math5_eharris1/Week2_HW/instructions.txt diff --git a/CLI/t-git.py b/CLI/t-git.py index e97a0c6..17bac59 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -4,6 +4,8 @@ import requests import webbrowser import pprint import json +import shutil +import time #git clone student directory ==> <student-id>/classes/assignments @@ -26,14 +28,23 @@ def getTeacher(ion_user): def getDB(url): r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) - return r.json() + print("GET:" + str(r.status_code)) + return(r.json()) def postDB(data, url): r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - return(r.status_code) + print("POST:" + str(r.status_code)) + return(r.json()) + def putDB(data, url): - r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) - return(r.status_code) + r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + print("PUT:" + str(r.status_code)) + return(r.json()) + +def delDB(url): + r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + print("DELETE:" + str(r.status_code)) + return None def command(command): ar = [] @@ -42,7 +53,7 @@ def command(command): ar.append(c) process = subprocess.Popen(ar, stdout=subprocess.PIPE,stderr=subprocess.PIPE) p=process.poll() - output = process.communicate()[0] + output = process.communicate()[1] #print(output.decode('utf-8')) class Teacher: @@ -54,46 +65,75 @@ class Teacher: self.git=data['git'] self.username=data['ion_user'] self.url= "http://127.0.0.1:8000/teachers/" + self.username + "/" - self.classes=data['classes'].split(" ") - self.sclass=data['classes'] + #classes in id form (Example: 4,5) + + cid=data['classes'].split(",") + try: + cid.remove('') + except: + pass + try: + cid.remove("") + except: + pass + classes=[] + for c in cid: + url = "http://127.0.0.1:8000/classes/" + str(c) + "/" + classes.append(getDB(url)) + + self.classes = classes + self.sclass=str(data['classes']) if(os.path.isdir(self.username)): - print("Already synced to " + self.username) + print("Synced to " + self.username) else: os.mkdir(self.username) - def checkGit(self, ass): - for a in ass: - if a =='.git': - return True - return False - #update API and Github, all assignments / classes def update(self): #lists all classes + ignore=['.git','.DS_Store'] classes = os.listdir(self.username) - + for i in ignore: + try: + classes.remove(i) + except: + pass + #list of classes that have been deleted (not with deleteClass) + extra = self.classes #checks all class directories first for c in classes: path = self.username + "/" + c if(self.checkClass(path) == False): return - cdict = [] - for c in classes: + ind=0 + for i in range(len(classes)): + print(extra) + c = classes[i] 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): - data = self.addClasstoGit(path) - postDB(data, 'http://127.0.0.1:8000/classes/') + if (self.checkInDB(path)==False): + self.addClass(path) else: #push to git loc = os.getcwd() os.chdir(path) + command('git fetch origin') + command('git pull origin master') command('git add .') command('git commit -m "Update"') command('git push -u origin master') os.chdir(loc) + try: + extra.pop(ind) + ind=i-1 + except: + pass + print(i) + print("EXTRA: " + str(extra)) + ind=ind+1 + for e in extra: + self.deleteClass(e['path']) #class name format: <course-name>_<ion_user> @@ -103,7 +143,7 @@ class Teacher: 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>") + print("Incorrect class name: Must be in the format: " + self.username+ "/<course-name>_<ion_user>, not " + path) return False dirs = os.listdir(path) #checks if there is a file (not within Assignments) in class, need at least 1 @@ -115,15 +155,15 @@ class Teacher: for d in dirs: if(os.path.isfile(d)): deffile=True - if(os.path.isdir(d)) and d != '.git': + else: #checks if there is a file in an Assignment, need at least 1 as_file = False - asdir = os.listdir(d) + asdir = os.listdir(path + "/" + d) for a in asdir: - if(os.path.isfile(a)): + if(os.path.isfile(path + "/" + d + "/" +a)): as_file=True if(as_file==False): - as_bad = a + as_bad = d break if(as_file==False): print("Assignment '" + as_bad + "' does not have a default file!") @@ -133,6 +173,14 @@ class Teacher: print("Need a default file in the " + path + " Directory!") return False return True + + def checkInDB(self, path): + n = path.split("/") + n = n[len(n)-1] + for c in self.classes: + if(n == c['name']): + return True + return False #adds class to git, not API def addClasstoGit(self, path): @@ -143,6 +191,7 @@ class Teacher: if(self.checkClass(path)): if(requests.get(url).status_code != 200): input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n") + time.sleep(2) webbrowser.open('https://github.com/new') input("Repo created? (Press any key to continue)\n") @@ -152,14 +201,25 @@ class Teacher: 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) - command('git init') - command('git add .') - command('git commit -m Hello_Class') - command('git remote add origin ' + url + '.git') - command('git push -u origin master') + cdir = os.getcwd() + os.chdir(path) + command('git init') + command('git add .') + command('git commit -m Hello_Class') + command('git remote add origin ' + url + '.git') + command('git push -u origin master') + else: + cdir = os.getcwd() + os.chdir(path) + print("Repo already exists. Cloning instead.") + command('git clone') + command('git fetch origin') + command('git pull') + command('git add .') + command('git commit -m Hello_Class') + command('git push -u origin master') os.chdir(cdir) + print(cdir) data={ 'name':cname, 'repo':url, @@ -169,40 +229,21 @@ class Teacher: return data return None - - #make a new class from scratch - #subject: string, assignments: list - #class name must be: <subject>_<ion_user> - def makeClass(self, cname, assignments): - cdir = os.getcwd() - os.chdir(self.username) - #check if class exists - if(os.path.exists(cname)): - print("Class already exists: " + cname) - return - else: - if((("_" + self.username) in cname) == False): - print("class name must be: "+ cname + "_" + self.username) - return - path = self.username + "/" + cname - os.mkdir(cname) - f=open(cname + "/README.md", "w") - f.close() - #push to remote repo - os.chdir(cname) - for a in assignments: - os.mkdir(a) - f=open(a + "/instructions.txt", "w") - f.close() - os.chdir(cdir) - + #make class from existing directory, add to git and api + def addClass(self, path): + if (self.checkClass(path)): data = self.addClasstoGit(path) - print(postDB(data, 'http://127.0.0.1:8000/classes/')) + #add class to db + data = postDB(data, 'http://127.0.0.1:8000/classes/') if(len(self.sclass)==0): - classes = cname + classes = data['id'] else: - classes = self.sclass + "," + cname - + classes = self.sclass + "," + str(data['id']) + self.sclass=classes + self.classes.append(data) + print(self.sclass) + print(self.classes) + data={ 'first_name':self.first_name, 'last_name':self.last_name, @@ -211,9 +252,114 @@ class Teacher: 'url':self.url, 'classes':classes } + print(putDB(data, self.url)) + + cid=getDB(self.url)['classes'].split(",") + try: + cid.remove('') + except: + pass + try: + cid.remove("") + except: + pass + classes=[] + for c in cid: + url = "http://127.0.0.1:8000/classes/" + str(c) + "/" + classes.append(getDB(url)) + self.classes = classes + return data + + #make a new class from scratch + #subject: string, assignments: list + #class name must be: <subject>_<ion_user> + def makeClass(self, cname, assignments): + #check if class exists + path = self.username + "/" + cname + if(os.path.exists(path)): + print("Class already exists: " + cname) + return + else: + if((("_" + self.username) in cname) == False): + print("class name must be: "+ cname + "_" + self.username) + return + cdir = os.getcwd() + os.mkdir(path) + f=open(path + "/README.md", "w") + f.close() + #push to remote repo + os.chdir(path) + for a in assignments: + os.mkdir(a) + f=open(a + "/instructions.txt", "w") + f.close() + os.chdir(cdir) + + data = self.addClass(path) + return data + + def deleteClass(self, path): + if(os.path.exists(path) == False): + print(path + " does not exist locally.") + resp = input("Do you want to delete " + path + " from the SkoolOS system? (y/N) ") + if(resp != 'y'): + return + + cname = path.split("/") + cname = cname[len(cname)-1] + cid = None + repo = '' + for c in self.classes: + if cname == c['name']: + cid = str(c['id']) + repo = c['repo'] + print(cid) + #remove from api + + for i in range(len(self.classes)): + if(self.classes[i]['id'] == int(cid)): + del self.classes[i] + s="" + for c in self.classes: + s = s + str(c['id']) + "," + print(s) + s = s[:-1] + print(s) + data={ + 'first_name':self.first_name, + 'last_name':self.last_name, + 'git':self.git, + 'ion_user':self.username, + 'url':self.url, + 'classes':s + } + print(putDB(data, self.url)) + delDB("http://127.0.0.1:8000/classes/" +cid + "/") + break + + #remove locally + try: + shutil.rmtree(path) + except: + pass + + #remove from git + input("Delete repository: " + cname + ". Scroll to the bottom of the page and press 'Delete this repository' (Press any key to continue) ") + print(repo) + time.sleep(2) + webbrowser.open(repo + "/settings") + input("Repo deleted? (Press any key to continue) ") + + print(repo) + while(requests.get(repo).status_code == 200): + print(requests.get(repo)) + r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n") + if(r=="N" or r=="No" or r=='n'): + return None + #make student repo by student id def addStudent(self,stid): print(stid) @@ -223,6 +369,5 @@ class Teacher: data = getTeacher("eharris1") t = Teacher(data) -t.makeClass('Math4_eharris1', ['Week1_HW', 'Week2_HW']) - +t.update() diff --git a/Website/api/migrations/0002_auto_20200609_0358.py b/Website/api/migrations/0002_auto_20200609_0358.py new file mode 100644 index 0000000..bb2af02 --- /dev/null +++ b/Website/api/migrations/0002_auto_20200609_0358.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-09 03:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='teacher', + name='classes', + field=models.CharField(blank=True, default='', max_length=100), + ), + ] diff --git a/Website/api/models.py b/Website/api/models.py index c7881aa..a8770e4 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -36,7 +36,7 @@ class Teacher(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) # classes = models.ManyToManyField(Classes, default="") - classes=models.CharField(max_length=100, default="") + classes=models.CharField(max_length=100, default="", blank=True) ion_user=models.CharField(primary_key=True, max_length=100) git=models.CharField(max_length=100) diff --git a/eharris1/CalculusBS_eharris1/README.md b/eharris1/CalculusBS_eharris1/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/CalculusBS_eharris1/Week1/worksheet1.txt b/eharris1/CalculusBS_eharris1/Week1/worksheet1.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math4_eharris1/README.md b/eharris1/Math4_eharris1/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math4_eharris1/Week1_HW/instructions.txt b/eharris1/Math4_eharris1/Week1_HW/instructions.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math4_eharris1/Week2_HW/instructions.txt b/eharris1/Math4_eharris1/Week2_HW/instructions.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math5_eharris1/README.md b/eharris1/Math5_eharris1/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math5_eharris1/Week1_HW/instructions.txt b/eharris1/Math5_eharris1/Week1_HW/instructions.txt deleted file mode 100644 index e69de29..0000000 diff --git a/eharris1/Math5_eharris1/Week2_HW/instructions.txt b/eharris1/Math5_eharris1/Week2_HW/instructions.txt deleted file mode 100644 index e69de29..0000000 From fc88e6c4c99a5e12485c2ad4fa74eea70721b4b1 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 9 Jun 2020 17:41:31 -0400 Subject: [PATCH 21/22] bug fix2 --- CLI/t-git.py | 163 +++++++++++++++++++++++++-------------------------- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/CLI/t-git.py b/CLI/t-git.py index 17bac59..e1ba43c 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -6,6 +6,7 @@ import pprint import json import shutil import time +import prompt_toolkit.clipboard.pyperclip #git clone student directory ==> <student-id>/classes/assignments @@ -56,6 +57,7 @@ def command(command): output = process.communicate()[1] #print(output.decode('utf-8')) +#public methods: deleteClass, makeClass, update class Teacher: def __init__(self, data): # teacher info already stored in API @@ -99,15 +101,26 @@ class Teacher: except: pass #list of classes that have been deleted (not with deleteClass) - extra = self.classes + extra = [] + for c in self.classes: + extra.append(c) + for i in range(len(extra)): + e = extra[i]['path'] + extra[i] = e + print("Extra: "+str(extra)) + print("Local:" + str(classes)) #checks all class directories first for c in classes: path = self.username + "/" + c if(self.checkClass(path) == False): return - ind=0 + extra.remove(path) + print("Current classes: " + path) + + for e in extra: + self.deleteClass(e) + for i in range(len(classes)): - print(extra) c = classes[i] path = self.username + "/" + c #lists all assignments and default files @@ -124,16 +137,6 @@ class Teacher: command('git commit -m "Update"') command('git push -u origin master') os.chdir(loc) - try: - extra.pop(ind) - ind=i-1 - except: - pass - print(i) - print("EXTRA: " + str(extra)) - ind=ind+1 - for e in extra: - self.deleteClass(e['path']) #class name format: <course-name>_<ion_user> @@ -142,6 +145,9 @@ class Teacher: def checkClass(self,path): cname = path.split("/") cname = cname[len(cname)-1] + if(os.path.isfile(path)): + print(path + " must be in a Class directory.") + return False if(("_" + self.username) in cname) == False: print("Incorrect class name: Must be in the format: " + self.username+ "/<course-name>_<ion_user>, not " + path) return False @@ -183,92 +189,81 @@ class Teacher: return False #adds class to git, not API + #Assuming valid class name def addClasstoGit(self, path): cname = path.split("/") cname = cname[len(cname)-1] #push to remote repo url='https://github.com/' + self.git + "/" + cname - if(self.checkClass(path)): - if(requests.get(url).status_code != 200): - input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n") - time.sleep(2) - webbrowser.open('https://github.com/new') - input("Repo created? (Press any key to continue)\n") + if(requests.get(url).status_code != 200): + input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n") + try: + pyperclip.copy(cname) + spam = pyperclip.paste() + print(cname + " copied to clipboard.") + except: + pass + time.sleep(2) + webbrowser.open('https://github.com/new') + input("Repo created? (Press any key to continue)\n") - 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) - command('git init') - command('git add .') - command('git commit -m Hello_Class') - command('git remote add origin ' + url + '.git') - command('git push -u origin master') - else: - cdir = os.getcwd() - os.chdir(path) - print("Repo already exists. Cloning instead.") - command('git clone') - command('git fetch origin') - command('git pull') - command('git add .') - command('git commit -m Hello_Class') - command('git push -u origin master') - os.chdir(cdir) - print(cdir) - data={ - 'name':cname, - 'repo':url, - 'path':path, - 'teacher':self.username - } - return data - return None + print(url) + while(requests.get(url).status_code != 200): + 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) + command('git init') + command('git add .') + command('git commit -m Hello_Class') + command('git remote add origin ' + url + '.git') + command('git push -u origin master') + else: + cdir = os.getcwd() + os.chdir(path) + print("Repo already exists. Cloning instead.") + command('git clone') + command('git fetch origin') + command('git pull') + command('git add .') + command('git commit -m Hello_Class') + command('git push -u origin master') + os.chdir(cdir) + print(cdir) + data={ + 'name':cname, + 'repo':url, + 'path':path, + 'teacher':self.username + } + return data #make class from existing directory, add to git and api - def addClass(self, path): + def addClass(self, path): + if (self.checkClass(path)): data = self.addClasstoGit(path) - #add class to db + #make class instance in db data = postDB(data, 'http://127.0.0.1:8000/classes/') - if(len(self.sclass)==0): - classes = data['id'] - else: - classes = self.sclass + "," + str(data['id']) - self.sclass=classes + #add to instance + #upate self.classes self.classes.append(data) - print(self.sclass) - print(self.classes) + if(len(self.sclass)==0): + self.sclass = data['id'] + else: + self.sclass = self.sclass + "," + str(data['id']) + #update teacher instance in db, classes field data={ 'first_name':self.first_name, 'last_name':self.last_name, 'git':self.git, 'ion_user':self.username, 'url':self.url, - 'classes':classes + 'classes':self.sclass } - - print(putDB(data, self.url)) - - cid=getDB(self.url)['classes'].split(",") - try: - cid.remove('') - except: - pass - try: - cid.remove("") - except: - pass - classes=[] - for c in cid: - url = "http://127.0.0.1:8000/classes/" + str(c) + "/" - classes.append(getDB(url)) - self.classes = classes + putDB(data, self.url) return data @@ -317,14 +312,15 @@ class Teacher: cid = str(c['id']) repo = c['repo'] print(cid) + #remove from api - for i in range(len(self.classes)): if(self.classes[i]['id'] == int(cid)): + print("DELETE: " + self.classes[i]['name']) del self.classes[i] s="" for c in self.classes: - s = s + str(c['id']) + "," + s = s + str(self.classes[i]['id']) + "," print(s) s = s[:-1] print(s) @@ -337,7 +333,7 @@ class Teacher: 'classes':s } print(putDB(data, self.url)) - delDB("http://127.0.0.1:8000/classes/" +cid + "/") + delDB("http://127.0.0.1:8000/classes/" + cid + "/") break #remove locally @@ -355,7 +351,6 @@ class Teacher: print(repo) while(requests.get(repo).status_code == 200): - print(requests.get(repo)) r = input("Repo still no deleted yet. (Press any key to continue after repo deleted, or 'N' to exit)\n") if(r=="N" or r=="No" or r=='n'): return None @@ -369,5 +364,5 @@ class Teacher: data = getTeacher("eharris1") t = Teacher(data) +t.deleteClass("eharris1/Crypto_eharris1") t.update() - From 7c8ae8ad33787b8ead98f84558223d9531066839 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 9 Jun 2020 18:02:13 -0400 Subject: [PATCH 22/22] teacher fix final --- CLI/t-git.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CLI/t-git.py b/CLI/t-git.py index e1ba43c..9c2f4e9 100644 --- a/CLI/t-git.py +++ b/CLI/t-git.py @@ -6,7 +6,7 @@ import pprint import json import shutil import time -import prompt_toolkit.clipboard.pyperclip +import pyperclip #git clone student directory ==> <student-id>/classes/assignments @@ -199,7 +199,6 @@ class Teacher: input("Make new Git Repo with name: " + cname + " (Press any key to continue)\n") try: pyperclip.copy(cname) - spam = pyperclip.paste() print(cname + " copied to clipboard.") except: pass @@ -241,7 +240,6 @@ class Teacher: #make class from existing directory, add to git and api def addClass(self, path): - if (self.checkClass(path)): data = self.addClasstoGit(path) #make class instance in db @@ -311,7 +309,6 @@ class Teacher: if cname == c['name']: cid = str(c['id']) repo = c['repo'] - print(cid) #remove from api for i in range(len(self.classes)): @@ -319,8 +316,9 @@ class Teacher: print("DELETE: " + self.classes[i]['name']) del self.classes[i] s="" + #recreate sclass field, using ids for c in self.classes: - s = s + str(self.classes[i]['id']) + "," + s = s + str(c['id']) + "," print(s) s = s[:-1] print(s) @@ -364,5 +362,5 @@ class Teacher: data = getTeacher("eharris1") t = Teacher(data) -t.deleteClass("eharris1/Crypto_eharris1") +t.makeClass('English11_eharris1', ["Essay1"]) t.update()