Skip to content

Commit

Permalink
added year filter + bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancham1603 committed Feb 3, 2024
1 parent f04ba61 commit 5868149
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
18 changes: 9 additions & 9 deletions apps/nightpass/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,29 @@ def generate_pass(request, campus_resource):
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:
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:
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:
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:
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:
if student_hostel_pass_count >= user.student.hostel.max_students_allowed:
data = {
'status':False,
'message':'All slots are booked for today!'
Expand Down
24 changes: 22 additions & 2 deletions apps/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@
from datetime import date, datetime
import io


class YearWiseFilter(admin.SimpleListFilter):
title = 'Year'
parameter_name = 'year'

def lookups(self, request, model_admin):
return (
('1', '1st Year'),
('2', '2nd Year'),
('3', '3rd Year'),
('4', '4th Year'),
)

def queryset(self, request, queryset):
if self.value() == '1':
return queryset.filter(user__student__semester__in=['1','2'])
if self.value() == '2':
return queryset.filter(user__student__semester__in=['3','4'])
if self.value() == '3':
return queryset.filter(user__student__semester__in=['5','6'])
if self.value() == '4':
return queryset.filter(user__student__semester__in=['7','8'])

class NightPassAdmin(admin.ModelAdmin):
list_display = ( 'name','user','hostel','date', 'campus_resource','hostel_check_out', 'check_in', 'check_out', 'hostel_check_in', 'defaulter')
search_fields = ('user__student__name','user__student__registration_number','user__student__email')
actions = ['export_as_xlsx']
list_filter = (('date', DateRangeFilter),'campus_resource','user__student__gender','user__student__hostel', 'defaulter', 'check_in', 'check_out')
list_filter = (('date', DateRangeFilter),'campus_resource','user__student__gender','user__student__hostel', YearWiseFilter,'defaulter', 'check_in', 'check_out')
autocomplete_fields = ('user', 'campus_resource')
readonly_fields = ('pass_id', 'check_in_time', 'check_out_time', 'hostel_checkout_time', 'hostel_checkin_time')

Expand Down

0 comments on commit 5868149

Please sign in to comment.