Skip to content

Commit

Permalink
fixed timezone in nightpass export
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancham1603 committed Dec 2, 2023
1 parent f8fc9e8 commit 503bdfe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from xlsxwriter import Workbook
from datetime import date, datetime
import io
from django.utils import timezone


class NightPassAdmin(admin.ModelAdmin):
Expand All @@ -19,9 +20,20 @@ def export_as_xlsx(modeladmin, request, queryset):
headers = ['User', 'Email', 'Hostel', 'Pass ID', 'Date', 'Campus Resource', 'Check In','Check In Time', 'Check Out', 'Check Out Time', 'Hostel Check Out Time' ,'Hostel Check In Time']
data = []
for obj in queryset:
data.append([obj.user.student.name, obj.user.email , obj.user.student.hostel.name,obj.pass_id, obj.date.strftime('%d/%m/%y'), obj.campus_resource.name, obj.check_in, obj.check_in_time.strftime('%H:%M:%S') if obj.check_in_time is not None else None, obj.check_out, obj.check_out_time.strftime('%H:%M:%S') if obj.check_out_time is not None else None, obj.hostel_checkout_time.strftime('%H:%M:%S') if obj.hostel_checkout_time is not None else None, obj.hostel_checkin_time.strftime('%H:%M:%S') if obj.hostel_checkin_time is not None else None,])
data.append([obj.user.student.name,
obj.user.email ,
obj.user.student.hostel.name,
obj.pass_id,
obj.date.strftime('%d/%m/%y'),
obj.campus_resource.name,
obj.check_in,
timezone.localtime(obj.check_in_time).strftime('%H:%M:%S') if obj.check_in_time is not None else None,
obj.check_out,
timezone.localtime(obj.check_out_time).strftime('%H:%M:%S') if obj.check_out_time is not None else None,
timezone.localtime(obj.hostel_checkout_time).strftime('%H:%M:%S') if obj.hostel_checkout_time is not None else None,
timezone.localtime(obj.hostel_checkin_time).strftime('%H:%M:%S') if obj.hostel_checkin_time is not None else None,])
output = io.BytesIO()
wb = Workbook(output, {'in_memory': True})
wb = Workbook(output, {'in_memory': True, 'remove_timezone':True})
ws = wb.add_worksheet()

for col_num, header in enumerate(headers):
Expand Down

0 comments on commit 503bdfe

Please sign in to comment.