diff --git a/stude/accounts/migrations/0002_studentstatus.py b/stude/accounts/migrations/0002_studentstatus.py new file mode 100644 index 0000000..7eb3b60 --- /dev/null +++ b/stude/accounts/migrations/0002_studentstatus.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.2 on 2023-06-26 13:46 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='StudentStatus', + fields=[ + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('x_latitude', models.FloatField(null=True)), + ('y_latitude', models.FloatField(null=True)), + ('subject', models.CharField(max_length=100)), + ('year_level', models.CharField(choices=[('1st', '1st year'), ('2nd', '2nd year'), ('3rd', '3rd year'), ('4th', '4th year'), ('5th', '5th Year'), ('Irreg', 'Irregular')], max_length=50)), + ('semester', models.CharField(choices=[('1st', '1st semester'), ('2nd', '2nd semester')], max_length=50)), + ('timestamp', models.DateField(auto_now_add=True)), + ], + ), + ] diff --git a/stude/accounts/migrations/0003_delete_studentstatus.py b/stude/accounts/migrations/0003_delete_studentstatus.py new file mode 100644 index 0000000..c8084c1 --- /dev/null +++ b/stude/accounts/migrations/0003_delete_studentstatus.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.2 on 2023-06-26 14:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0002_studentstatus'), + ] + + operations = [ + migrations.DeleteModel( + name='StudentStatus', + ), + ] diff --git a/stude/accounts/models.py b/stude/accounts/models.py index 218b8ba..ad9cb4f 100644 --- a/stude/accounts/models.py +++ b/stude/accounts/models.py @@ -14,15 +14,6 @@ def validate_student_id(value): class CustomUser(AbstractUser): - def _get_upload_to(instance, filename): - base_filename, file_extension = os.path.splitext(filename) - # Convert filename to a slug format - cleaned_filename = slugify(base_filename) - # Get the student ID number - student_id = str(instance.student_id_number) - new_filename = f"{student_id}_{cleaned_filename}{file_extension}" - return os.path.join('avatars', new_filename) - YEAR_LEVELS = ( ('1st', '1st year'), ('2nd', '2nd year'), @@ -35,6 +26,16 @@ class CustomUser(AbstractUser): ('1st', '1st semester'), ('2nd', '2nd semester'), ) + + def _get_upload_to(instance, filename): + base_filename, file_extension = os.path.splitext(filename) + # Convert filename to a slug format + cleaned_filename = slugify(base_filename) + # Get the student ID number + student_id = str(instance.student_id_number) + new_filename = f"{student_id}_{cleaned_filename}{file_extension}" + return os.path.join('avatars', new_filename) + first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) # Email inherited from base user class diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index 7d07f33..4659fa8 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -1,15 +1,20 @@ from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer from djoser.serializers import UserSerializer as BaseUserSerializer from accounts.models import CustomUser +from student_status.serializers import StudentStatusSerializer class CustomUserSerializer(BaseUserSerializer): + user_status = StudentStatusSerializer( + source='studentstatus', read_only=True) + class Meta(BaseUserSerializer.Meta): model = CustomUser - fields = '__all__' + fields = ('username', 'email', 'password', + 'student_id_number', 'year_level', 'semester', 'avatar', 'is_banned', 'user_status') class UserRegistrationSerializer(BaseUserRegistrationSerializer): class Meta(BaseUserRegistrationSerializer.Meta): fields = ('username', 'email', 'password', - 'is_student', 'student_id_number', 'year_level', 'semester', 'avatar') + 'student_id_number', 'year_level', 'semester', 'avatar') diff --git a/stude/accounts/urls.py b/stude/accounts/urls.py index 5c53f15..8df3791 100644 --- a/stude/accounts/urls.py +++ b/stude/accounts/urls.py @@ -3,5 +3,5 @@ from django.urls import path, include urlpatterns = [ path('', include('djoser.urls')), - path('', include('djoser.urls.authtoken')) + path('', include('djoser.urls.authtoken')), ] diff --git a/stude/config/settings.py b/stude/config/settings.py index 0c8500d..9ce413f 100644 --- a/stude/config/settings.py +++ b/stude/config/settings.py @@ -62,7 +62,7 @@ INSTALLED_APPS = [ 'djoser', 'rest_framework.authtoken', 'accounts', - + 'student_status', ] MIDDLEWARE = [ diff --git a/stude/student_status/__init__.py b/stude/student_status/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stude/student_status/admin.py b/stude/student_status/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/stude/student_status/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/stude/student_status/apps.py b/stude/student_status/apps.py new file mode 100644 index 0000000..74ae38d --- /dev/null +++ b/stude/student_status/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class StudentStatusConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'student_status' diff --git a/stude/student_status/migrations/0001_initial.py b/stude/student_status/migrations/0001_initial.py new file mode 100644 index 0000000..5425574 --- /dev/null +++ b/stude/student_status/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.2 on 2023-06-26 14:03 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('accounts', '0003_delete_studentstatus'), + ] + + operations = [ + migrations.CreateModel( + name='StudentStatus', + fields=[ + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('x_latitude', models.FloatField(null=True)), + ('y_latitude', models.FloatField(null=True)), + ('subject', models.CharField(max_length=100)), + ('year_level', models.CharField(choices=[('1st', '1st year'), ('2nd', '2nd year'), ('3rd', '3rd year'), ('4th', '4th year'), ('5th', '5th Year'), ('Irreg', 'Irregular')], max_length=50)), + ('semester', models.CharField(choices=[('1st', '1st semester'), ('2nd', '2nd semester')], max_length=50)), + ('timestamp', models.DateField(auto_now_add=True)), + ], + ), + ] diff --git a/stude/student_status/migrations/__init__.py b/stude/student_status/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stude/student_status/models.py b/stude/student_status/models.py new file mode 100644 index 0000000..cf1c9cf --- /dev/null +++ b/stude/student_status/models.py @@ -0,0 +1,28 @@ +from django.db import models +from accounts.models import CustomUser + +# Create your models here. + + +class StudentStatus(models.Model): + YEAR_LEVELS = ( + ('1st', '1st year'), + ('2nd', '2nd year'), + ('3rd', '3rd year'), + ('4th', '4th year'), + ('5th', '5th Year'), + ('Irreg', 'Irregular'), + ) + SEMESTERS = ( + ('1st', '1st semester'), + ('2nd', '2nd semester'), + ) + user = models.OneToOneField( + CustomUser, on_delete=models.CASCADE, primary_key=True) + x_latitude = models.FloatField(null=True) + y_latitude = models.FloatField(null=True) + subject = models.CharField(max_length=100) + year_level = models.CharField( + max_length=50, choices=CustomUser.YEAR_LEVELS) + semester = models.CharField(max_length=50, choices=CustomUser.SEMESTERS) + timestamp = models.DateField(auto_now_add=True) diff --git a/stude/student_status/serializers.py b/stude/student_status/serializers.py new file mode 100644 index 0000000..151deaf --- /dev/null +++ b/stude/student_status/serializers.py @@ -0,0 +1,9 @@ +from rest_framework import serializers +from student_status.models import StudentStatus + + +class StudentStatusSerializer(serializers.ModelSerializer): + class Meta: + model = StudentStatus + fields = ('x_latitude', 'y_latitude', 'subject', + 'year_level', 'semester', 'timestamp') diff --git a/stude/student_status/tests.py b/stude/student_status/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/stude/student_status/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/stude/student_status/views.py b/stude/student_status/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/stude/student_status/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.