From 4a26f6ae3e1dee047d8eb6b97971fa5da29ad12c Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 14 Jan 2024 20:13:19 +0800 Subject: [PATCH 1/3] Remove brand from equipment name --- equipment_tracker/equipments/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/equipment_tracker/equipments/models.py b/equipment_tracker/equipments/models.py index fe7fa45..dc14018 100644 --- a/equipment_tracker/equipments/models.py +++ b/equipment_tracker/equipments/models.py @@ -80,7 +80,7 @@ def create_superuser(sender, **kwargs): # Get equipment information category = filename.split('-')[0] - name = row[2] + ' ' + row[1] + name = row[1] # If quantity is missing, set value as 0 if (row[3] == ''): available = 0 From 85fb48935270c0e9e6076dc317ab6e510d7d235d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 14 Jan 2024 20:57:27 +0800 Subject: [PATCH 2/3] Remove avatar field in user and add section field --- .../accounts/migrations/0001_initial.py | 7 ++- .../__pycache__/0001_initial.cpython-311.pyc | Bin 4097 -> 3978 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 164 -> 164 bytes equipment_tracker/accounts/models.py | 29 ++--------- equipment_tracker/accounts/serializers.py | 21 ++++---- .../__pycache__/0001_initial.cpython-311.pyc | Bin 5484 -> 5484 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 166 -> 166 bytes equipment_tracker/schema.yml | 45 +++++++++++++----- 8 files changed, 49 insertions(+), 53 deletions(-) diff --git a/equipment_tracker/accounts/migrations/0001_initial.py b/equipment_tracker/accounts/migrations/0001_initial.py index d5bd51e..2b5a61b 100644 --- a/equipment_tracker/accounts/migrations/0001_initial.py +++ b/equipment_tracker/accounts/migrations/0001_initial.py @@ -1,10 +1,9 @@ -# Generated by Django 4.2.7 on 2024-01-05 10:26 +# Generated by Django 5.0.1 on 2024-01-14 12:55 -import accounts.models import django.contrib.auth.models import django.contrib.auth.validators -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): @@ -33,7 +32,7 @@ class Migration(migrations.Migration): ('is_technician', models.BooleanField(default=False)), ('is_teacher', models.BooleanField(default=False)), ('course', models.CharField(choices=[('BS Chemistry', 'BS Chemistry'), ('BS Food Technology', 'BS Food Technology'), ('BS Applied Physics', 'BS Applied Physics'), ('BS Environmental Science', 'BS Environmental Science')], default=None, max_length=60, null=True)), - ('avatar', models.ImageField(null=True, upload_to=accounts.models.CustomUser._get_upload_to)), + ('section', models.CharField(default=None, max_length=60, null=True)), ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), ], diff --git a/equipment_tracker/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc b/equipment_tracker/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc index c2f55996979d6dde3ae7b5d74ee56ef682cb589f..fdb8fbc4f4f3ac6609d49c61de251f9cbfa377f9 100644 GIT binary patch delta 444 zcmZov=#uAM&dbZi00ftBE>2CJ$SWBV0_03*NMT4}%wdRP1k+4Vni)(p<*?+kMzQ9y zMX@n5Ffq6@q%gNIq_Cv2X0d||0)b`B3=FG*7y_c$CpK9yF50+z7n3F@OfW?!MK^_U zjRC6CG^P|oCWch@EYZokm~|ONC%<40WfYrykWqMYAd4EK_~r_h^~{p&#i_|9nfZB| z%thir^NNH(geZ{M?7&gP$S5&+Gv|ZJ`?$*4K(-Z^Z?@*HVUm`*Afq$G?TU=fhL8hE zCrU2Jgj|#fxgryCK_GPU4c;fbAb%IJ0SQfxTT+wwML2TvQ&Mw^i##X)=2NK`P032k zOV8IUEy>I&)+@=(O|8n$OTEPj6;4Si0(rNH1!hQ5Fo*>@{DcO delta 595 zcmeB@Z&cu2&dbZi00c}TGgA*w%&ti5Y*0C% zaYX-$Q_K~o>aL4c%anxd20x{rD|dK(+z^77&`6 diff --git a/equipment_tracker/accounts/migrations/__pycache__/__init__.cpython-311.pyc b/equipment_tracker/accounts/migrations/__pycache__/__init__.cpython-311.pyc index 17377aa4abd1d6e79a23293852efdbb5171481a7..5a70566f76e3a97896eb42da597017f999969201 100644 GIT binary patch delta 19 ZcmZ3&xP*~=IWI340}vEu=T79F2>>gS1fKu^ delta 19 ZcmZ3&xP*~=IWI340}%XLQ#X-&CIB!|1$qDg diff --git a/equipment_tracker/accounts/models.py b/equipment_tracker/accounts/models.py index 1a94350..113c6e7 100644 --- a/equipment_tracker/accounts/models.py +++ b/equipment_tracker/accounts/models.py @@ -1,35 +1,12 @@ -from django.db import models + +from django.db.models.signals import post_migrate from django.contrib.auth.models import AbstractUser from django.db import models -from django.db.models.signals import post_migrate from django.dispatch import receiver import os -from uuid import uuid4 class CustomUser(AbstractUser): - # Function for avatar uploads - def _get_upload_to(instance, filename): - base_filename, file_extension = os.path.splitext(filename) - # Get the student ID number - ext = base_filename.split('.')[-1] - filename = '{}.{}'.format(uuid4().hex, ext) - - student_id = str(instance.student_id_number) - new_filename = f"{student_id}_{filename}_{file_extension}" - return os.path.join('avatars', new_filename) - - # Delete old avatar file if new one is uploaded - def save(self, *args, **kwargs): - try: - # is the object in the database yet? - this = CustomUser.objects.get(id=self.id) - if this.avatar != self.avatar: - this.avatar.delete(save=False) - except: - pass # when new photo then we do nothing, normal case - super(CustomUser, self).save(*args, **kwargs) - first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) # Email inherited from base user class @@ -49,7 +26,7 @@ class CustomUser(AbstractUser): course = models.CharField( max_length=60, null=True, choices=COURSE_CHOICES, default=None) - avatar = models.ImageField(upload_to=_get_upload_to, null=True) + section = models.CharField(max_length=60, null=True, default=None) @property def full_name(self): diff --git a/equipment_tracker/accounts/serializers.py b/equipment_tracker/accounts/serializers.py index 9e7bf89..9130474 100644 --- a/equipment_tracker/accounts/serializers.py +++ b/equipment_tracker/accounts/serializers.py @@ -1,39 +1,38 @@ -from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer from djoser.serializers import UserSerializer as BaseUserSerializer from django.core import exceptions as django_exceptions from rest_framework import serializers from accounts.models import CustomUser from rest_framework.settings import api_settings from django.contrib.auth.password_validation import validate_password -from django.utils.encoding import smart_str -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes -from drf_extra_fields.fields import Base64ImageField - # There can be multiple subject instances with the same name, only differing in course, year level, and semester. We filter them here class CustomUserSerializer(BaseUserSerializer): - avatar = Base64ImageField() + course = serializers.ChoiceField( + choices=CustomUser.COURSE_CHOICES, allow_blank=True, allow_null=True) + section = serializers.CharField(allow_blank=True, allow_null=True) class Meta(BaseUserSerializer.Meta): model = CustomUser - fields = ('id', 'username', 'email', 'avatar', 'first_name', + fields = ('id', 'username', 'email', 'first_name', 'course', 'section', 'last_name', 'is_teacher', 'is_technician') + read_only_fields = ('id', 'username', 'email', + 'is_teacher', 'is_technician') class UserRegistrationSerializer(serializers.ModelSerializer): email = serializers.EmailField(required=True) course = serializers.ChoiceField( - choices=CustomUser.COURSE_CHOICES, required=True) + choices=CustomUser.COURSE_CHOICES, allow_blank=True, allow_null=True) + section = serializers.CharField(allow_blank=True, allow_null=True) password = serializers.CharField( write_only=True, style={'input_type': 'password', 'placeholder': 'Password'}) class Meta: model = CustomUser # Use your custom user model here - fields = ('username', 'email', 'password', 'avatar', 'course', + fields = ('username', 'email', 'password', 'course', 'section', 'first_name', 'last_name') - read_only_fields = ('is_teacher', 'is_technician') + read_only_fields = ('username', 'email', 'is_teacher', 'is_technician') def validate(self, attrs): user = self.Meta.model(**attrs) diff --git a/equipment_tracker/equipments/migrations/__pycache__/0001_initial.cpython-311.pyc b/equipment_tracker/equipments/migrations/__pycache__/0001_initial.cpython-311.pyc index f0376dc6b1563ff46e14e0833614a91fb4a4f340..c4c6e3cb626f5f7333e1f83a1116a30f92ad81ca 100644 GIT binary patch delta 20 acmaE(^+t<(IWI340}w>soW7AeQ4|0}hz0%t delta 20 acmaE(^+t<(IWI340}wEY%-qPGC<*{PlLX`d diff --git a/equipment_tracker/equipments/migrations/__pycache__/__init__.cpython-311.pyc b/equipment_tracker/equipments/migrations/__pycache__/__init__.cpython-311.pyc index b83f87dd5c19d5e022f6230ef82203aa14c051fe..2c4bf8882464475278652d9c881a71c50d3c238c 100644 GIT binary patch delta 19 ZcmZ3+xQvl|IWI340}vEu=T79F4FD_L1f>7~ delta 19 ZcmZ3+xQvl|IWI340}%XLQ#X-&HUKc21%Lnm diff --git a/equipment_tracker/schema.yml b/equipment_tracker/schema.yml index 190c3e3..d19016d 100644 --- a/equipment_tracker/schema.yml +++ b/equipment_tracker/schema.yml @@ -1139,6 +1139,9 @@ components: required: - token - uid + BlankEnum: + enum: + - '' BreakageReport: type: object properties: @@ -1210,12 +1213,18 @@ components: format: email title: Email address maxLength: 254 - avatar: - type: string - format: uri first_name: type: string maxLength: 100 + course: + nullable: true + oneOf: + - $ref: '#/components/schemas/CourseEnum' + - $ref: '#/components/schemas/NullEnum' + section: + type: string + nullable: true + maxLength: 60 last_name: type: string maxLength: 100 @@ -1224,7 +1233,6 @@ components: is_technician: type: boolean required: - - avatar - first_name - id - last_name @@ -1448,6 +1456,9 @@ components: - history_user - id - name + NullEnum: + enum: + - null PasswordResetConfirm: type: object properties: @@ -1477,12 +1488,18 @@ components: format: email title: Email address maxLength: 254 - avatar: - type: string - format: uri first_name: type: string maxLength: 100 + course: + nullable: true + oneOf: + - $ref: '#/components/schemas/CourseEnum' + - $ref: '#/components/schemas/NullEnum' + section: + type: string + nullable: true + maxLength: 60 last_name: type: string maxLength: 100 @@ -1731,12 +1748,15 @@ components: password: type: string writeOnly: true - avatar: - type: string - format: uri - nullable: true course: - $ref: '#/components/schemas/CourseEnum' + nullable: true + oneOf: + - $ref: '#/components/schemas/CourseEnum' + - $ref: '#/components/schemas/BlankEnum' + - $ref: '#/components/schemas/NullEnum' + section: + type: string + nullable: true first_name: type: string maxLength: 100 @@ -1749,6 +1769,7 @@ components: - first_name - last_name - password + - section - username UsernameResetConfirm: type: object From 7b511e0d8cdad1dd80c20a02780e15ba70a957bf Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 14 Jan 2024 21:05:08 +0800 Subject: [PATCH 3/3] Remove section field from transactions. This should be in the user model instead --- .../__pycache__/0001_initial.cpython-311.pyc | Bin 3978 -> 3978 bytes .../migrations/0003_transaction_section.py | 18 ------------------ equipment_tracker/transactions/models.py | 1 - equipment_tracker/transactions/serializers.py | 3 +-- 4 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 equipment_tracker/transactions/migrations/0003_transaction_section.py diff --git a/equipment_tracker/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc b/equipment_tracker/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc index fdb8fbc4f4f3ac6609d49c61de251f9cbfa377f9..945b698509c4f7130020085243156a082c0d6e10 100644 GIT binary patch delta 19 ZcmeB@?~>