Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20
Commits
e06e3b29
Verified
Commit
e06e3b29
authored
1 year ago
by
bleizi
Browse files
Options
Downloads
Patches
Plain Diff
one question by page
parent
9596aa7b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!218
Wei with questions
Pipeline
#12967
failed with stages
in 15 minutes and 45 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/wei/forms/surveys/wei2023.py
+23
-26
23 additions, 26 deletions
apps/wei/forms/surveys/wei2023.py
with
23 additions
and
26 deletions
apps/wei/forms/surveys/wei2023.py
+
23
−
26
View file @
e06e3b29
...
...
@@ -42,25 +42,11 @@ class WEISurveyForm2023(forms.Form):
Survey form for the year 2023.
Members answer 20 question, from which we calculate the best associated bus.
"""
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
for
question
in
WORDS
:
self
.
fields
[
question
]
=
forms
.
ChoiceField
(
label
=
WORDS
[
question
][
0
]
+
question
,
widget
=
forms
.
RadioSelect
(),
)
def
set_registration
(
self
,
registration
):
"""
Filter the bus selector with the buses of the current WEI.
"""
information
=
WEISurveyInformation2023
(
registration
)
if
not
information
.
seed
:
information
.
seed
=
int
(
1000
*
time
.
time
())
information
.
save
(
registration
)
registration
.
_force_save
=
True
registration
.
save
()
# if self.data:
# for question in WORDS:
...
...
@@ -68,14 +54,14 @@ class WEISurveyForm2023(forms.Form):
# if self.is_valid():
# return
#
rng = Random(information.seed) # add someting if it's alwais the same
#
questions = list(WORDS.keys()
)
#
rng.shuffle(questions)
#
for question in questions:
for
question
in
WORDS
:
answers
=
[(
answer
,
WORDS
[
question
][
1
][
answer
])
for
answer
in
WORDS
[
question
][
1
]]
self
.
fields
[
question
].
choices
=
answers
question
=
information
.
questions
[
information
.
step
]
print
(
information
.
step
,
question
)
self
.
fields
[
question
]
=
forms
.
ChoiceField
(
label
=
WORDS
[
question
][
0
]
+
question
,
widget
=
forms
.
RadioSelect
(),
)
answers
=
[(
answer
,
WORDS
[
question
][
1
][
answer
])
for
answer
in
WORDS
[
question
][
1
]]
self
.
fields
[
question
].
choices
=
answers
class
WEIBusInformation2023
(
WEIBusInformation
):
...
...
@@ -96,10 +82,19 @@ class WEISurveyInformation2023(WEISurveyInformation):
We store the id of the selected bus. We store only the name, but is not used in the selection:
that
'
s only for humans that try to read data.
"""
# Random seed that is stored at the first time to ensure that words are generated only once
seed
=
0
step
=
0
questions
=
list
(
WORDS
.
keys
())
def
__init__
(
self
,
registration
):
# print(hasattr(self,"questions"))
# if not hasattr(self, "questions"):
# rng = Random(int(1000 * time.time()))
# questions = list(WORDS.keys())
# rng.shuffle(questions)
# setattr(self, "questions", questions)
# print(questions)
for
question
in
WORDS
:
setattr
(
self
,
str
(
question
),
None
)
super
().
__init__
(
registration
)
...
...
@@ -129,9 +124,11 @@ class WEISurvey2023(WEISurvey):
@transaction.atomic
def
form_valid
(
self
,
form
):
self
.
information
.
step
+=
1
for
question
in
WORDS
:
answer
=
form
.
cleaned_data
[
question
]
setattr
(
self
.
information
,
question
,
answer
)
if
question
in
form
.
cleaned_data
:
answer
=
form
.
cleaned_data
[
question
]
setattr
(
self
.
information
,
question
,
answer
)
self
.
save
()
@classmethod
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment