oTree Slider Task.
Project description
# oTree Slider Task
An easy to configure, ready to use slider task for oTree.
This is a beta version, you can help to enhance it by submitting issues and pull requests.
## Installation
```bash
pip3 install slider_task
```
In `settings.py` add `slider_task` to `INSTALLED_APPS`
```python
INSTALLED_APPS = ['otree', 'slider_task']
```
For installing on your server, your `requirements_base.txt` should include `slider_task`.
## Integrating with your experiment
### `models.py`
Add these two import statements at the top:
```python
from otree.db.models import ForeignKey
from slider_task.models import BaseSlider, SliderPlayer
```
If you want to show your sliders in multiple columns, add `slider_columns` to your `Constants`
```python
class Constants(BaseConstants):
slider_columns = 3
# ...
```
Make sure your `Player` class inherits from `SliderPlayer`
```python
class Player(SliderPlayer):
pass
```
Add the `Slider` class, which inherits from `BaseSlider`.
The foreign key assignemnt is required.
```python
class Slider(BaseSlider):
player = ForeignKey(Player)
```
Finally, make sure to call `prepare_sliders()` for each player when creating the session.
Here you can also specify how many sliders you want to show to players as well as their minimum and maximum values which. (The defaults are num=1, min=0, max=100.)
```python
class Subsession(BaseSubsession):
def creating_session(self):
for p in self.get_players():
p.prepare_sliders(num=20, min=0, max=4)
```
### `views.py`
Add these two import statements at the top:
```python
from .models import Slider
from slider_task.pages import SliderTaskPage
```
Let the page, which is supposed to show the slider task inherit from `SliderTaskPage` and assign the Constants and Slider objects. Don't forget to include it in the `page_sequence`.
```python
class Sliders(SliderTaskPage):
Constants = Constants
Slider = Slider
# ...
page_sequence = [
Sliders
]
```
An easy to configure, ready to use slider task for oTree.
This is a beta version, you can help to enhance it by submitting issues and pull requests.
## Installation
```bash
pip3 install slider_task
```
In `settings.py` add `slider_task` to `INSTALLED_APPS`
```python
INSTALLED_APPS = ['otree', 'slider_task']
```
For installing on your server, your `requirements_base.txt` should include `slider_task`.
## Integrating with your experiment
### `models.py`
Add these two import statements at the top:
```python
from otree.db.models import ForeignKey
from slider_task.models import BaseSlider, SliderPlayer
```
If you want to show your sliders in multiple columns, add `slider_columns` to your `Constants`
```python
class Constants(BaseConstants):
slider_columns = 3
# ...
```
Make sure your `Player` class inherits from `SliderPlayer`
```python
class Player(SliderPlayer):
pass
```
Add the `Slider` class, which inherits from `BaseSlider`.
The foreign key assignemnt is required.
```python
class Slider(BaseSlider):
player = ForeignKey(Player)
```
Finally, make sure to call `prepare_sliders()` for each player when creating the session.
Here you can also specify how many sliders you want to show to players as well as their minimum and maximum values which. (The defaults are num=1, min=0, max=100.)
```python
class Subsession(BaseSubsession):
def creating_session(self):
for p in self.get_players():
p.prepare_sliders(num=20, min=0, max=4)
```
### `views.py`
Add these two import statements at the top:
```python
from .models import Slider
from slider_task.pages import SliderTaskPage
```
Let the page, which is supposed to show the slider task inherit from `SliderTaskPage` and assign the Constants and Slider objects. Don't forget to include it in the `page_sequence`.
```python
class Sliders(SliderTaskPage):
Constants = Constants
Slider = Slider
# ...
page_sequence = [
Sliders
]
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.
See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for slider_task-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e6f8fd3beda708196087655846bc7bde420d8ea165e76083054b73d28d06a85 |
|
MD5 | e110b16f4e981f6c4b66fd24a5ee9a85 |
|
BLAKE2b-256 | 16b5077223a939f01677197533d28a2fb5ef74671e0029a8e50b8c4e57b15a6b |