Пример #1
0
def searchPerson(request):
  try:
    if not request.user.is_authenticated():
      raise Http404

    responseData = {'result':'failed'}
    firstName = ''
    lastName = ''
    if(request.method == 'GET'):
      firstName = request.GET['firstName']
      lastName = request.GET['lastName']
    elif(request.method == 'POST'):
      firstName = request.POST['firstName']
      lastName = request.POST['lastName']

    thisPerson = Person.objects.filter(firstName__exact=firstName,
                                       lastName__exact=lastName)
    if(len(thisPerson) > 0):
      week = Week.getCurrentWeek()
      lastLogins = []
      logins = TimingEvent.objects.filter(person__exact=thisPerson, 
                                              signedIn__gte=week.start, 
                                              signedOut__lte=week.end)
      if(len(logins) > 5):
        logins = logins[0:5]

      for login in logins:
        lastLogins.append({"start":login.signedIn.strftime('%m/%d/%y %H:%M:%S %Z'), 
                           "end": login.signedOut.strftime('%m/%d/%y %H:%M:%S %Z'), 
                           "hours": login.hours()})
      print lastLogins

      responseData['firstName'] = firstName
      responseData['lastName'] = lastName
      responseData['hours'] = thisPerson[0].getCurrentHours(week)
      responseData['isSignedIn'] = thisPerson[0].isSignedIn()
      responseData['lastLogins'] = lastLogins
      responseData['result'] = "success"

    return HttpResponse(json.dumps(responseData), mimetype="application/json")
  except Exception as inst:
    return HttpResponse("exception: " + inst.__str__())
Пример #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)
Пример #3
0
os.environ['DJANGO_SETTINGS_MODULE'] = 'studyhours.settings'

from hoursheet.models import Person, Week, TimingEvent

today = datetime.date.today()
dayoffset = today.weekday()
now = datetime.datetime(today.year, today.month, today.day,tzinfo=pytz.timezone('US/Central'))
now = now + datetime.timedelta(days = -1 * (dayoffset + 1))
end = datetime.datetime(now.year,now.month,now.day,23,59,59, tzinfo=pytz.timezone('US/Central'))
end = end + datetime.timedelta(days=7)

for x in xrange(15):
  print "now is ", now
  print "end is ", end
  week = Week(start=now, end=end)
  now = now + datetime.timedelta(days=7)
  end = end + datetime.timedelta(days=7)
  week.save()

people = ['Adam Kosecki', 'Alex Delong', "Alex O'Neil", 'Andrew Baumen', 'Bret Payne', 'Cody Burgess', 'Cody Haislip', 'Corey Reuter', 'Dylan Alarcon', 'Gage Witt', 'Grant Luebbering', 'Jacob Francka', 'Jake Kistler', 'John Walsh', 'Joel Cardin', 'Jerek Nash', 'Josiah Enns', 'Kevin Walaszek', 'Lafe Windmiller', 'Logan Gesiler', 'Matt Achelpohl', 'Michael Keener', 'Ollie Naeger', 'Trevor Townsend', 'Brandon Gasser', 'Sam Manson', "Jimmy O'Donnel", 'Jeremy Satterfield', 'Josh Weber']
for person in people:
  thisperson = Person(firstName=person.split(' ')[0], lastName=person.split(' ')[1], weeklyHours=12, currentFine=2)
  thisperson.save()

people = ['Ryan Covington', 'Daniel FLing', 'Nick Slama', 'Kenny Holtz', 'Mason Smith']
for person in people:
  thisperson = Person(firstName=person.split(' ')[0], lastName=person.split(' ')[1], weeklyHours=6, currentFine=2)
  thisperson.save()

people = ['Eric Moore', 'Tiredej Bunyarataphantusadf', 'Brian Bakala', 'Jared Wyatt', 'Zach Boswell', 'Mark Bradshaw', 'Alex Miles']