Skip to content
Snippets Groups Projects
Commit afc2b8f9 authored by Tomáš's avatar Tomáš
Browse files

ensure repeatability

parent 42c48e82
No related branches found
No related tags found
1 merge request!1Test release
Pipeline #11289 failed
......@@ -10,12 +10,12 @@
{% render_bundle "rv_voting_calc" %}
<link
href="https://styleguide.pirati.cz/2.11.x/css/styles.css"
href="https://styleguide.pirati.cz/2.10.x/css/styles.css"
rel="stylesheet"
media="all"
>
<link
href="https://styleguide.pirati.cz/2.11.x/css/pattern-scaffolding.css"
href="https://styleguide.pirati.cz/2.10.x/css/pattern-scaffolding.css"
rel="stylesheet"
media="all"
>
......@@ -25,7 +25,7 @@
<main>
<h1 class="text-6xl font-bebas mb-5">Kalkulačka hlasování RV</h1>
<div class="grid grid-cols-2 gap-7 mb-5 pb-4 items-center border-b border-gray-100">
<div class="grid grid-cols-1 md:grid-cols-2 gap-7 mb-5 pb-4 items-center border-b border-gray-100">
<h2 class="text-2xl font-bebas">Hlasy členů</h2>
<div class="flex items-center gap-3 justify-between">
......@@ -42,7 +42,7 @@
</div>
</div>
<div class="grid grid-cols-2 gap-7">
<div class="grid grid-cols-1 md:grid-cols-2 gap-7">
<ul class="flex flex-col gap-2">
{% for member in rv_members %}
<li class="flex gap-4 items-center">
......@@ -66,7 +66,7 @@
>
</ul>
<div class="mt-4 flex gap-4 justify-end">
<div class="mt-4 flex gap-4 md:justify-end justify-center">
<a
class="hidden btn"
id="permalink"
......
......@@ -4,6 +4,7 @@ import json
import math
import random
import secrets
import urllib.parse
import gql
import requests
......@@ -57,6 +58,8 @@ def index(request):
# Get votes from a possible permalink
options_by_member = request.GET.get("votes")
if options_by_member is not None:
options_by_member = urllib.parse.unquote(options_by_member)
# BEGIN Input validation
if options_by_member is not None:
......@@ -86,12 +89,12 @@ def get_rv_members(request, get_rv_gid: bool = False):
rv_gid = None
if "rv_gid" in request.GET:
rv_gid = urllib.parse.unquote(request.GET["rv_gid"])
try:
base64.b64decode(request.GET["rv_gid"], validate=True)
base64.b64decode(rv_gid, validate=True)
except binascii.Error:
raise HTTPExceptions.BAD_REQUEST
rv_gid = request.GET["rv_gid"]
else:
rv_gid = settings.CHOBOTNICE_RV_GID
......@@ -465,6 +468,8 @@ def do_step_b_through_d(
def get_calculated_votes(request):
options_by_member = request.GET.get("votes")
if options_by_member is not None:
options_by_member = urllib.parse.unquote(options_by_member)
# BEGIN Input validation
......@@ -596,8 +601,15 @@ def get_calculated_votes(request):
base64.b64encode(secrets.token_bytes()).decode("utf-8")
)
)
# Unquote the seed if it was found in the URL parameters
if "seed" in request.GET:
seed = urllib.parse.unquote(seed)
random.seed(seed)
print(seed)
# Continue until steps B - D have reached a final conclusion and count
# the amount of times the function ran to achieve this.
iteration = 0
......@@ -623,6 +635,7 @@ def get_calculated_votes(request):
"md_steps": md_steps
}
)
# Set the random seed cookie to the one used in the calculation.
response.set_cookie("seed", seed)
# Do the same for RV's GID.
......
......@@ -93,11 +93,11 @@ $(window).ready(
+ `?votes=${encodeURIComponent(JSON.stringify(votes))}`
+ (
(rvGid !== null) ?
`&rv_gid=${rvGid}` : ""
`&rv_gid=${encodeURIComponent(rvGid)}` : ""
)
+ (
(seed !== null) ?
`&seed=${seed}` : ""
`&seed=${encodeURIComponent(seed)}` : ""
)
);
......@@ -115,8 +115,8 @@ $(window).ready(
// Base URL
window.location.href.split('?')[0]
+ `?votes=${encodeURIComponent(JSON.stringify(votes))}`
+ `&rv_gid=${Cookies.get("rv_gid")}`
+ `&seed=${Cookies.get("seed")}`
+ `&rv_gid=${encodeURIComponent(Cookies.get("rv_gid"))}`
+ `&seed=${encodeURIComponent(Cookies.get("seed"))}`
)
);
$("#download-log").attr(
......@@ -127,6 +127,7 @@ $(window).ready(
)
);
$("#result")[0].scrollIntoView();
$(event.currentTarget).removeClass("btn--loading").prop("disabled", false);
}
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment