Skip to content

Commit

Permalink
added date range filter + defaulter fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancham1603 committed Dec 3, 2023
1 parent 3634cf2 commit 98dda09
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions apps/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from django.contrib import admin
from django.apps import apps
from django.http import HttpResponse
from django.utils import timezone
from django.utils.html import format_html
from rangefilter.filter import DateRangeFilter
from tablib import Dataset
from .models import *
from import_export.admin import ImportExportModelAdmin
from .resources import *
from xlsxwriter import Workbook
from datetime import date, datetime
import io
from django.utils import timezone
from django.utils.html import format_html



class NightPassAdmin(admin.ModelAdmin):
list_display = ( 'user','date', 'campus_resource','hostel_check_out', 'check_in', 'check_out', 'hostel_check_in', 'defaulter')
search_fields = ('pass_id', 'user')
actions = ['export_as_xlsx']
list_filter = ('date', 'campus_resource', 'defaulter')
list_filter = (('date', DateRangeFilter),'campus_resource', 'defaulter')
autocomplete_fields = ('user', 'campus_resource')

def user(self, obj):
Expand Down
10 changes: 9 additions & 1 deletion apps/users/management/commands/check_defaulters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand
from ...models import NightPass, Student
from datetime import date, timedelta
from datetime import date, timedelta, datetime, time

def check_defaulters():
previous_day_nightpasses = NightPass.objects.filter(date=date.today()-timedelta(days=1))
Expand All @@ -11,6 +11,14 @@ def check_defaulters():
defaulter = True
remarks+= "Did not go to Location. "
else:
if nightpass.hostel_checkout_time:
if (nightpass.check_in_time - nightpass.hostel_checkout_time) > timedelta(minutes=20):
defaulter = True
remarks+= "Entered library after 20mins. "
else:
if (nightpass.check_in_time - datetime.combine(nightpass.check_in_time.date(), time(20,50))) > timedelta(minutes=20):
defaulter = True
remarks+= "Entered library after 20mins. "
if not nightpass.check_out:
defaulter=True
remarks+= "Left library unethically. "
Expand Down
3 changes: 2 additions & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
'import_export',
'django_crontab',
'hijack',
'hijack.contrib.admin'
'hijack.contrib.admin',
'rangefilter'
]


Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ django-import-export
django-crontab
uuid
tablib
XlsxWriter
XlsxWriter
django-admin-rangefilter

0 comments on commit 98dda09

Please sign in to comment.