Skip to content

Commit

Permalink
Merge branch 'master' into travis-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rselwyn committed Jan 13, 2016
2 parents 73b1d04 + 866f88e commit 577df37
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Peter <[email protected]> (@DeckardKane)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# attendance

# attendance [![Build Status](https://travis-ci.org/team8/attendance.svg?branch=master)](https://travis-ci.org/team8/attendance)
##What is this?
This is an attendance system we are working on to benefit our robotics team, FRC Team \#8. We are currently working with a combination of [Django](https://www.djangoproject.com/), a Python library designed (well, for a lot of things) to make working with databases a bit easier; HTML; and some PHP for the online portal we're creating.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'attendanceapp/style.css' %}" />
<link rel="stylesheet" type="text/css"
href="{% static 'attendanceapp/style.css' %}" />

<html>
<head>
Expand All @@ -17,7 +18,10 @@

<form action="{% url 'ScanCard' %}" method="post">
{% csrf_token %}
<input type="text" id="cardBox" name="studentID" autofocus>
<input type="text" id="cardBox" name="studentID" autofocus pattern=".{8}|.{14}"
required title="Either 8 or 14 characters.
If this is Martin, your ID is currently 8 digits long, I'm working on
making it 4">
<input type="submit" value="Log in/out">
</form>

Expand Down
56 changes: 40 additions & 16 deletions attendance-website/attendanceapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
from django.http import HttpResponse
from django.utils import timezone
from django.template import RequestContext, loader

import math
import requests
import urllib2
import re

# Create your views here.

#idNotFound = render(request, 'attendanceapp/ScanCard.html', {'message':"Sorry, student ID# not found."})
#helloMartin = render(request, 'attendanceapp/ScanCard.html', {'message':"Hi Martin!"})

def index(request):
#Load the index html page
template=loader.get_template('attendanceapp/index.html')
Expand All @@ -19,6 +23,7 @@ def index(request):
#Render the html and return it to the user -> This is only used in the index view
return HttpResponse(template.render(context))


def logIn(student):
#Make the student at the lab
student.atLab=True
Expand All @@ -29,6 +34,7 @@ def logIn(student):
#Write to the database
student.save()


def logOut(student):
#Tell the system that the student is no longer in the lab
student.atLab=False
Expand Down Expand Up @@ -64,52 +70,70 @@ def logOut(student):
#Return the number of minutes
return minutesWorked


def makeNewStudent(ID):

html = requests.post("https://palo-alto.edu/Forgot/Reset.cfm",data={"username":str(ID)}).text
name = re.search(r'<input name="name" type="hidden" label="name" value=(.*?)"',html).group(1)
Student(name=name,studentID=ID,subteam=Subteam.objects.get(name="Unknown")).save()
try:
html = urllib2.urlopen(urllib2.Request("https://palo-alto.edu/Forgot/Reset.cfm",urllib2.urlencode({"username":str(ID)})))
name = re.search(r'<input name="name" type="hidden" label="name" value=(.*?)"',html).group(0)
Student(name=name,studentID=ID,subteam=Subteam.objects.filter(name="Unknown")).save()
return True
#return False
except: return False


def logInPage(request):
#Check if we are passed the student ID -> check if it is first time loading the page
#If this passes, that means a student is logging in/out
#If this fails...???

try: studentID=request.POST['studentID']
except: return render(request, 'attendanceapp/ScanCard.html')


try:student=Student.objects.get(studentID=studentID)

except:
#if len(studentID)==4:
# if studentID=="8888":
# #return helloMartin
# else: return idNotFound

#Check to see if the inputted # meets the standard for ID# format. This
#should be encapsulated, but it may be redundant with the introduction of
#the HTML5 pattern attribute on the ScanCard page.
if len(studentID) != 8:
if len(studentID)==14:
studentID=studentID[5:13]
else: return idNotFound

try: student=Student.objects.get(studentID=studentID)

except:
if makeNewStudent(request.POST['studentID']) == False:
print "makeNewStudent failing"
return render(request, 'attendanceapp/ScanCard.html', {'message':"Sorry, student ID# not found."})

else:
student=Student.objects.get(studentID=studentID)


if student.atLab==True:

minutes = logOut(student)
timeReturn = str(math.trunc(minutes/60)) + " hours, " + " and " + str(math.trunc(minutes%60)) + " minutes."
return render(request,'attendanceapp/ScanCard.html',{'message':"Hello " + student.name + ". You worked " + timeReturn + " today."})
timeReturn = str(math.trunc(minutes/60)) + " hours, " + " and " + str(math.trunc(minutes%60)) + " minutes"
return render(request,'attendanceapp/ScanCard.html',{'message':"Hey " + student.name + "! You worked " + timeReturn + ", great job!"})

else:
logIn(student)
return render(request,'attendanceapp/ScanCard.html',{'message':"Hello " + student.name + " you just logged in"})
return render(request,'attendanceapp/ScanCard.html',{'message':"Hey " + student.name + ", you just logged in. Good to see you!"})

#This is part of our Slack Integration. This one is supposed to return a list of people currently in the lab. SLack will send a payload through POST, we have to interpret it and send a response back. Not implemented (yet).
#This is part of our Slack Integration.
#This one is supposed to return a list of people currently in the lab.
#Slack will send a payload through POST.
#We have to interpret it and send a response back. Not implemented (yet).
def whoIsInLab(request):
try:
pass
except Exception as e:
raise


#This is part of our Slack Integration. Same technical details as above, this one will return true/false depending on whether the specific person requested is in the lab or not. Not implemented (yet).
#This is part of our Slack Integration.
#Same technical details as above, this one will return true/false depending on whether the specific person requested is in the lab or not. Not implemented (yet).
def specificPersonInLab(request):
try:
ID = request.POST['studentID']
Expand Down
3 changes: 2 additions & 1 deletion attendance-website/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Django==1.8.5
Django==1.8.5
requests==2.9.1

0 comments on commit 577df37

Please sign in to comment.