# Notes
*Step by step on what I'm working on...*
Going back to this version since I didn't really log anything \& I'm not sure how I fixed this, lol.
1. Running ***otree devserver*** to see what happens.
* PS **C:\Users\lover\Downloads\otree_genderidentityswitching>** otree devserver
Traceback (most recent call last):
File **"C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\database.py"**, line 275, in init_orm
models = get_models_module(app)
File **"C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\common.py"**, line 75, in get_models_module
return import_module(module_name)
File **"C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\importlib\__init__.py"**, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File **""**, line 1050, in _gcd_import
File **""**, line 1027, in _find_and_load
File **""**, line 1006, in _find_and_load_unlocked
File **""**, line 688, in _load_unlocked
File **""**, line 883, in exec_module
File **""**, line 241, in _call_with_frames_removed
File **"C:\Users\lover\Downloads\otree_genderidentityswitching\anagram\_\_init\_\_.py"**, line 2, in
from .. import models ImportError: attempted relative import beyond top-level package
2. Imported automium_web as per suggestion ...doesn't fix anything...
3. Ran ***otree update_my_code***
* 1. scl\pages.py:
-------------------------------------------------------------------------------------------------------------------
| vars_for_all_templates() will not be called automatically. You should rename it to something like "shared_vars",|
| then call it from each page's vars_for_template. For example: |
| |
| def vars_for_template(self): |
| return shared_vars(self) |
| |
| def vars_for_template(self): |
| # combine it with the page's vars |
| return {'a': 1, 'b': 2, **shared_vars(self)} |
| |
---------------------------------------------------------------------------------------------------------------------
|2. anagram\templates\anagram\Task.html: In Bootstrap 5, data-toggle has been renamed to data-bs-toggle.
|3. anagram\templates\anagram\Task.html: In Bootstrap 5, data-target has been renamed to data-bs-target.
|4. anagram_ctb_1\templates\anagram_ctb_1\Task.html: In Bootstrap 5, data-toggle has been renamed to data-bs-toggle.
|5. anagram_ctb_1\templates\anagram_ctb_1\Task.html: In Bootstrap 5, data-target has been renamed to data-bs-target.
|6. group_identity_switch\templates\group_identity_switch\SwitchingVoting.html:
| floatformat is not available because it comes from Django. You should replace it with to0/to1/to2, for example {{ my_number|to2 }}
|Done. all files checked.
|(If you want, you can also run "otree remove_self" to switch to the new 'no self' format)
4. Updating scl\pages as per recommendation in (1) above.
5. Making updates according to (6)
Still won't load... Found funky line 2 in pages.py `from ._builtin import Page, WaitPage`
* Didn't seem in fix it by commenting it out. Getting the error `AttributeError: module 'anagram' has no attribute 'Player'`
* Resolved error by adding variables named Group, Player, Subsession
## Main Problem Found
The main issue was that anagrams file hierarchy cannot have `pages.py`, & `models.py` in separate locations; they must
be included in `__init__.py`. Here the "No-Self" format with a single `__init__.py` says it is supposed to be optional,
but without the new format it won't load deverser... It might be because the other apps are formatted that way already, and it doesn't know how to deal with both.
To-Do:
-[x] Move content into `__init__.py` and delete files
-[x] ~~pages.py~~
-[x] ~~models.py~~
- [] Update content to match otree specifications
-[x] ~~pages.py~~
- [x] models.py
- [x] (3) Replace all mentioned of `self` with `player: Player` | `subsession | Subsession`
- [x] (4) `Constants` class must be renamed `C` to avoid `AttributeError: type object 'Constants' has no attribute 'players_per_group'
- [x] (5) `Constants` must be changed in the html as well
`UndefinedVariable: Cannot resolve the variable 'Constants' (line 25, in "Constants.total_number")`
`File anagram/Instructions2.html, line 25, in Constants.total_number`
- [x] (6) `AttributeError: 'Subsession' object has no attribute 'sync_team_by_sex'` in `File anagram\__init__.py, line 207, in after_all_players_arrive`
- [] ~~Redo group_players logic line 207~~ -wasn't necessary
- [x] Update pip, heroku, and otree requirements.
Example of no-self:
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
kept = models.CurrencyField(
min=0,
max=C.ENDOWMENT,
label="I will keep",
)
# FUNCTIONS
def set_payoffs(group):
player1 = group.get_player_by_id(1)
player2 = group.get_player_by_id(2)
player1.payoff = group.kept
player2.payoff = C.ENDOWMENT - group.kept
# PAGES
class Introduction(Page):
pass
class Offer(Page):
form_model = 'group'
form_fields = ['kept']
def is_displayed(player):
return player.id_in_group == 1
class ResultsWaitPage(WaitPage):
after_all_players_arrive = 'set_payoffs'
class Results(Page):
@staticmethod
def vars_for_template(player):
group = player.group
return dict(payoff=player.payoff, offer=C.ENDOWMENT - group.kept)
* Changed `Constants` class to `C` and capitalized everything.
New Error: (3)
Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 26, in __call__
await response(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\responses.py", line 224, in __call__
await run_until_first_complete(
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\concurrency.py", line 24, in run_until_first_complete
[task.result() for task in done]
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\concurrency.py", line 24, in
[task.result() for task in done]
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\responses.py", line 216, in stream_response
async for chunk in self.body_iterator:
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 56, in body_stream
task.result()
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 38, in coro
await self.app(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\errorpage.py", line 247, in __call__
raise exc # from None
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\errorpage.py", line 227, in __call__
await self.app(scope, receive, _send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 25, in __call__
response = await self.dispatch_func(request, self.call_next)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\middleware.py", line 42, in dispatch
response = await call_next(request)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 45, in call_next
task.result()
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\base.py", line 38, in coro
await self.app(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\middleware\sessions.py", line 75, in __call__
await self.app(scope, receive, send_wrapper)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\patch.py", line 41, in __call__
raise exc # from None
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\patch.py", line 29, in __call__
await self.app(scope, receive, sender)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\routing.py", line 582, in __call__
await route.handle(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\routing.py", line 243, in handle
await self.app(scope, receive, send)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\views\abstract.py", line 118, in dispatch
response = await run_in_threadpool(self.inner_dispatch, request)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\starlette\concurrency.py", line 40, in run_in_threadpool
return await loop.run_in_executor(None, func, *args)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\views\abstract.py", line 425, in inner_dispatch
return self.get()
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\views\abstract.py", line 468, in get
if not self._is_displayed():
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\views\abstract.py", line 236, in _is_displayed
return self.call_user_defined('is_displayed')
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\views\abstract.py", line 89, in call_user_defined
return getattr(type(self), method_name)(self.player, *args, **kwargs)
File "C:\Users\lover\Downloads\otree_genderidentityswitching\anagram\__init__.py", line 170, in is_displayed
return self.player.round_number == 1
File "C:\Users\lover\AppData\Local\Programs\Python\Python310-32\lib\site-packages\otree\database.py", line 586, in __getattribute__
res = super().__getattribute__(attr)
AttributeError: 'Player' object has no attribute 'player'