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