Ramdomize order of form fields

310 views
Skip to first unread message

Hakan Pusmaz

unread,
Jun 20, 2021, 9:15:47 AM6/20/21
to oTree help & discussion
Hi everyone,

i don't know how to randomize the order of form fields. Is there a solution for this?

kind regards,
Hakan

Chris @ oTree

unread,
Jun 20, 2021, 6:00:39 PM6/20/21
to oTree help & discussion
get_form_fields

Hakan Pusmaz

unread,
Jun 21, 2021, 8:06:45 AM6/21/21
to oTree help & discussion
Hi Chris, 

It works without shuffling. But after shuffling, it doesn't work. May you help me, please?

form_model = 'player'
def get_form_fields(self):
import random
diamonds = ['duty', 'intellect', 'adversity', 'mating', 'positivity',
'negativity', 'deception', 'sociality', "attention"]
diamonds = random.shuffle(diamonds)

kind regards,
Hakan

Chris @ oTree

unread,
Jun 21, 2021, 8:08:48 AM6/21/21
to Hakan Pusmaz, oTree help & discussion
It’s missing a return statement. 

Sent from my phone

On Jun 21, 2021, at 6:06 AM, 'Hakan Pusmaz' via oTree help & discussion <ot...@googlegroups.com> wrote:

Hi Chris, 
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/05b4b303-82fd-4386-bfa1-445272f9a129n%40googlegroups.com.

Hakan Pusmaz

unread,
Jun 21, 2021, 8:13:46 AM6/21/21
to oTree help & discussion
form_model = 'player'
def get_form_fields(self):
import random
diamonds = ['duty', 'intellect', 'adversity', 'mating', 'positivity',
'negativity', 'deception', 'sociality', "attention"]
diamonds = random.shuffle(diamonds)

return diamonds

Sorry Chris. The statement is there. I did'nt copy it. 

Hakan Pusmaz

unread,
Jun 21, 2021, 8:15:13 AM6/21/21
to oTree help & discussion

I have searched for a solution. But I couldn't find anything. 

Chris @ oTree

unread,
Jun 21, 2021, 8:17:21 AM6/21/21
to Hakan Pusmaz, oTree help & discussion
random.shuffle does not return anything. It shuffles the list in place. You can find more info on this topic on google. 

Sent from my phone

On Jun 21, 2021, at 6:15 AM, 'Hakan Pusmaz' via oTree help & discussion <ot...@googlegroups.com> wrote:



Chris @ oTree

unread,
Jun 21, 2021, 8:19:52 AM6/21/21
to oTree help & discussion
def get_form_fields(self):
  import random
  diamonds = ['duty', 'intellect', 'adversity', 'mating', 'positivity',
    'negativity', 'deception', 'sociality', "attention"]
  random.shuffle(diamonds)
  return diamonds

Hakan Pusmaz

unread,
Jun 21, 2021, 8:25:11 AM6/21/21
to oTree help & discussion
It works :) Thank you very much, Chris!
Reply all
Reply to author
Forward
0 new messages