Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Event Mode

  • Loading branch information...
commit 0b9d7e7af84384ea9fe60a2da111f3aed7161812 1 parent 8363ecc
@dustball dustball authored
View
53 main.py
@@ -31,6 +31,48 @@
def parse_json(data):
return simplejson.loads(data.replace('/*-secure-','').replace('*/', ''))
+# An event. Usually contains zero rows ("regular mode") or ONE row ("event mode")
+class Event(db.Model):
+ event_name = db.StringProperty()
+ logo_url = db.StringProperty()
+ from_time = db.DateTimeProperty()
+ to_time = db.DateTimeProperty()
+ webhook_url = db.StringProperty()
+ custom_html = db.TextProperty()
+
+ @classmethod
+ def get_current_event(cls):
+ current_event = cls.all().get()
+ return current_event
+
+ @classmethod
+ def delete_current_event(cls):
+ current_event = cls.all().get()
+ if current_event:
+ current_event.delete()
+
+# Configure a special event
+class EventModeHandler(webapp.RequestHandler):
+ def get(self):
+ current_event = Event.get_current_event()
+ now = datetime.now().strftime("%Y-%m-%d %X")
+ self.response.out.write(template.render('templates/eventmode.html', locals()))
+
+ def post(self):
+ Event.delete_current_event()
+ new_event = Event(
+ event_name=self.request.get('event_name'),
+ logo_url=self.request.get('logo_url'),
+ from_time=datetime.strptime(self.request.get("from_time"), "%Y-%m-%d %X"),
+ to_time= datetime.strptime(self.request.get("to_time"), "%Y-%m-%d %X"),
+ webhook_url=self.request.get('webhook_url'),
+ custom_html=self.request.get('custom_html')
+ )
+ new_event.put()
+ self.redirect('/eventmode')
+
+
+
# A log of all signins. One row per signin.
class Signin(db.Model):
email = db.StringProperty(required=True)
@@ -127,6 +169,13 @@ def get(self):
response = {"signins":record.signins, "name":signin.name, "tos":tos}
else:
response = {"error": "need to specify email and type"}
+ current_event = Event.get_current_event()
+ if current_event:
+ urlfetch.fetch(url=current_event.webhook_url,
+ payload=self.request.query_string,
+ method=urlfetch.POST,
+ headers={'Content-Type': 'application/x-www-form-urlencoded'})
+
self.response.out.write(simplejson.dumps(response))
# Initializes SigninRecord database (see util.py)
@@ -160,6 +209,9 @@ def get(self):
dayofWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
oldDate = datetime.now(Pacific())
day = dayofWeek[datetime.weekday(oldDate)]
+ event = Event.get_current_event()
+ if datetime.now()>event.from_time and datetime.now() < event.to_time:
+ current_event = event
self.response.out.write(template.render('templates/main.html', locals()))
def post(self):
@@ -339,6 +391,7 @@ def main():
application = webapp.WSGIApplication([
('/', MainHandler),
(r'^/_ah/mail/there.*', MailHandler),
+ ('/eventmode', EventModeHandler),
('/ministaff', MiniStaffHandler),
('/signin', SigninHandler),
('/staff', StaffHandler),
View
23 static/signin.js
@@ -1,16 +1,17 @@
var main_screen_turn_on = false;
+
function capstaff(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
if (evt.keyCode) code = evt.keyCode;
else if (evt.which) code = evt.which;
- var em = document.getElementById("em").value;
+ var em = $("input[name=email]").val();
if (code==45 || code==18) {
showStaffButtons();
return false;
}
if (code==9 && em.length > 0 && em.indexOf("@") == -1) {
- document.getElementById("em").value = em+"@hackerdojo.com";
+ $("input[name=email]").val(em+"@hackerdojo.com");
return false;
}
}
@@ -25,7 +26,7 @@ function autosignin(x) {
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
- var em = document.getElementById("em").value;
+ var em = $("input[name=email]").val();
if (evt.keyCode==45 || evt.keyCode==18) {
showStaffButtons();
@@ -46,11 +47,11 @@ function stopRKey(evt) {
}
if ((code == 13) && (node.type=="text")) {
- entered = document.getElementById("em").value.replace(/^\;/, "").replace(/\?$/, "");
+ entered = $("input[name=email]").val().replace(/^\;/, "").replace(/\?$/, "");
/* RFID is numeric */
if (entered > 0) {
- document.getElementById("em").value = "";
+ $("input[name=email]").val("");
$('#ajaxloading').fadeIn();
$.ajax({
url: 'http://signup.hackerdojo.com/api/rfid?id='+entered+'&callback=?',
@@ -66,7 +67,7 @@ function stopRKey(evt) {
// window.audio = new Audio("/static/list.mp3");
// window.audio.play();
$('#rfidwelcome').fadeIn();
- document.getElementById("em").value = data.username + "@hackerdojo.com";
+ $("input[name=email]").val(data.username + "@hackerdojo.com");
$('.rfidpic').attr("src",data.gravatar);
$('.rfidname').html(data.name);
if (data.auto_signin && data.auto_signin > 0 && data.auto_signin < 4) {
@@ -108,7 +109,7 @@ String.prototype.capitalize = function(){
};
function clickmember() {
- var em = document.getElementById("em").value;
+ var em = $("input[name=email]").val();
if (em.indexOf("@hackerdojo.com")==-1) {
$("#dojodomain").fadeIn();
return false;
@@ -126,7 +127,7 @@ function clickmember() {
/* Set the type and proceed with signin */
function go(x) {
- if (isEmail(document.getElementById("em").value)) {
+ if (isEmail($("input[name=email]").val())) {
document.getElementById("ttt").value = x;
$('#rfidwelcome').fadeOut();
$('#ajaxloading').fadeIn();
@@ -162,6 +163,7 @@ function prepare_for_signin() {
$("#staffbuttons").hide();
$('#ttt').val("");
$('#em').val("");
+ $("input[type=text]").val("");
$('#em').focus();
}
@@ -173,10 +175,7 @@ function ok() {
$.ajax({
url: '/signin',
dataType: "json",
- data: {
- "email":document.getElementById("em").value,
- "type":document.getElementById("ttt").value
- },
+ data: $('#ajax_form').serialize(),
timeout: 14 * 1000,
error: function(data) {
auto_reset();
View
28 templates/eventmode.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Event Mode</title>
+<style>
+input[type="text"], textarea {width:900px}
+</style>
+</head>
+
+<body>
+
+<h1>Event Mode Config</h1>
+
+<p>The current time is: {{now}}</p>
+
+<form method="POST">
+ <table>
+ <tr><td align="right">Event Name:</td><td><input type="text" name="event_name" value="{{current_event.event_name|escape}}"></td></tr>
+ <tr><td align="right">Logo URL:</td><td><input type="text" name="logo_url" value="{{current_event.logo_url|escape}}"></td></tr>
+ <tr><td align="right">From:</td><td><input type="text" name="from_time" value="{{current_event.from_time}}"></td></tr>
+ <tr><td align="right">To:</td><td><input type="text" name="to_time" value="{{current_event.to_time}}"></td></tr>
+ <tr><td align="right">HTTP Post URL:</td><td><input type="text" name="webhook_url" value="{{current_event.webhook_url|escape}}"></td></tr>
+ <tr><td align="right">Custom HTML:</td><td><textarea rows="12" name="custom_html">{{current_event.custom_html|escape}}</textarea></td></tr>
+ <tr><td align="right" colspan="2"><input type="submit" value="Save"></td></tr>
+ </table>
+</form>
+
+</body>
View
39 templates/main.html
@@ -155,19 +155,38 @@ <h2 style="margin-top:0">Please use your @hackerdojo.com address</h2>
</div>
<center>
- <img style="margin:1.5em" src="/static/logo.png" width="690" height="244" />
+ <form id="ajax_form" onsubmit="return false;">
+ {% if current_event %}
+ <table><tr>
+ <td><img style="margin:1.5em" src="{{current_event.logo_url}}" width="455" height="161" /></td>
+ <td>at</td>
+ <td><img style="margin:1.5em" src="/static/logo.png" width="455" height="161" /></td>
+ </tr></table>
+ {% else %}
+ <img style="margin:1.5em" src="/static/logo.png" width="690" height="244" />
+ {% endif %}
+
<h2>Please Sign In</h2>
+
+ {% if current_event.custom_html %}
+ {{current_event.custom_html}}
+ <br>
+ <input type="button" value="Event Attendee" onclick="go('Event')" />
+ <input type="button" value="Hacker Dojo Member" onclick="clickmember()" />
+ {% else %}
E-mail:
- <input id="em" type="text" name="email">
- <a style="color:green; font-size:9px" href="#" onclick="$('#privacy').fadeIn();">E-mail Privacy</a>
- <br>
- <input type="button" value="Member" onclick="clickmember()" />
- <input type="button" value="Guest" onclick="go('Guest')" />
- <input type="button" value="Event Attendee" onclick="go('Event')" />
- <div id="staffbuttons" style="display:none">
- <input type=button value="Staff" onclick="go('StaffKey')" />
- </div>
+ <input id="em" type="text" name="email">
+ <a style="color:green; font-size:9px" href="#" onclick="$('#privacy').fadeIn();">E-mail Privacy</a>
+ <br>
+ <input type="button" value="Member" onclick="clickmember()" />
+ <input type="button" value="Guest" onclick="go('Guest')" />
+ <input type="button" value="Event Attendee" onclick="go('Event')" />
+ <div id="staffbuttons" style="display:none">
+ <input type=button value="Staff" onclick="go('StaffKey')" />
+ </div>
+ {% endif %}
<input id="ttt" type="hidden" name="type" value="" />
+ </form>
</center>
<audio autobuffer nocontrols>
Please sign in to comment.
Something went wrong with that request. Please try again.