def accept_usl(request, pk): usl_being_accepted = UnCertifiedSickLeave.objects.get(pk=pk) usl_being_accepted.usl_checked_by_validator = True usl_being_accepted.usl_accepted = True usl_being_accepted.save() current_year = getCurrentYear() usl_for_current_year_check = UnCertifiedSickPerYear.objects.filter( yearly_usl_officer_id=usl_being_accepted.usl_officer_id).filter( usl_year=current_year) if usl_for_current_year_check.exist(): usl_for_current_year_check = UnCertifiedSickPerYear.objects.get( yearly_usl_officer_id=usl_being_accepted.usl_officer_id, usl_year=current_year) usl_for_current_year_check.number_usl_for_year += 1 else: new_uncert_sick_per_year = UnCertifiedSickPerYear( yearly_usl_officer_id=usl_being_accepted.usl_officer_id, usl_year=current_year, number_usl_for_year=1) #NOTIFICATION TO APPLICANT THAT UN-CERT HAS BEEN ACCEPTED. notify.send( request.user, recipient=usl_being_accepted.usl_officer_id, verb=" has accepted your Un-Certified Sick Leave application: " + str(usl_being_accepted)) messages.success( request, "You have accepted this uncertified sick leave application.") return redirect('view_staff_sick_leave_applications')
def accept_fm(request, pk): fm_being_accepted = ForceMajeure.objects.get(pk=pk) fm_being_accepted.fm_checked_by_validator = True fm_being_accepted.fm_accepted = True fm_being_accepted.save() current_year = getCurrentYear() fm_for_current_year_check = ForceMajeurePerYear.objects.filter( yearly_fm_officer_id=fm_being_accepted.fm_officer_id).filter( fm_year=current_year) if fm_for_current_year_check.exists(): fm_for_current_year_check = ForceMajeurePerYear.objects.get( yearly_fm_officer_id=fm_being_accepted.fm_officer_id, fm_year=current_year) fm_for_current_year_check.number_fm_for_year += 1 else: new_fm_for_year = ForceMajeurePerYear( yearly_fm_officer_id=fm_being_accepted.fm_officer_id, fm_year=current_year, number_fm_for_year=1) #NOTIFICATION TO APPLICANT THAT FM ACCEPTED. notify.send(request.user, recipient=fm_being_accepted.fm_officer_id, verb=" has accepted your Force Majeure application: " + str(fm_being_accepted)) messages.success(request, "Force Majeure application accepted.") return redirect('view_staff_sick_leave_applications')
def view_lates(request): ''' This view renders the users lates records for display. ''' user = request.user my_late_clockings = Lates.objects.filter(lates_officer_id=user.pk).order_by('-date_of_late') len_late_clockings = len(my_late_clockings) current_year = getCurrentYear() lates_for_current_year = LatesPerYear.objects.filter(yearly_lates_officer_id=user.pk).filter(lates_year=current_year) if lates_for_current_year.exists(): users_lates_for_year = LatesPerYear.objects.get(yearly_lates_officer_id=user.pk, lates_year=current_year) number_of_lates = users_lates_for_year.number_lates_for_year else: number_of_lates = 0 page_number = 1 page = request.GET.get('page', page_number) paginator = Paginator(my_late_clockings, 8) try: my_late_clocks = paginator.page(page) except PageNotAnInteger: my_late_clocks = paginator.page(1) except EmptyPage: my_late_clocks = paginator.page(paginator.num_pages) return render(request, "my_late_clockings.html", {'my_late_clocks': my_late_clocks, 'len_late_clockings': len_late_clockings, 'number_of_lates': number_of_lates, 'current_year': current_year})
def checkForLateClocking(t, officer): ''' Helper function to check of a clocking is late. ''' from .models import Lates, LatesPerYear, Roster, Shift clocking_being_checked = t todays_date = dt.date.today() clocking_being_checked_as_dt_obj = dt.datetime.combine( todays_date, clocking_being_checked) person_who_clocked = officer todays_roster = Roster.objects.get(roster_officer_id=person_who_clocked, roster_shift_date=todays_date) #May add more conditional logic to check clocking for Overtime & Exchanges. todays_shift = get_object_or_404(Shift, pk=todays_roster.roster_shift.id) start_time_as_dt_obj = dt.datetime.combine(todays_roster.roster_shift_date, todays_shift.shift_start_time) if clocking_being_checked_as_dt_obj > start_time_as_dt_obj: late_duration = clocking_being_checked_as_dt_obj - start_time_as_dt_obj grace_period = dt.timedelta(minutes=10) if late_duration > grace_period: new_late = Lates(lates_officer_id=person_who_clocked, date_of_late=todays_roster.roster_shift_date, late_clocking_time=clocking_being_checked, duration_of_late=late_duration) new_late.save() #check for New Lates Per Year current_year = getCurrentYear() lates_for_current_year_check = LatesPerYear.objects.filter( yearly_lates_officer_id=person_who_clocked).filter( lates_year=current_year) if lates_for_current_year_check.exists(): lates_for_current_year_check = LatesPerYear.objects.get( yearly_lates_officer_id=person_who_clocked, lates_year=current_year) lates_for_current_year_check.number_lates_for_year += 1 lates_for_current_year_check.save() else: new_lates_for_current_year_check = LatesPerYear( yearly_lates_officer_id=person_who_clocked, lates_year=current_year, number_lates_for_year=1) new_lates_for_current_year_check.save() return
def accept_csl(request, pk): ''' This view allows a supervisor to accept a csl application. ''' csl_being_accepted = CertifiedSickLeave.objects.get(pk=pk) csl_being_accepted.csl_checked_by_validator = True csl_being_accepted.csl_accepted = True csl_being_accepted.save() current_year = getCurrentYear() csl_for_current_year_check = CertifiedSickPerYear.objects.filter(yearly_csl_officer_id=csl_being_accepted.csl_officer_id).filter(csl_year=current_year) if csl_for_current_year_check.exists(): csl_for_current_year_check = CertifiedSickPerYear.objects.get(yearly_csl_officer_id=csl_being_accepted.csl_officer_id, csl_year=current_year) csl_for_current_year_check.number_csl_for_year += 1 else: new_cert_sick_per_year = CertifiedSickPerYear(yearly_csl_officer_id=csl_being_accepted.csl_officer_id, csl_year=current_year, number_csl_for_year=1) #NOTIFICATION TO APPLICANT THAT CERT HAS BEEN ACCEPTED. notify.send(request.user, recipient=csl_being_accepted.csl_officer_id, verb=" has accepted your Certified Sick Leave application: " + str(csl_being_accepted)) messages.success(request, "You have accepted this certified sick leave application.") return redirect('view_staff_sick_leave_applications')