@@ -430,7 +430,7 @@ def take_attendance_view(request, scheduled_activity_id):
430
430
"show_checkboxes" : (scheduled_activity .block .locked or request .user .is_eighth_admin ),
431
431
"show_icons" : (scheduled_activity .block .locked and scheduled_activity .block .attendance_locked () and not request .user .is_eighth_admin ),
432
432
"bbcu_script" : settings .BBCU_SCRIPT ,
433
- "is_sponsor " : scheduled_activity . user_is_sponsor ( request . user ),
433
+ "qrurl " : request . build_absolute_uri ( reverse ( "qr_attendance" , args = [ scheduled_activity . id , scheduled_activity . attendance_code ]) ),
434
434
}
435
435
436
436
if request .user .is_eighth_admin :
@@ -774,31 +774,21 @@ def email_students_view(request, scheduled_activity_id):
774
774
775
775
@login_required
776
776
@deny_restricted
777
- def student_attendance_view (request ):
777
+ def student_attendance_view (request , attc = None , attf = None , attimef = None , atteachf = None ):
778
778
blocks = EighthBlock .objects .get_blocks_today ()
779
- attc = None
780
- attf = None
781
- attimef = None
782
- atteachf = None
783
779
if request .method == "POST" :
784
780
now = timezone .localtime ()
785
- dayblks = Day .objects .select_related ("day_type" ).get (date = now ).day_type .blocks . all ()
781
+ dayblks = Day .objects .select_related ("day_type" ).get (date = now ).day_type .blocks
786
782
for blk in blocks :
787
783
blklet = blk .block_letter
788
784
code = request .POST .get (blklet )
789
785
if code is None :
790
786
continue
791
787
act = request .user .eighthscheduledactivity_set .get (block = blk )
792
788
if act .get_code_mode_display () == "Auto" :
793
- dayblk = None
794
- for bk in dayblks :
795
- name = bk .name
796
- if name is None :
797
- continue
798
- if blklet in name and "8" in name :
799
- dayblk = bk
800
- break
801
- if dayblk is None :
789
+ try :
790
+ dayblk = dayblks .get (name = "8" + blklet )
791
+ except Exception :
802
792
attimef = blk
803
793
break
804
794
start_time = shift_time (tm (hour = dayblk .start .hour , minute = dayblk .start .minute ), - 20 )
@@ -811,34 +801,95 @@ def student_attendance_view(request):
811
801
break
812
802
code = code .upper ()
813
803
if code == act .attendance_code :
814
- present = EighthSignup .objects .filter (scheduled_activity = act , user__in = [request .user .id ])
815
- present .update (was_absent = False )
816
- attc = blk
817
- for s in present :
818
- invalidate_obj (s )
819
- act .attendance_taken = True
820
- act .save ()
821
- invalidate_obj (act )
804
+ try :
805
+ present = EighthSignup .objects .get (scheduled_activity = act , user__in = [request .user .id ])
806
+ present .was_absent = False
807
+ invalidate_obj (present )
808
+ act .attendance_taken = True
809
+ act .save ()
810
+ invalidate_obj (act )
811
+ attc = blk
812
+ except Exception :
813
+ attf = blk
822
814
break
823
815
else :
824
816
attf = blk
825
817
break
818
+ return student_frontend (request , attc , attf , attimef , atteachf )
819
+
820
+
821
+ @login_required
822
+ @deny_restricted
823
+ def student_frontend (request , attc = None , attf = None , attimef = None , atteachf = None ):
824
+ blocks = EighthBlock .objects .get_blocks_today ()
826
825
if blocks :
827
826
sch_acts = []
827
+ att_marked = []
828
828
for b in blocks :
829
829
try :
830
830
act = request .user .eighthscheduledactivity_set .get (block = b )
831
831
if act .activity .name != "z - Hybrid Sticky" :
832
832
sch_acts .append ([b , act , ", " .join ([r .name for r in act .get_true_rooms ()]), ", " .join ([s .name for s in act .get_true_sponsors ()])])
833
-
833
+ signup = EighthSignup .objects .get (user = request .user , scheduled_activity = act )
834
+ if not signup .was_absent :
835
+ att_marked .append (b )
834
836
except EighthScheduledActivity .DoesNotExist :
835
837
sch_acts .append ([b , None ])
836
838
response = render (
837
839
request ,
838
840
"eighth/student_submit_attendance.html" ,
839
- context = {"sch_acts" : sch_acts , "attc" : attc , "attf" : attf , "attimef" : attimef , "atteachf" : atteachf },
841
+ context = {"sch_acts" : sch_acts , "att_marked" : att_marked , " attc" : attc , "attf" : attf , "attimef" : attimef , "atteachf" : atteachf },
840
842
)
841
843
else :
842
844
messages .error (request , "There are no eighth period blocks scheduled today." )
843
845
response = redirect ("index" )
844
846
return response
847
+
848
+
849
+ @login_required
850
+ @deny_restricted
851
+ def qr_attendance_view (request , act_id , code ):
852
+ act = get_object_or_404 (EighthScheduledActivity , id = act_id )
853
+ error = False
854
+ block = act .block
855
+ attc = None
856
+ attf = None
857
+ attimef = None
858
+ atteachf = None
859
+ if act .get_code_mode_display () == "Auto" :
860
+ now = timezone .localtime ()
861
+ dayblks = Day .objects .select_related ("day_type" ).get (date = now ).day_type .blocks
862
+ try :
863
+ dayblk = dayblks .get (name = "8" + block .block_letter )
864
+ start_time = shift_time (tm (hour = dayblk .start .hour , minute = dayblk .start .minute ), - 20 )
865
+ end_time = shift_time (tm (hour = dayblk .end .hour , minute = dayblk .end .minute ), 20 )
866
+ if not start_time <= now .time () <= end_time :
867
+ attimef = block
868
+ error = True
869
+ except Exception :
870
+ attimef = block
871
+ error = True
872
+ elif act .get_code_mode_display () == "Closed" :
873
+ atteachf = block
874
+ error = True
875
+ if not error :
876
+ code = code .upper ()
877
+ if code == act .attendance_code :
878
+ try :
879
+ present = EighthSignup .objects .get (scheduled_activity = act , user__in = [request .user .id ])
880
+ present .was_absent = False
881
+ invalidate_obj (present )
882
+ act .attendance_taken = True
883
+ act .save ()
884
+ invalidate_obj (act )
885
+ attc = block
886
+ messages .success (request , "Attendance marked." )
887
+ except Exception :
888
+ attf = block
889
+ messages .error (request , "Failed to mark attendance." )
890
+ else :
891
+ attf = block
892
+ messages .error (request , "Failed to mark attendance." )
893
+ else :
894
+ messages .error (request , "Failed to mark attendance." )
895
+ return student_frontend (request , attc , attf , attimef , atteachf )
0 commit comments