diff --git a/stude/accounts/management/commands/clean_old_entries.py b/stude/accounts/management/commands/clean_old_entries.py new file mode 100644 index 0000000..40bd156 --- /dev/null +++ b/stude/accounts/management/commands/clean_old_entries.py @@ -0,0 +1,34 @@ +from django.core.management.base import BaseCommand +from django.utils import timezone +from django.contrib.gis.geos import Point +from study_groups.models import StudyGroup +from student_status.models import StudentStatus + + +class Command(BaseCommand): + help = 'Removes old study groups and resets old student statuses' + + def handle(self, *args, **kwargs): + # Get the current time + now = timezone.now() + + # Get the time 8 hours ago + time_threshold = now - timezone.timedelta(hours=8) + + # Delete StudyGroup entries older than 8 hours + StudyGroup.objects.filter(timestamp__lt=time_threshold).delete() + + # Get StudentStatus entries older than 8 hours + old_statuses = StudentStatus.objects.filter( + timestamp__lt=time_threshold) + + # Set the fields of the old statuses to the required values + for status in old_statuses: + status.location = Point(0, 0) + status.subject = None + status.landmark = None + status.study_group = None + status.save() + + self.stdout.write(self.style.SUCCESS( + 'Successfully cleaned old entries')) diff --git a/stude/accounts/migrations/0004_alter_customuser_options_and_more.py b/stude/accounts/migrations/0004_alter_customuser_options_and_more.py new file mode 100644 index 0000000..b322b02 --- /dev/null +++ b/stude/accounts/migrations/0004_alter_customuser_options_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.3 on 2023-10-01 05:25 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0003_alter_customuser_options_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='customuser', + options={'verbose_name': 'user', 'verbose_name_plural': 'users'}, + ), + migrations.AlterUniqueTogether( + name='customuser', + unique_together=set(), + ), + ] diff --git a/stude/schema.yml b/stude/schema.yml index 9d52df3..327fc79 100644 --- a/stude/schema.yml +++ b/stude/schema.yml @@ -135,7 +135,7 @@ paths: name: id schema: type: integer - description: A unique integer value identifying this custom user. + description: A unique integer value identifying this user. required: true tags: - api @@ -155,7 +155,7 @@ paths: name: id schema: type: integer - description: A unique integer value identifying this custom user. + description: A unique integer value identifying this user. required: true tags: - api @@ -187,7 +187,7 @@ paths: name: id schema: type: integer - description: A unique integer value identifying this custom user. + description: A unique integer value identifying this user. required: true tags: - api @@ -218,7 +218,7 @@ paths: name: id schema: type: integer - description: A unique integer value identifying this custom user. + description: A unique integer value identifying this user. required: true tags: - api @@ -857,6 +857,22 @@ paths: responses: '204': description: No response body + /api/v1/study_groups/member_avatars/: + get: + operationId: api_v1_study_groups_member_avatars_list + tags: + - api + security: + - jwtAuth: [] + responses: + '200': + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/CustomUserAvatar' + description: '' /api/v1/study_groups/near/: get: operationId: api_v1_study_groups_near_list @@ -1065,6 +1081,20 @@ components: - student_id_number - username - yearlevel_shortname + CustomUserAvatar: + type: object + properties: + avatar: + type: string + format: uri + username: + type: string + readOnly: true + description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_ + only. + required: + - avatar + - username Landmark: type: object properties: