diff --git a/rv_voting_calc/templates/rv_voting_calc/index.html b/rv_voting_calc/templates/rv_voting_calc/index.html index b08953579cda5387d16add0d4fba2f0f8de6f34a..367cc0921908d88d253eb13a1222d61f1c15690f 100644 --- a/rv_voting_calc/templates/rv_voting_calc/index.html +++ b/rv_voting_calc/templates/rv_voting_calc/index.html @@ -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" diff --git a/rv_voting_calc/views.py b/rv_voting_calc/views.py index 38091e416a283bde2817216daedfaf52318a0b84..05261f0aa3e0004bc1e0bfb808989fbfb6b912f2 100644 --- a/rv_voting_calc/views.py +++ b/rv_voting_calc/views.py @@ -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. diff --git a/static_src/rv_voting_calc.js b/static_src/rv_voting_calc.js index 69ba73f8742c06a6b0ddcffc70378f3d95022ef2..828ba0e3e8f8ab7202ca7e1634c103372a4a53b4 100644 --- a/static_src/rv_voting_calc.js +++ b/static_src/rv_voting_calc.js @@ -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); } );