Beispiel #1
0
def check(request):
    try:
        S = Shift.objects.filter(id=request.POST['shft'])
        P = Period.objects.filter(start_at__lte=date.today()).filter(end_at__gte=date.today())[0]
        E = Employee.objects.filter(id=request.POST['emp'])
        SE = ShiftEmployees.objects.get(shift=S,employee=E,period=P)
        L = Log(shiftemployees=SE, date=datetime.datetime.now(), absent=False)
	day = datetime.datetime.now()
	b = S[0].block
	Sdate = datetime.datetime(day.year, day.month, day.day,b.start_at.hour,b.start_at.minute,0)
        Edate = datetime.datetime(day.year, day.month, day.day,b.end_at.hour,b.end_at.minute,0)
        if not Log.objects.filter(shiftemployees=SE, absent=False, date__range=(Sdate,Edate)):
            L. weeknumber = L.date.isocalendar()[1]
    	    L.save()
    except (KeyError, Shift.DoesNotExist):
        return HttpResponseRedirect(reverse('checkin.views.checkin'))
    else:
        return HttpResponseRedirect(reverse('checkin.views.checkin'))
Beispiel #2
0
def absences(request):
    #since beggining of period till now: find absences and create absent logs
    P = Period.objects.filter(start_at__lte=date.today()).filter(end_at__gte=date.today())
    B = Block.objects.all()
    S = Shift.objects.all()
    L = Log.objects.all()
    difference = (datetime.datetime.now() - P[0].start_at).days
    start_day = datetime.datetime(P[0].start_at.year, P[0].start_at.month, P[0].start_at.day,0,0,0)
    for d in range(difference+1):
        day = start_day + datetime.timedelta(d)
        if day.weekday() < 5: #if its a week day
            for b in B:
                s = S.filter(block=b).get(weekday=day.weekday()+1)
                SE = ShiftEmployees.objects.filter(shift=s).filter(period=P[0])
                Adate = datetime.datetime(day.year, day.month, day.day,b.start_at.hour,b.start_at.minute,0)
                Ndate = datetime.datetime(day.year, day.month, day.day,b.end_at.hour,b.end_at.minute,0)
                for se in SE:
                    if not L.filter(date__range=(Adate,Ndate)).filter(shiftemployees=se): #if the log for that block  in the day wasnt created
                        Lnew = Log(shiftemployees=se, date=Ndate, absent=True, weeknumber=Ndate.isocalendar()[1])
                        Lnew.save()
    return HttpResponseRedirect(reverse('checkin.views.log'))