diff --git a/equipment_tracker/accounts/admin.py b/equipment_tracker/accounts/admin.py index c7b0b42..844f17a 100644 --- a/equipment_tracker/accounts/admin.py +++ b/equipment_tracker/accounts/admin.py @@ -9,7 +9,7 @@ class CustomUserAdmin(UserAdmin): list_display = UserAdmin.list_display + \ ('is_technician', 'is_teacher', 'id') fieldsets = UserAdmin.fieldsets + ( - (None, {'fields': ('is_technician', 'is_teacher')}), + (None, {'fields': ('is_technician', 'is_teacher', 'course')}), ) diff --git a/equipment_tracker/accounts/migrations/0001_initial.py b/equipment_tracker/accounts/migrations/0001_initial.py index c9975de..718073b 100644 --- a/equipment_tracker/accounts/migrations/0001_initial.py +++ b/equipment_tracker/accounts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.7 on 2023-12-08 14:41 +# Generated by Django 4.2.7 on 2023-12-29 10:21 import accounts.models import django.contrib.auth.models @@ -32,6 +32,7 @@ class Migration(migrations.Migration): ('is_active', models.BooleanField(default=False)), ('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)), ('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/models.py b/equipment_tracker/accounts/models.py index c9dd977..1a94350 100644 --- a/equipment_tracker/accounts/models.py +++ b/equipment_tracker/accounts/models.py @@ -39,6 +39,16 @@ class CustomUser(AbstractUser): is_active = models.BooleanField(default=False) is_technician = models.BooleanField(default=False) is_teacher = models.BooleanField(default=False) + + COURSE_CHOICES = ( + ('BS Chemistry', 'BS Chemistry'), + ('BS Food Technology', 'BS Food Technology'), + ('BS Applied Physics', 'BS Applied Physics'), + ('BS Environmental Science', 'BS Environmental Science'), + ) + + course = models.CharField( + max_length=60, null=True, choices=COURSE_CHOICES, default=None) avatar = models.ImageField(upload_to=_get_upload_to, null=True) @property @@ -108,7 +118,7 @@ def create_superuser(sender, **kwargs): if not User.objects.filter(username=username).exists(): # Create the superuser with is_active set to False user = User.objects.create_user( - username=username, email=email, password=password, first_name=first_name, last_name=last_name) + username=username, email=email, password=password, first_name=first_name, last_name=last_name, course="BS Chemistry") # Activate the user user.is_active = True diff --git a/equipment_tracker/accounts/serializers.py b/equipment_tracker/accounts/serializers.py index f2a6410..9e7bf89 100644 --- a/equipment_tracker/accounts/serializers.py +++ b/equipment_tracker/accounts/serializers.py @@ -24,12 +24,14 @@ class CustomUserSerializer(BaseUserSerializer): class UserRegistrationSerializer(serializers.ModelSerializer): email = serializers.EmailField(required=True) + course = serializers.ChoiceField( + choices=CustomUser.COURSE_CHOICES, required=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', + fields = ('username', 'email', 'password', 'avatar', 'course', 'first_name', 'last_name') read_only_fields = ('is_teacher', 'is_technician') diff --git a/equipment_tracker/breakages/migrations/0001_initial.py b/equipment_tracker/breakages/migrations/0001_initial.py index de2644c..6e10fa7 100644 --- a/equipment_tracker/breakages/migrations/0001_initial.py +++ b/equipment_tracker/breakages/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.7 on 2023-12-08 15:33 +# Generated by Django 4.2.7 on 2023-12-29 10:09 from django.db import migrations, models import django.db.models.deletion @@ -10,8 +10,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('transactions', '0001_initial'), ('equipments', '0001_initial'), + ('transactions', '0001_initial'), ] operations = [ diff --git a/equipment_tracker/equipments/migrations/0001_initial.py b/equipment_tracker/equipments/migrations/0001_initial.py index 33f3ba8..982e758 100644 --- a/equipment_tracker/equipments/migrations/0001_initial.py +++ b/equipment_tracker/equipments/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.7 on 2023-12-08 14:41 +# Generated by Django 4.2.7 on 2023-12-29 10:09 from django.conf import settings from django.db import migrations, models @@ -31,7 +31,7 @@ class Migration(migrations.Migration): name='HistoricalEquipmentInstance', fields=[ ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), - ('status', models.CharField(choices=[('Working', 'Working'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='PENDING', max_length=20)), + ('status', models.CharField(choices=[('Available', 'Available'), ('Pending', 'Pending'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='Available', max_length=20)), ('remarks', models.TextField(max_length=512, null=True)), ('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)), ('last_updated', models.DateTimeField(blank=True, editable=False)), @@ -77,7 +77,7 @@ class Migration(migrations.Migration): name='EquipmentInstance', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('status', models.CharField(choices=[('Working', 'Working'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='PENDING', max_length=20)), + ('status', models.CharField(choices=[('Available', 'Available'), ('Pending', 'Pending'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='Available', max_length=20)), ('remarks', models.TextField(max_length=512, null=True)), ('date_added', models.DateTimeField(default=django.utils.timezone.now, editable=False)), ('last_updated', models.DateTimeField(auto_now=True)), diff --git a/equipment_tracker/equipments/migrations/0002_alter_equipmentinstance_status_and_more.py b/equipment_tracker/equipments/migrations/0002_alter_equipmentinstance_status_and_more.py deleted file mode 100644 index 864064f..0000000 --- a/equipment_tracker/equipments/migrations/0002_alter_equipmentinstance_status_and_more.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-16 06:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('equipments', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='equipmentinstance', - name='status', - field=models.CharField(choices=[('Available', 'Available'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='Available', max_length=20), - ), - migrations.AlterField( - model_name='historicalequipmentinstance', - name='status', - field=models.CharField(choices=[('Available', 'Available'), ('Broken', 'Broken'), ('Borrowed', 'Borrowed')], default='Available', max_length=20), - ), - ] diff --git a/equipment_tracker/schema.yml b/equipment_tracker/schema.yml index 6ac770c..ff56ada 100644 --- a/equipment_tracker/schema.yml +++ b/equipment_tracker/schema.yml @@ -1201,6 +1201,18 @@ components: required: - cleared - uncleared_transactions + CourseEnum: + enum: + - BS Chemistry + - BS Food Technology + - BS Applied Physics + - BS Environmental Science + type: string + description: |- + * `BS Chemistry` - BS Chemistry + * `BS Food Technology` - BS Food Technology + * `BS Applied Physics` - BS Applied Physics + * `BS Environmental Science` - BS Environmental Science CustomUser: type: object properties: @@ -1565,6 +1577,8 @@ components: type: integer teacher: type: integer + subject: + type: string equipments: type: array items: @@ -1674,6 +1688,8 @@ components: type: integer teacher: type: integer + subject: + type: string equipments: type: array items: @@ -1692,6 +1708,7 @@ components: - borrower - equipments - id + - subject - teacher - timestamp - transaction_status @@ -1734,6 +1751,8 @@ components: type: string format: uri nullable: true + course: + $ref: '#/components/schemas/CourseEnum' first_name: type: string maxLength: 100 @@ -1741,6 +1760,7 @@ components: type: string maxLength: 100 required: + - course - email - first_name - last_name diff --git a/equipment_tracker/transactions/migrations/0001_initial.py b/equipment_tracker/transactions/migrations/0001_initial.py index eccc11a..d7f1b8c 100644 --- a/equipment_tracker/transactions/migrations/0001_initial.py +++ b/equipment_tracker/transactions/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.7 on 2023-12-08 14:41 +# Generated by Django 4.2.7 on 2023-12-29 10:09 from django.conf import settings from django.db import migrations, models @@ -20,7 +20,9 @@ class Migration(migrations.Migration): name='Transaction', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('remarks', models.TextField(max_length=512, null=True)), ('transaction_status', models.CharField(choices=[('Pending Approval', 'Pending Approval'), ('Approved', 'Approved'), ('Rejected', 'Rejected'), ('Cancelled', 'Cancelled'), ('Borrowed', 'Borrowed'), ('Returned: Pending Checking', 'Returned: Pending Checking'), ('With Breakages: Pending Resolution', 'With Breakages: Pending Resolution'), ('Finalized', 'Finalized')], default='Pending', max_length=40)), + ('subject', models.TextField(max_length=128)), ('timestamp', models.DateTimeField(default=django.utils.timezone.now, editable=False)), ('borrower', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='borrowed_transactions', to=settings.AUTH_USER_MODEL)), ('equipments', models.ManyToManyField(to='equipments.equipmentinstance')), diff --git a/equipment_tracker/transactions/migrations/0002_transaction_remarks.py b/equipment_tracker/transactions/migrations/0002_transaction_remarks.py deleted file mode 100644 index d2b8464..0000000 --- a/equipment_tracker/transactions/migrations/0002_transaction_remarks.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.7 on 2023-12-08 15:55 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('transactions', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='transaction', - name='remarks', - field=models.TextField(max_length=512, null=True), - ), - ] diff --git a/equipment_tracker/transactions/models.py b/equipment_tracker/transactions/models.py index 21180c1..588963e 100644 --- a/equipment_tracker/transactions/models.py +++ b/equipment_tracker/transactions/models.py @@ -33,6 +33,7 @@ class Transaction(models.Model): equipments = models.ManyToManyField(EquipmentInstance) transaction_status = models.CharField( max_length=40, choices=TRANSACTION_STATUS_CHOICES, default='Pending') + subject = models.TextField(max_length=128) timestamp = models.DateTimeField(default=now, editable=False) def __str__(self): diff --git a/equipment_tracker/transactions/serializers.py b/equipment_tracker/transactions/serializers.py index 54c954e..8d956b1 100644 --- a/equipment_tracker/transactions/serializers.py +++ b/equipment_tracker/transactions/serializers.py @@ -30,6 +30,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer): many=False, slug_field='id', queryset=CustomUser.objects.all(), required=True, allow_null=False) equipments = serializers.SlugRelatedField( many=True, slug_field='id', queryset=EquipmentInstance.objects.all(), required=True) + subject = serializers.CharField(required=True, allow_null=False) timestamp = serializers.DateTimeField( format="%m-%d-%Y %I:%M %p", read_only=True) @@ -38,7 +39,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Transaction - fields = ['id', 'borrower', 'teacher', + fields = ['id', 'borrower', 'teacher', 'subject', 'equipments', 'remarks', 'transaction_status', 'timestamp'] read_only_fields = ['id', 'timestamp'] @@ -149,6 +150,13 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer): "You cannot change the equipments of an already created transaction" ) + # Subject Validation + # Do not allow changes to subject on created transactions + if 'subject' in validated_data: + raise serializers.ValidationError( + "You cannot change the subject of an already created transaction" + ) + # Transaction Status Validation # Check if the update involves the transaction status if 'transaction_status' in validated_data: