2

I'm writing a psychology experiment in Python, and I need to make it available as a web app. I've already got the Python basically working as a command-line program. On the recommendation of a CS buddy I'm using Django with a sqlite db. This is also working, my development server is up and the database tables are ready and waiting.

What I don't understand is how to glue these two pieces together. The Django tutorials I've found are all about building things like blogs, messaging systems or polls; systems based on sending form data. I can't do that, because I'm timing responses to presented stimuli in milliseconds - I need to build an interactive app that doesn't rely (during the exercise) on form POST data or URL changes.

In short: I have no idea how to go from my simple command line program to a "real time" interactive web application.

Maximum kudos for links to relevant tutorials! I will also really appreciate a high-level explanation of the concept I'm missing here.

(FYI, I asked a previous question (choice of database) about this project here)

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Tr3y
  • 191
  • 4
  • 11

1 Answers1

3

You are going to need to use HTML/Javascript, and then you can collect and send the results to the server. The results can get gamed though, as the code for the exercise is going to be client side.

Edit: I recommend a Javascript library, jQuery: http://docs.jquery.com/Tutorials

Edit 2:

I'll be a bit more specific, you need at least two models in Django, Exercise, and ExecutedExercise. Exercise will have fields with its name, number, etc., generic data for each exercise. ExecutedExercise will have two fields, a foreign key to Exercise, and a field to store how long it took to finish.

Now in Javascript, you're going to time the exercises, and then post them to a Django view that will handle the data storage. How to post them? You could use http://api.jquery.com/jQuery.post/ Create the data string, data = { e1: timingE1, e2: timingE2 } and post it to the view. You can handle the POST parameters in that view, create a ExecutedExercise object (you'll have the time it took for each exercise) and save them.

msc
  • 3,780
  • 1
  • 22
  • 27
  • Questions: what do you mean by 'get gamed'? &, you mean I will have to re-do this in jquery - my python implementation is useless? – Tr3y Aug 05 '11 at 17:36
  • @Tr3y, no, only the frontend system (the interactivity), the retrieving/storing/validating of input can stay in django. But django code runs at the server, you need client code, which can be achieved by jquery. – KillianDS Aug 05 '11 at 17:39
  • By get gamed, I mean, since you're going to implement it client side, and send the results to the server, the client could just make up results and send them. No idea if this is a possible scenario in your situation. – msc Aug 05 '11 at 17:41
  • @killianDS: I already did all the interactivity in python as a command line program. My assumption was that I could give this a GUI and put it directly on the web. But it sounds like Python/Django are only for the backend and the site - I can't use python for the actual exercise. Correct? – Tr3y Aug 05 '11 at 17:42
  • @msc, thanks for the insight, good answer. Any advice on how to protect against rigging the results that way? – Tr3y Aug 05 '11 at 17:49