Skip to content

Commit

Permalink
add solve behavior, fix javascript root url thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud Hashemi committed May 19, 2012
1 parent c5c4be2 commit d995f3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
7 changes: 4 additions & 3 deletions dabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ class DabImage(DabModel):

class DabSolution(DabModel):
dabblet = pw.ForeignKeyField(Dabblet, related_name='dabblet')
choice = pw.ForeignKeyField(DabChoice, related_name='choice')
choice = pw.ForeignKeyField(DabChoice, null=True, related_name='choice')

solver_ip = pw.CharField()
date_solved = pw.DateTimeField(db_index=True)
solver_ip = pw.CharField()
solver_index = pw.IntegerField()
date_solved = pw.DateTimeField(db_index=True)


def test():
Expand Down
2 changes: 1 addition & 1 deletion dabnabbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def test():

if __name__ == '__main__':
import time
dcount = 2000
dcount = 100
start = time.time()
print 'Saving a bunch (',dcount,') of Dabblets.'
dabblets = save_a_bunch(dcount)
Expand Down
25 changes: 19 additions & 6 deletions dabserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from datetime import datetime

import bottle
from bottle import route, run, request, response, static_file
Expand Down Expand Up @@ -59,18 +60,30 @@ def get_session(session_id=None):
SESSIONS[session_id] = session
return session

@route('/solve/')
@route('/solve/', method='POST')
def solve_dabblet():
session_id = request.get_cookie('session_id') #TODO: decorator-ify session
session = get_session(session_id)
response.set_cookie('session_id', session['id'])

dabblet_id = int(request.POST['dabblet_id'])
choice_id = int(request.POST['choice_id'])

dabblet = Dabblet.get(id=dabblet_id)
choice = DabChoice.get(id=choice_id)



if choice_id < 0:
choice = None
else:
choice = DabChoice.get(id=choice_id)

sol = DabSolution(dabblet=dabblet,
choice=choice,
solver_ip=request.get('REMOTE_ADDR'),
solver_index=session.get('cur_index', 0),
date_solved=datetime.now())
sol.save()
# replace?
return { 'hello stephen': "it's 2:37AM and your request succeeded" }


@route('/random/')
def get_random_dabblet():
rdabs = Dabblet.select().order_by("RANDOM()").limit(2)
Expand Down
2 changes: 1 addition & 1 deletion static/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(document).ready(function() {

function new_random() {

do_query('http://localhost:8080/next/', page_setup);
do_query('/next/', page_setup);

function page_setup(err, data){
var dab = data.dabblet;
Expand Down

0 comments on commit d995f3e

Please sign in to comment.