Skip to content

Commit

Permalink
added year and hostel limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancham1603 committed Feb 3, 2024
1 parent 1cb3c45 commit f04ba61
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.'),
),
]
10 changes: 9 additions & 1 deletion apps/global_settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'
2 changes: 1 addition & 1 deletion apps/nightpass/management/commands/start_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
18 changes: 18 additions & 0 deletions apps/nightpass/migrations/0004_hostel_max_students_allowed.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 2 additions & 0 deletions apps/nightpass/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 47 additions & 2 deletions apps/nightpass/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f04ba61

Please sign in to comment.