Exemple #1
0
def signIn(request):
  if not request.user.is_authenticated():
    raise Http404

  if(request.method == "POST"):
    thisPerson = Person.objects.filter(firstName__exact=request.POST['firstName'],
                                       lastName__exact=request.POST['lastName'])
    if len(thisPerson) == 1:
      thisPerson = thisPerson[0]

    if not thisPerson.isSignedIn():
      signedIn = datetime.datetime.now(pytz.timezone('UTC'));
      event = TimingEvent(person=thisPerson, signedIn=signedIn)
      event.save()

  
  return searchPerson(request)
Exemple #2
0
def signOut(request):
  if not request.user.is_authenticated():
    raise Http404
    
  if(request.method == "POST"):
    thisPerson = Person.objects.filter(firstName__exact=request.POST['firstName'],
                                       lastName__exact=request.POST['lastName'])

    event = TimingEvent.objects.filter(person__exact=thisPerson[0], 
                                        signedOut__isnull=True)

    if(len(thisPerson) == 1 and len(event) == 1):
      thisPerson = thisPerson[0]
      event = event[0]

      now = datetime.datetime.now(pytz.timezone('US/Central'))
      inThisWeek = Week.getCurrentWeek(False, event.signedIn)
      inPriorWeek = Week.getCurrentWeek(True, event.signedIn)
      outThisWeek = Week.getCurrentWeek(False, now)
      outPriorWeek = Week.getCurrentWeek(True, now)

      print "WEEK ID IS ", inThisWeek.pk

      print inThisWeek

      if inThisWeek.pk == inPriorWeek.pk: #if signed in on a weekday
        print "signed in on a weekday"
        if outThisWeek.pk == outPriorWeek.pk:
          event.signedOut = now
        else: #if signed in on weekday and signed out on sunday
          print "signedOut on sunday"
          hoursWithThis = thisPerson.getCurrentHours(outPriorWeek) + timeFromMidnight(event.signedIn)
          if hoursWithThis >= thisPerson.weeklyHours:
            event.signedOut = outThisWeek.start + datetime.timedelta(seconds=-1)
            newEvent = TimingEvent(person=thisPerson, signedIn=outThisWeek.start, signedOut=now)
            newEvent.save()
          else: #if they need this current sunday session to be counted for the prior week
            event.priorWeek = True
            event.signedOut = now
      else:
        print "signed in on sunday"
        hours = thisPerson.getCurrentHours(outPriorWeek)
        if outThisWeek.pk == outPriorWeek.pk:
          print 'signed out on weekday'
          if hours >= thisPerson.weeklyHours:
            event.signedOut = now
          else:
            newEvent = None;
            event.priorWeek = True
            if hours + timeFromMidnight(now) < thisPerson.weeklyHours:
              event.signedOut = inPriorWeek.end
              
              newEvent = TimingEvent(person=thisPerson, 
                                     signedIn=midnight(outPriorWeek.start), 
                                     signedOut=now)
            else:
              timeNeeded = datetime.timedelta(hours=(thisPerson.weeklyHours - hours))
              event.signedOut = event.signedIn + timeNeeded
              newEvent = TimingEvent(person=thisPerson,
                                     signedIn=event.signedOut,
                                     signedOut=now)
            newEvent.save()
        else:
          print "signedOut on sunday"
          if hours >= thisPerson.weeklyHours:
            event.signedOut = now
          else:
            event.priorWeek = True
            hoursWithThis = hours + (now - event.signedIn).seconds/3600 + (now - event.signedIn).days * 24
            if hoursWithThis < thisPerson.weeklyHours:
              event.signedOut = now
            else:
              timeNeeded = datetime.timedelta(hours=(thisPerson.weeklyHours - hours))
              event.signedOut = event.signedIn + timeNeeded
              newEvent = TimingEvent(person=thisPerson,
                                     signedIn=event.signedOut,
                                     signedOut=now)
              newEvent.save()

      event.save()

  return searchPerson(request)