mirror of
https://github.com/Rushilwiz/spaceout.git
synced 2025-04-17 01:50:18 -04:00
Reformatted Code
This commit is contained in:
parent
53b2e4526f
commit
ecfa1eebc2
|
@ -3,4 +3,4 @@ from django.contrib import admin
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
admin.site.register(Profile)
|
admin.site.register(Profile)
|
||||||
admin.site.register(Classroom)
|
admin.site.register(Classroom)
|
||||||
|
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class ApiConfig(AppConfig):
|
class ApiConfig(AppConfig):
|
||||||
name = 'api'
|
name = "api"
|
||||||
|
|
|
@ -16,21 +16,59 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Profile',
|
name="Profile",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('profile_pic', models.ImageField(default='default.jpg', upload_to='profile_pics')),
|
"id",
|
||||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"profile_pic",
|
||||||
|
models.ImageField(default="default.jpg", upload_to="profile_pics"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"user",
|
||||||
|
models.OneToOneField(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to=settings.AUTH_USER_MODEL,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Classroom',
|
name="Classroom",
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
(
|
||||||
('name', models.CharField(max_length=30)),
|
"id",
|
||||||
('teacher', models.CharField(max_length=30)),
|
models.AutoField(
|
||||||
('period', models.CharField(blank=True, max_length=1, unique=True, verbose_name=django.db.models.fields.PositiveIntegerField)),
|
auto_created=True,
|
||||||
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.profile')),
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=30)),
|
||||||
|
("teacher", models.CharField(max_length=30)),
|
||||||
|
(
|
||||||
|
"period",
|
||||||
|
models.CharField(
|
||||||
|
blank=True,
|
||||||
|
max_length=1,
|
||||||
|
unique=True,
|
||||||
|
verbose_name=django.db.models.fields.PositiveIntegerField,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"student",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE, to="api.profile"
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,12 +6,12 @@ from django.db import migrations
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('api', '0001_initial'),
|
("api", "0001_initial"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='profile',
|
model_name="profile",
|
||||||
name='profile_pic',
|
name="profile_pic",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
# Generated by Django 3.1.4 on 2020-12-13 07:46
|
# Generated by Django 3.1.4 on 2020-12-13 07:46
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('api', '0002_remove_profile_profile_pic'),
|
("api", "0002_remove_profile_profile_pic"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='classroom',
|
model_name="classroom",
|
||||||
name='link',
|
name="link",
|
||||||
field=models.CharField(default='https://meet.google.com/', max_length=100),
|
field=models.CharField(default="https://meet.google.com/", max_length=100),
|
||||||
preserve_default=False,
|
preserve_default=False,
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='classroom',
|
model_name="classroom",
|
||||||
name='student',
|
name="student",
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='classes', to='api.profile'),
|
field=models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="classes",
|
||||||
|
to="api.profile",
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,17 +6,17 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('api', '0003_auto_20201213_0246'),
|
("api", "0003_auto_20201213_0246"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='classroom',
|
name="classroom",
|
||||||
options={'ordering': ['period']},
|
options={"ordering": ["period"]},
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='classroom',
|
model_name="classroom",
|
||||||
name='period',
|
name="period",
|
||||||
field=models.PositiveIntegerField(blank=True),
|
field=models.PositiveIntegerField(blank=True),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -22,13 +22,16 @@ class Profile(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Classroom(models.Model):
|
class Classroom(models.Model):
|
||||||
student = models.ForeignKey(Profile, related_name='classes', on_delete=models.CASCADE)
|
student = models.ForeignKey(
|
||||||
|
Profile, related_name="classes", on_delete=models.CASCADE
|
||||||
|
)
|
||||||
name = models.CharField(max_length=30)
|
name = models.CharField(max_length=30)
|
||||||
teacher = models.CharField(max_length=30)
|
teacher = models.CharField(max_length=30)
|
||||||
link = models.CharField(max_length=100)
|
link = models.CharField(max_length=100)
|
||||||
period = models.PositiveIntegerField(blank=True)
|
period = models.PositiveIntegerField(blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.student.user.username}'s Class: {self.name}"
|
return f"{self.student.user.username}'s Class: {self.name}"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['period']
|
ordering = ["period"]
|
||||||
|
|
|
@ -7,13 +7,13 @@ from .models import *
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['id', 'username', 'first_name', 'last_name', 'email']
|
fields = ["id", "username", "first_name", "last_name", "email"]
|
||||||
|
|
||||||
|
|
||||||
class ClassroomSerializer(serializers.ModelSerializer):
|
class ClassroomSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classroom
|
model = Classroom
|
||||||
fields = ['id', 'name', 'teacher', 'link', 'period']
|
fields = ["id", "name", "teacher", "link", "period"]
|
||||||
|
|
||||||
|
|
||||||
class ProfileSerializer(serializers.ModelSerializer):
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
|
@ -22,15 +22,18 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = ['id', 'user', 'classes']
|
fields = ["id", "user", "classes"]
|
||||||
|
|
||||||
|
|
||||||
class ProfileDetailSerializer(serializers.ModelSerializer):
|
class ProfileDetailSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Profile
|
model = Profile
|
||||||
fields = ['id', 'user']
|
fields = ["id", "user"]
|
||||||
|
|
||||||
|
|
||||||
class ClassroomDetailSerializer(serializers.ModelSerializer):
|
class ClassroomDetailSerializer(serializers.ModelSerializer):
|
||||||
student = ProfileDetailSerializer()
|
student = ProfileDetailSerializer()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classroom
|
model = Classroom
|
||||||
fields = ['id', 'name', 'teacher', 'link', 'period', 'student']
|
fields = ["id", "name", "teacher", "link", "period", "student"]
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
from django.db.models.signals import post_save
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def create_profile(sender, instance, created, **kwargs):
|
def create_profile(sender, instance, created, **kwargs):
|
||||||
if created:
|
if created:
|
||||||
Profile.objects.create(user=instance)
|
Profile.objects.create(user=instance)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def save_profile(sender, instance, **kwargs):
|
def save_profile(sender, instance, **kwargs):
|
||||||
instance.profile.save()
|
instance.profile.save()
|
||||||
|
|
|
@ -18,9 +18,9 @@ from django.urls import path
|
||||||
from .views import *
|
from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('ping/', PingView.as_view()),
|
path("ping/", PingView.as_view()),
|
||||||
path('user/', UserView.as_view()),
|
path("user/", UserView.as_view()),
|
||||||
path('profile/', ProfileView.as_view()),
|
path("profile/", ProfileView.as_view()),
|
||||||
path('classes/', ClassroomView.as_view()),
|
path("classes/", ClassroomView.as_view()),
|
||||||
path('classes/<int:class_id>', ClassroomDetail.as_view())
|
path("classes/<int:class_id>", ClassroomDetail.as_view()),
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,12 +9,14 @@ from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from .serializers import *
|
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
|
from .serializers import *
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def retry_on_exception(view, num_retries=3, on_failure=HttpResponse(status=500), delay_=0.5, backoff_=1.5):
|
def retry_on_exception(
|
||||||
|
view, num_retries=3, on_failure=HttpResponse(status=500), delay_=0.5, backoff_=1.5
|
||||||
|
):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def retry(*args, **kwargs):
|
def retry(*args, **kwargs):
|
||||||
delay = delay_
|
delay = delay_
|
||||||
|
@ -24,13 +26,17 @@ def retry_on_exception(view, num_retries=3, on_failure=HttpResponse(status=500),
|
||||||
except OperationalError as ex:
|
except OperationalError as ex:
|
||||||
if i == num_retries - 1:
|
if i == num_retries - 1:
|
||||||
return on_failure
|
return on_failure
|
||||||
elif getattr(ex.__cause__, 'pgcode', '') == errorcodes.SERIALIZATION_FAILURE:
|
elif (
|
||||||
|
getattr(ex.__cause__, "pgcode", "")
|
||||||
|
== errorcodes.SERIALIZATION_FAILURE
|
||||||
|
):
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
delay *= backoff_
|
delay *= backoff_
|
||||||
else:
|
else:
|
||||||
return on_failure
|
return on_failure
|
||||||
except Error as ex:
|
except Error as ex:
|
||||||
return on_failure
|
return on_failure
|
||||||
|
|
||||||
return retry
|
return retry
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,24 +50,27 @@ class UserView(APIView):
|
||||||
serializer = UserSerializer(request.user)
|
serializer = UserSerializer(request.user)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class ProfileView(APIView):
|
class ProfileView(APIView):
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
profile = Profile.objects.get(user=request.user)
|
profile = Profile.objects.get(user=request.user)
|
||||||
serializer = ProfileSerializer(profile)
|
serializer = ProfileSerializer(profile)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class ClassroomView(APIView):
|
class ClassroomView(APIView):
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
classes = Profile.objects.get(user=request.user).classes
|
classes = Profile.objects.get(user=request.user).classes
|
||||||
serializer = ClassroomSerializer(classes, many=True)
|
serializer = ClassroomSerializer(classes, many=True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class ClassroomDetail(APIView):
|
class ClassroomDetail(APIView):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
class_id = self.kwargs.get('class_id', None)
|
class_id = self.kwargs.get("class_id", None)
|
||||||
classroom = Classroom.objects.get(id=class_id)
|
classroom = Classroom.objects.get(id=class_id)
|
||||||
if request.user == classroom.student.user:
|
if request.user == classroom.student.user:
|
||||||
serializer = ClassroomDetailSerializer(classroom)
|
serializer = ClassroomDetailSerializer(classroom)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
else:
|
else:
|
||||||
return Response(status=status.HTTP_403_FORBIDDEN)
|
return Response(status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
|
|
|
@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = '^0n$28f^vwgqqrt2y5o-c3-d8pgzcgv0%uqd%j_c-!!1a(te+!'
|
SECRET_KEY = "^0n$28f^vwgqqrt2y5o-c3-d8pgzcgv0%uqd%j_c-!!1a(te+!"
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
@ -31,74 +31,71 @@ ALLOWED_HOSTS = []
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
'config',
|
"config",
|
||||||
'rest_framework',
|
"rest_framework",
|
||||||
'api',
|
"api",
|
||||||
'djoser',
|
"djoser",
|
||||||
'crispy_forms'
|
"crispy_forms",
|
||||||
]
|
]
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = "bootstrap4"
|
||||||
|
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||||
'rest_framework.authentication.BasicAuthentication',
|
"rest_framework.authentication.BasicAuthentication",
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
"rest_framework.authentication.SessionAuthentication",
|
||||||
),
|
|
||||||
'DEFAULT_PERMISSION_CLASSES': (
|
|
||||||
'rest_framework.permissions.IsAuthenticated',
|
|
||||||
),
|
),
|
||||||
|
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
||||||
}
|
}
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
"django.middleware.security.SecurityMiddleware",
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'config.urls'
|
ROOT_URLCONF = "config.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [BASE_DIR / 'templates']
|
"DIRS": [BASE_DIR / "templates"],
|
||||||
,
|
"APP_DIRS": True,
|
||||||
'APP_DIRS': True,
|
"OPTIONS": {
|
||||||
'OPTIONS': {
|
"context_processors": [
|
||||||
'context_processors': [
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.request",
|
||||||
'django.template.context_processors.request',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.messages.context_processors.messages",
|
||||||
'django.contrib.messages.context_processors.messages',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'config.wsgi.application'
|
WSGI_APPLICATION = "config.wsgi.application"
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
"default": {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
"ENGINE": "django.db.backends.sqlite3",
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
"NAME": BASE_DIR / "db.sqlite3",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#DATABASES = {
|
# DATABASES = {
|
||||||
# 'default': {
|
# 'default': {
|
||||||
# 'ENGINE' : 'django_cockroachdb',
|
# 'ENGINE' : 'django_cockroachdb',
|
||||||
# 'NAME' : 'spaceout',
|
# 'NAME' : 'spaceout',
|
||||||
|
@ -107,7 +104,7 @@ DATABASES = {
|
||||||
# 'HOST' : 'localhost',
|
# 'HOST' : 'localhost',
|
||||||
# 'PORT' : 35767,
|
# 'PORT' : 35767,
|
||||||
# }
|
# }
|
||||||
#}
|
# }
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
|
@ -115,16 +112,16 @@ DATABASES = {
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -132,9 +129,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = "en-us"
|
||||||
|
|
||||||
TIME_ZONE = 'EST'
|
TIME_ZONE = "EST"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
@ -146,12 +143,12 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = "/static/"
|
||||||
|
|
||||||
## Custom
|
## Custom
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
BASE_DIR / 'static',
|
BASE_DIR / "static",
|
||||||
]
|
]
|
||||||
|
|
||||||
LOGIN_REDIRECT_URL = 'home'
|
LOGIN_REDIRECT_URL = "home"
|
||||||
LOGIN_URL = 'login'
|
LOGIN_URL = "login"
|
||||||
|
|
|
@ -15,13 +15,13 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from frontend import urls as frontend_urls
|
|
||||||
|
|
||||||
from api import urls as api_urls
|
from api import urls as api_urls
|
||||||
|
from frontend import urls as frontend_urls
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path('api/', include(api_urls)),
|
path("api/", include(api_urls)),
|
||||||
path('', include(frontend_urls)),
|
path("", include(frontend_urls)),
|
||||||
path('out/', include(frontend_urls)),
|
path("out/", include(frontend_urls)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,6 +11,6 @@ import os
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class FrontendConfig(AppConfig):
|
class FrontendConfig(AppConfig):
|
||||||
name = 'frontend'
|
name = "frontend"
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from api.models import Classroom
|
from api.models import Classroom
|
||||||
|
|
||||||
|
|
||||||
class UserRegisterForm(UserCreationForm):
|
class UserRegisterForm(UserCreationForm):
|
||||||
email = forms.EmailField(label='Email')
|
email = forms.EmailField(label="Email")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['username', 'email', 'password1', 'password2']
|
fields = ["username", "email", "password1", "password2"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(UserRegisterForm, self).__init__(*args, **kwargs)
|
super(UserRegisterForm, self).__init__(*args, **kwargs)
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
self.fields[field].widget.attrs['placeholder'] = self.fields[field].label
|
self.fields[field].widget.attrs["placeholder"] = self.fields[field].label
|
||||||
self.fields[field].widget.attrs['class'] = 'input100'
|
self.fields[field].widget.attrs["class"] = "input100"
|
||||||
|
|
||||||
|
|
||||||
class ClassroomForm(forms.ModelForm):
|
class ClassroomForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Classroom
|
model = Classroom
|
||||||
fields = ['name', 'teacher', 'link', 'period']
|
fields = ["name", "teacher", "link", "period"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(ClassroomForm, self).__init__(*args, **kwargs)
|
super(ClassroomForm, self).__init__(*args, **kwargs)
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
self.fields[field].widget.attrs['placeholder'] = self.fields[field].label
|
self.fields[field].widget.attrs["placeholder"] = self.fields[field].label
|
||||||
self.fields[field].widget.attrs['class'] = 'input100'
|
self.fields[field].widget.attrs["class"] = "input100"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,26 @@ Including another URLconf
|
||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.urls import path
|
|
||||||
from .views import *
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from .views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('login/', auth_views.LoginView.as_view(template_name='frontend/login.html'), name='login'),
|
path(
|
||||||
path('logout/', auth_views.LogoutView.as_view(template_name='frontend/logout.html'), name='logout'),
|
"login/",
|
||||||
path('register/', register_view, name='register'),
|
auth_views.LoginView.as_view(template_name="frontend/login.html"),
|
||||||
path('create_user/', register_view, name='create_user'),
|
name="login",
|
||||||
path('', home_view, name='home'),
|
),
|
||||||
path('classes', class_form_view, name='classroom_form')
|
path(
|
||||||
|
"logout/",
|
||||||
|
auth_views.LogoutView.as_view(template_name="frontend/logout.html"),
|
||||||
|
name="logout",
|
||||||
|
),
|
||||||
|
path("register/", register_view, name="register"),
|
||||||
|
path("create_user/", register_view, name="create_user"),
|
||||||
|
path("", home_view, name="home"),
|
||||||
|
path("classes", class_form_view, name="classroom_form"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.shortcuts import render, redirect
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from .forms import *
|
from django.shortcuts import redirect, render
|
||||||
|
|
||||||
from api.models import *
|
from api.models import *
|
||||||
|
|
||||||
|
from .forms import *
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def register_view(request):
|
def register_view(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = UserRegisterForm(request.POST)
|
form = UserRegisterForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
user = form.save()
|
user = form.save()
|
||||||
|
@ -15,15 +17,27 @@ def register_view(request):
|
||||||
prof = Profile(user=user)
|
prof = Profile(user=user)
|
||||||
prof.save()
|
prof.save()
|
||||||
|
|
||||||
messages.success(request, f'Your account has been created! You are now able to log in')
|
messages.success(
|
||||||
return redirect('login')
|
request, f"Your account has been created! You are now able to log in"
|
||||||
|
)
|
||||||
|
return redirect("login")
|
||||||
else:
|
else:
|
||||||
form = UserRegisterForm()
|
form = UserRegisterForm()
|
||||||
return render(request, 'frontend/register.html', {'form': form})
|
return render(request, "frontend/register.html", {"form": form})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def home_view(request):
|
def home_view(request):
|
||||||
return render(request, 'frontend/temp.html', {'classes': Classroom.objects.filter(student=Profile.objects.get(user=request.user))})
|
return render(
|
||||||
|
request,
|
||||||
|
"frontend/temp.html",
|
||||||
|
{
|
||||||
|
"classes": Classroom.objects.filter(
|
||||||
|
student=Profile.objects.get(user=request.user)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def class_form_view(request):
|
def class_form_view(request):
|
||||||
|
@ -32,15 +46,15 @@ def class_form_view(request):
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
class_i = Classroom(
|
class_i = Classroom(
|
||||||
student=Profile.objects.get(user=request.user),
|
student=Profile.objects.get(user=request.user),
|
||||||
name=form.cleaned_data.get('name'),
|
name=form.cleaned_data.get("name"),
|
||||||
teacher=form.cleaned_data.get('teacher'),
|
teacher=form.cleaned_data.get("teacher"),
|
||||||
link=form.cleaned_data.get('link'),
|
link=form.cleaned_data.get("link"),
|
||||||
period=form.cleaned_data.get('period'),
|
period=form.cleaned_data.get("period"),
|
||||||
)
|
)
|
||||||
class_i.save()
|
class_i.save()
|
||||||
return redirect('home')
|
return redirect("home")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
form = ClassroomForm
|
form = ClassroomForm
|
||||||
|
|
||||||
return render(request, 'frontend/classroomForm.html', {'form': form})
|
return render(request, "frontend/classroomForm.html", {"form": form})
|
||||||
|
|
|
@ -6,7 +6,7 @@ import sys
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
@ -18,5 +18,5 @@ def main():
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user