Example #1
0
def ajax_set_questions():
	hackathon = request.form["hackathon_id"]
	questions = request.form["questions"]

	hackathon = get_object_or_404(Hackathon, id = hackathon)
	hackathon.trivia = questions
	hackathon.save()
Example #2
0
def ajax_set_questions():
    hackathon = request.form["hackathon_id"]
    questions = request.form["questions"]

    hackathon = get_object_or_404(Hackathon, id=hackathon)
    hackathon.trivia = questions
    hackathon.save()
Example #3
0
def ajax_get_event_attendees():
	hackathon = get_object_or_404(Hackathon, id = request.form["hackathon_id"])
	req = urllib2.Request("https://graph.facebook.com/"+str(hackathon.facebook_id)+"/attending?access_token="+session["fb_token"])
	print "https://graph.facebook.com/"+str(hackathon.facebook_id)+"/attending?access_token="+session["fb_token"]
	response = urllib2.urlopen(req)
	decoder = JSONDecoder()
	attending = decoder.decode(response.read())["data"]
	return {"attending": attending}
Example #4
0
def manage_hackathon(hackathon_id):
	hackathon = get_object_or_404(Hackathon, id = hackathon_id)

	if request.method == "POST":
		ann = Announcement(hackathon = hackathon, message = request.form["message"])
		ann.save()
		return redirect(url_for("dash", hackathon_id = hackathon.id))

	return render_template("manage.html", hackathon = hackathon)
Example #5
0
def manage_hackathon(hackathon_id):
    hackathon = get_object_or_404(Hackathon, id=hackathon_id)

    if request.method == "POST":
        ann = Announcement(hackathon=hackathon,
                           message=request.form["message"])
        ann.save()
        return redirect(url_for("dash", hackathon_id=hackathon.id))

    return render_template("manage.html", hackathon=hackathon)
Example #6
0
def ajax_guess():
	hackathon = get_object_or_404(Hackathon, id = request.form["hackathon_id"])
	guess = request.form["guess"]

	if guess.strip().lower() == hackathon.cur_question.split("|")[1].strip().lower():
		hackathon.cur_question = random.choice(hackathon.trivia.split("\n"))
		hackathon.save()
		return {"guess": "correct"}
	else:
		return {"guess": "incorrect"}
Example #7
0
def ajax_guess():
    hackathon = get_object_or_404(Hackathon, id=request.form["hackathon_id"])
    guess = request.form["guess"]

    if guess.strip().lower() == hackathon.cur_question.split(
            "|")[1].strip().lower():
        hackathon.cur_question = random.choice(hackathon.trivia.split("\n"))
        hackathon.save()
        return {"guess": "correct"}
    else:
        return {"guess": "incorrect"}
Example #8
0
def ajax_updates():
	shoutouts_after = request.form["shoutouts_after"]
	hackathon = get_object_or_404(Hackathon, id = request.form["hackathon_id"])
	shoutouts = Shoutout.select().where(Shoutout.id > shoutouts_after, Shoutout.hackathon == hackathon).order_by(Shoutout.id)
	out = []
	for so in shoutouts:
		out.append({"message": so.message, "fbid": so.user.facebook_id, "id": so.id})
	last_id = shoutouts_after
	if len(out):
		last_id = out[-1]["id"]
	return {"shoutouts": out, "last_id": last_id, "cur_question": hackathon.cur_question.split("|")[0]}
Example #9
0
def ajax_get_event_attendees():
    hackathon = get_object_or_404(Hackathon, id=request.form["hackathon_id"])
    req = urllib2.Request("https://graph.facebook.com/" +
                          str(hackathon.facebook_id) +
                          "/attending?access_token=" + session["fb_token"])
    print "https://graph.facebook.com/" + str(
        hackathon.facebook_id
    ) + "/attending?access_token=" + session["fb_token"]
    response = urllib2.urlopen(req)
    decoder = JSONDecoder()
    attending = decoder.decode(response.read())["data"]
    return {"attending": attending}
Example #10
0
def dash(hackathon_id):
	hackathon = get_object_or_404(Hackathon, id = hackathon_id)
	now = datetime.datetime.now()

	hacks = []

	req = urllib2.Request("https://graph.facebook.com/"+str(hackathon.facebook_id)+"/photos?access_token="+str(session["fb_token"]))
	response = urllib2.urlopen(req)
	decoder = JSONDecoder()
	photos = decoder.decode(response.read())
	photos = photos["data"]


	number_males = 0
	number_females = 0

	"""1
	req = urllib2.Request("https://graph.facebook.com/"+str(hackathon.facebook_id)+"/attending?access_token="+session["fb_token"])
	response = urllib2.urlopen(req)
	decoder = JSONDecoder()
	response = decoder.decode(response.read())
	people = response["data"]

	for person in people:
		pid = person["id"]

		req = urllib2.Request("https://graph.facebook.com/"+str(pid))
		response = urllib2.urlopen(req)
		decoder = JSONDecoder()
		response = decoder.decode(response.read())
		if ( response["gender"] == "male" ):
			number_males = number_males + 1
		elif ( response["gender"] == "female" ):
			number_females = number_females + 1

			"""

	hack_q = Hack.select().where(Hack.hackathon==hackathon)
	for h in hack_q:
		hacks.append(h)

	if now < hackathon.start_date:
		return render_template("dash-future.html", hackathon = hackathon, photos = photos, males_females = {"males": number_males, "females" : number_females})
	elif now < hackathon.end_date:
		req = urllib2.Request("https://graph.facebook.com/"+str(hackathon.facebook_id)+"/photos?access_token="+session["fb_token"])
		response = urllib2.urlopen(req)
		decoder = JSONDecoder()
		photos = decoder.decode(response.read())
		photos = photos["data"]
		anns = Announcement.select().where(Announcement.hackathon == hackathon).order_by(Announcement.time)
		return render_template("dash-present.html", hackathon = hackathon, hacks = hacks, anns = anns, photos = photos)
	else:
		return hack_get_all_time_stats(hackathon, hacks)
Example #11
0
def hack_create(hackathon_id):
    hackathon = get_object_or_404(Hackathon, id=hackathon_id)
    hack = Hack()

    if request.method == "POST":
        form = HackForm(request.form)
        if form.validate():
            form.populate_obj(hack)
            hack.hackathon = hackathon
            hack.save()
            flash("Your hack was successfully added", "success")
            return redirect(url_for("dash", hackathon_id=hackathon.id))
    else:
        form = HackForm()

    return render_template("hack-create.html", form=form, hackathon=hackathon)
Example #12
0
def hack_create(hackathon_id):
	hackathon = get_object_or_404(Hackathon, id = hackathon_id)
	hack = Hack()

	if request.method == "POST":
		form = HackForm(request.form)
		if form.validate():
			form.populate_obj(hack)
			hack.hackathon = hackathon
			hack.save()
			flash("Your hack was successfully added", "success")
			return redirect(url_for("dash", hackathon_id = hackathon.id))
	else:
		form = HackForm()

	return render_template("hack-create.html", form = form, hackathon = hackathon)
Example #13
0
def ajax_updates():
    shoutouts_after = request.form["shoutouts_after"]
    hackathon = get_object_or_404(Hackathon, id=request.form["hackathon_id"])
    shoutouts = Shoutout.select().where(
        Shoutout.id > shoutouts_after,
        Shoutout.hackathon == hackathon).order_by(Shoutout.id)
    out = []
    for so in shoutouts:
        out.append({
            "message": so.message,
            "fbid": so.user.facebook_id,
            "id": so.id
        })
    last_id = shoutouts_after
    if len(out):
        last_id = out[-1]["id"]
    return {
        "shoutouts": out,
        "last_id": last_id,
        "cur_question": hackathon.cur_question.split("|")[0]
    }
Example #14
0
def dash(hackathon_id):
    hackathon = get_object_or_404(Hackathon, id=hackathon_id)
    now = datetime.datetime.now()

    hacks = []

    req = urllib2.Request("https://graph.facebook.com/" +
                          str(hackathon.facebook_id) +
                          "/photos?access_token=" + str(session["fb_token"]))
    response = urllib2.urlopen(req)
    decoder = JSONDecoder()
    photos = decoder.decode(response.read())
    photos = photos["data"]

    number_males = 0
    number_females = 0
    """1
	req = urllib2.Request("https://graph.facebook.com/"+str(hackathon.facebook_id)+"/attending?access_token="+session["fb_token"])
	response = urllib2.urlopen(req)
	decoder = JSONDecoder()
	response = decoder.decode(response.read())
	people = response["data"]

	for person in people:
		pid = person["id"]

		req = urllib2.Request("https://graph.facebook.com/"+str(pid))
		response = urllib2.urlopen(req)
		decoder = JSONDecoder()
		response = decoder.decode(response.read())
		if ( response["gender"] == "male" ):
			number_males = number_males + 1
		elif ( response["gender"] == "female" ):
			number_females = number_females + 1

			"""

    hack_q = Hack.select().where(Hack.hackathon == hackathon)
    for h in hack_q:
        hacks.append(h)

    if now < hackathon.start_date:
        return render_template("dash-future.html",
                               hackathon=hackathon,
                               photos=photos,
                               males_females={
                                   "males": number_males,
                                   "females": number_females
                               })
    elif now < hackathon.end_date:
        req = urllib2.Request("https://graph.facebook.com/" +
                              str(hackathon.facebook_id) +
                              "/photos?access_token=" + session["fb_token"])
        response = urllib2.urlopen(req)
        decoder = JSONDecoder()
        photos = decoder.decode(response.read())
        photos = photos["data"]
        anns = Announcement.select().where(
            Announcement.hackathon == hackathon).order_by(Announcement.time)
        return render_template("dash-present.html",
                               hackathon=hackathon,
                               hacks=hacks,
                               anns=anns,
                               photos=photos)
    else:
        return hack_get_all_time_stats(hackathon, hacks)
Example #15
0
def ajax_post_shoutout():
    hackathon = get_object_or_404(Hackathon, id=request.form["hackathon_id"])
    so = Shoutout(user=auth.get_logged_in_user(),
                  hackathon=hackathon,
                  message=request.form["message"])
    so.save()
Example #16
0
def ajax_post_shoutout():
	hackathon = get_object_or_404(Hackathon, id = request.form["hackathon_id"])
	so = Shoutout(user = auth.get_logged_in_user(), hackathon = hackathon, message = request.form["message"])
	so.save()