diff --git a/Dockerfile b/Dockerfile index 6936cf3..3d2ced0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN chmod 0644 /etc/cron.d/cronjob # Create the log file to be able to run tail RUN touch /var/log/cron.log - + RUN crontab /etc/cron.d/cronjob # Run cron in the foreground diff --git a/apps/global_settings/migrations/0004_settings_enable_hostel_limits_and_more.py b/apps/global_settings/migrations/0004_settings_enable_hostel_limits_and_more.py new file mode 100644 index 0000000..115b524 --- /dev/null +++ b/apps/global_settings/migrations/0004_settings_enable_hostel_limits_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.2.7 on 2024-02-03 22:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('global_settings', '0003_alter_settings_options_settings_max_violation_count'), + ] + + operations = [ + migrations.AddField( + model_name='settings', + name='enable_hostel_limits', + field=models.BooleanField(default=False, help_text='Limit the number of students eligible for a particular hostel. Limit can be set from Hostel profile.'), + ), + migrations.AddField( + model_name='settings', + name='enable_yearwise_limits', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='settings', + name='first_year', + field=models.IntegerField(blank=True, default=0, null=True), + ), + migrations.AddField( + model_name='settings', + name='fourth_year', + field=models.IntegerField(blank=True, default=0, null=True), + ), + migrations.AddField( + model_name='settings', + name='second_year', + field=models.IntegerField(blank=True, default=0, null=True), + ), + migrations.AddField( + model_name='settings', + name='third_year', + field=models.IntegerField(blank=True, default=0, null=True), + ), + migrations.AlterField( + model_name='settings', + name='enable_hostel_timers', + field=models.BooleanField(default=False, help_text='Enabling activates the time limits specified in the Hostel profile. The timers below, however, will not be operational.'), + ), + ] diff --git a/apps/global_settings/models.py b/apps/global_settings/models.py index 83780ab..84f05c5 100644 --- a/apps/global_settings/models.py +++ b/apps/global_settings/models.py @@ -2,7 +2,8 @@ class Settings(models.Model): - enable_hostel_timers = models.BooleanField(default=False) + enable_hostel_limits = models.BooleanField(default=False, help_text="Limit the number of students eligible for a particular hostel. Limit can be set from Hostel profile.") + enable_hostel_timers = models.BooleanField(default=False, help_text="Enabling activates the time limits specified in the Hostel profile. The timers below, however, will not be operational.") frontend_checkin_timer = models.IntegerField(blank=True, null=True, default=0) backend_checkin_timer = models.IntegerField(blank=True, null=True, default=0) @@ -14,6 +15,13 @@ class Settings(models.Model): female_ratio = models.FloatField(blank=True, null=True, default=0.5) max_violation_count = models.IntegerField(blank=True, null=True, default=3) + + enable_yearwise_limits = models.BooleanField(default=False) + first_year = models.IntegerField(blank=True, null=True, default=0) + second_year = models.IntegerField(blank=True, null=True, default=0) + third_year = models.IntegerField(blank=True, null=True, default=0) + fourth_year = models.IntegerField(blank=True, null=True, default=0) + class Meta: verbose_name_plural = 'Settings' \ No newline at end of file diff --git a/apps/nightpass/management/commands/start_booking.py b/apps/nightpass/management/commands/start_booking.py index cefed29..307920c 100644 --- a/apps/nightpass/management/commands/start_booking.py +++ b/apps/nightpass/management/commands/start_booking.py @@ -6,5 +6,5 @@ class Command(BaseCommand): def handle(self, *args, **options): self.stdout.write(self.style.SUCCESS('Running your cron job...')) - CampusResource.objects.all().update(is_booking=True) + CampusResource.objects.all().update(is_booking=True, booking_complete=False) self.stdout.write(self.style.SUCCESS('Cron job completed successfully')) \ No newline at end of file diff --git a/apps/nightpass/migrations/0004_hostel_max_students_allowed.py b/apps/nightpass/migrations/0004_hostel_max_students_allowed.py new file mode 100644 index 0000000..5179b3c --- /dev/null +++ b/apps/nightpass/migrations/0004_hostel_max_students_allowed.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-02-03 22:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('nightpass', '0003_hostel_backend_checkin_timer_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='hostel', + name='max_students_allowed', + field=models.IntegerField(blank=True, default=0, null=True), + ), + ] diff --git a/apps/nightpass/models.py b/apps/nightpass/models.py index 09e091a..87a3103 100644 --- a/apps/nightpass/models.py +++ b/apps/nightpass/models.py @@ -13,6 +13,8 @@ class Hostel(models.Model): frontend_checkin_timer = models.IntegerField(blank=True, null=True, default=0) backend_checkin_timer = models.IntegerField(blank=True, null=True, default=0) + max_students_allowed = models.IntegerField(blank=True, null=True, default=0) + def __str__(self): return self.name diff --git a/apps/nightpass/views.py b/apps/nightpass/views.py index cfef5b7..cdcbdd4 100644 --- a/apps/nightpass/views.py +++ b/apps/nightpass/views.py @@ -15,8 +15,16 @@ from ..users.views import * from datetime import datetime, date, timedelta - - +sem_vs_year = { + 1: 1, + 2: 1, + 3: 2, + 4: 2, + 5: 3, + 6: 3, + 7: 4, + 8: 4, +} @login_required def campus_resources_home(request): @@ -80,6 +88,43 @@ def generate_pass(request, campus_resource): } return HttpResponse(json.dumps(data)) + if Settings.enable_yearwise_limits: + data = { + 'status':False, + 'message':'All slots are booked for today!' + } + student_year = sem_vs_year[user.student.semester] + if student_year == 1: + student_year_pass_count = NightPass.objects.filter(valid=True, campus_resource=campus_resource, + user__student__semester__in=[1,2]).count() + if student_year_pass_count > Settings.first_year: + return HttpResponse(json.dumps(data)) + elif student_year == 2: + student_year_pass_count = NightPass.objects.filter(valid=True, campus_resource=campus_resource, + user__student__semester__in=[3,4]).count() + if student_year_pass_count > Settings.second_year: + return HttpResponse(json.dumps(data)) + elif student_year == 3: + student_year_pass_count = NightPass.objects.filter(valid=True, campus_resource=campus_resource, + user__student__semester__in=[5,6]).count() + if student_year_pass_count > Settings.third_year: + return HttpResponse(json.dumps(data)) + elif student_year == 4: + student_year_pass_count = NightPass.objects.filter(valid=True, campus_resource=campus_resource, + user__student__semester__in=[7,8]).count() + if student_year_pass_count > Settings.fourth_year: + return HttpResponse(json.dumps(data)) + + if Settings.enable_hostel_limits: + student_hostel_pass_count = NightPass.objects.filter(valid=True, campus_resource=campus_resource, + user__student__hostel=user.student.hostel).count() + if student_hostel_pass_count > user.student.hostel.max_students_allowed: + data = { + 'status':False, + 'message':'All slots are booked for today!' + } + return HttpResponse(json.dumps(data)) + if int(user.student.violation_flags) >= int(Settings.max_violation_count): data = { 'status':False,