From a2a749e1ca3fcf941d42be4d815de8abece4cc10 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 5 Sep 2021 17:12:41 +0200 Subject: [PATCH] [WEI] Fix permission check to register new accounts to users Signed-off-by: Yohann D'ANELLO --- apps/wei/forms/surveys/wei2021.py | 21 +++++++++++---------- apps/wei/views.py | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/apps/wei/forms/surveys/wei2021.py b/apps/wei/forms/surveys/wei2021.py index ddb0fecb..fd788a74 100644 --- a/apps/wei/forms/surveys/wei2021.py +++ b/apps/wei/forms/surveys/wei2021.py @@ -44,16 +44,17 @@ class WEISurveyForm2021(forms.Form): rng = Random(information.seed) - words = [] - for _ignored in range(information.step + 1): - # Generate N times words - words = None - preferred_words = {bus: [word for word in WORDS if WEIBusInformation2021(bus).scores[word] >= 50] - for bus in WEISurveyAlgorithm2021.get_buses()} - while words is None or len(set(words)) != len(words): - # Ensure that there is no the same word 2 times - words = [rng.choice(words) for _ignored2, words in preferred_words.items()] - rng.shuffle(words) + words = None + # Update seed + rng.randint(0, information.step) + + preferred_words = {bus: [word for word in WORDS if bus.size > 0 + and WEIBusInformation2021(bus).scores[word] >= 50] + for bus in WEISurveyAlgorithm2021.get_buses()} + while words is None or len(set(words)) != len(words): + # Ensure that there is no the same word 2 times + words = [rng.choice(words) for _ignored2, words in preferred_words.items()] + rng.shuffle(words) words = [(w, w) for w in words] if self.data: self.fields["word"].choices = [(w, w) for w in WORDS] diff --git a/apps/wei/views.py b/apps/wei/views.py index cf7c3911..231fc220 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -489,7 +489,7 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView): wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"]) return WEIRegistration( wei=wei, - user=self.request.user, + user=User.objects.get(username="note"), first_year=True, birth_date="1970-01-01", gender="No", @@ -557,7 +557,7 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView): wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"]) return WEIRegistration( wei=wei, - user=self.request.user, + user=User.objects.get(username="note"), first_year=True, birth_date="1970-01-01", gender="No",