forked from NYUCCL/psiTurk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: (closes NYUCCL#48)
commit 9e2bd66 Author: Todd Gureckis <todd.gureckis@nyu.edu> Date: Tue Dec 10 00:24:49 2013 -0500 hides the default custom.py from the psiturk import path (Closes NYUCCL#48) kind of hacky, but works for now commit f10b6cc Author: Todd Gureckis <todd.gureckis@nyu.edu> Date: Tue Dec 10 00:15:41 2013 -0500 boom! this works (easier than expected). here's a nicer example to show how - example custom.py script showing how to access various customizable features - who want to write /calculate_bonus (?) commit 81c86ec Author: Todd Gureckis <todd.gureckis@nyu.edu> Date: Mon Dec 9 23:55:39 2013 -0500 moving authentication out as a importable module for end-users - users providing custom routes might want to password protect them (e.g., those providing custom views of data, etc...) - this provides a class-based decorator which can do this commit 5713e0b Author: Todd Gureckis <todd.gureckis@nyu.edu> Date: Mon Dec 9 23:19:39 2013 -0500 oops, lost these files due to .gitignore commit 06f7c7c Author: Todd Gureckis <todd.gureckis@nyu.edu> Date: Mon Dec 9 23:15:33 2013 -0500 very basic start for custom, user-provided routes (Issue NYUCCL#48) - changes to psiturk-setup-example - now create a folder for the files to live in - includes a default 'custom.py' showing how to add custom routes - files moved around so that they can be copied easier (all reside in psiturk/example now)
- Loading branch information
Showing
34 changed files
with
155 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
recursive-include psiturk/templates_example * | ||
recursive-include psiturk/static_example * | ||
recursive-include psiturk/example * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
# this file imports custom routes into the experiment server | ||
|
||
from flask import Blueprint, render_template, request, jsonify, Response, abort | ||
from jinja2 import TemplateNotFound | ||
from functools import wraps | ||
from sqlalchemy import or_ | ||
|
||
from psiturk.psiturk_config import PsiturkConfig | ||
from psiturk.experiment_errors import ExperimentError | ||
from psiturk.user_utils import PsiTurkAuthorization | ||
|
||
# # Database setup | ||
from psiturk.db import db_session, init_db | ||
from psiturk.models import Participant | ||
|
||
|
||
# load the configuration options | ||
config = PsiturkConfig() | ||
config.load_config() | ||
myauth = PsiTurkAuthorization(config) # if you want to add a password protect route use this | ||
|
||
# explore the Blueprint | ||
custom_code = Blueprint('custom_code', __name__, template_folder='templates', static_folder='static') | ||
|
||
|
||
|
||
########################################################### | ||
# serving warm, fresh, & sweet custom, user-provided routes | ||
# add them here | ||
########################################################### | ||
|
||
#---------------------------------------------- | ||
# example custom route | ||
#---------------------------------------------- | ||
@custom_code.route('/my_custom_view') | ||
def my_custom_view(): | ||
try: | ||
return render_template('custom.html') | ||
except TemplateNotFound: | ||
abort(404) | ||
|
||
#---------------------------------------------- | ||
# example using HTTP authentication | ||
#---------------------------------------------- | ||
@custom_code.route('/my_password_protected_route') | ||
@myauth.requires_auth | ||
def my_password_protected_route(): | ||
try: | ||
return render_template('custom.html') | ||
except TemplateNotFound: | ||
abort(404) | ||
|
||
#---------------------------------------------- | ||
# example accessing data | ||
#---------------------------------------------- | ||
@custom_code.route('/view_data') | ||
@myauth.requires_auth | ||
def list_my_data(): | ||
users = Participant.query.all() | ||
try: | ||
return render_template('list.html', participants=users) | ||
except TemplateNotFound: | ||
abort(404) |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Custom Routes</title> | ||
<link rel=stylesheet href="static/css/style.css" type="text/css" media="screen"> | ||
</head> | ||
<body> | ||
<div style="text-align: center;" id="thanks"> | ||
<h1>Booyah, this is an example custom route you can add to your project</h1> | ||
</div> | ||
</body> | ||
|
||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Here are all your users in the database</h1> | ||
|
||
{% for person in participants: %} | ||
{{ person.workerid }} {{ person.ipaddress }}<br> | ||
|
||
{% endfor %} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.