Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Rybička
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
TO
Rybička
Commits
0f65537e
Commit
0f65537e
authored
2 years ago
by
Tomáš
Browse files
Options
Downloads
Patches
Plain Diff
working on voting API
parent
dfb8d7dc
No related branches found
No related tags found
1 merge request
!1
Test release
Pipeline
#11234
failed
2 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
rv_voting_calc/templates/rv_voting_calc/index.html
+14
-6
14 additions, 6 deletions
rv_voting_calc/templates/rv_voting_calc/index.html
rv_voting_calc/views.py
+56
-3
56 additions, 3 deletions
rv_voting_calc/views.py
static_src/rv_voting_calc.js
+14
-4
14 additions, 4 deletions
static_src/rv_voting_calc.js
with
84 additions
and
13 deletions
rv_voting_calc/templates/rv_voting_calc/index.html
+
14
−
6
View file @
0f65537e
...
@@ -14,16 +14,16 @@
...
@@ -14,16 +14,16 @@
<main>
<main>
<h1
class=
"text-6xl font-bebas mb-5"
>
Kalkulačka hlasování RV
</h1>
<h1
class=
"text-6xl font-bebas mb-5"
>
Kalkulačka hlasování RV
</h1>
<div
class=
"grid grid-cols-2 gap-7 mb-5 items-center"
>
<div
class=
"grid grid-cols-2 gap-7 mb-5 pb-4 items-center border-b border-gray-100"
>
<div
class=
"flex items-center gap-3 justify-between"
>
<h2
class=
"text-2xl font-bebas"
>
Hlasy členů
</h2>
<h2
class=
"text-2xl font-bebas"
>
Hlasy členů
</h2>
<div
class=
"flex items-center gap-3 justify-between"
>
<h2
class=
"text-2xl font-bebas"
>
Výsledky
</h2>
<button
<button
class=
"bg-black text-white px-5 py-3 duration-100 hover:bg-gray-800"
class=
"bg-black text-white px-5 py-3 duration-100 hover:bg-gray-800"
id=
"count-votes"
id=
"count-votes"
>
Vypočítat
</button>
>
Vypočítat
</button>
</div>
</div>
<h2
class=
"text-2xl font-bebas"
>
Výsledky
</h2>
</div>
</div>
<div
class=
"grid grid-cols-2 gap-7"
>
<div
class=
"grid grid-cols-2 gap-7"
>
...
@@ -34,14 +34,22 @@
...
@@ -34,14 +34,22 @@
<i
class=
"ico--user text-xl mr-2"
></i>
<i
class=
"ico--user text-xl mr-2"
></i>
{{ member.displayName }}
{{ member.displayName }}
</div>
</div>
<select
class=
"grow w-full __vote-selection"
multiple=
"multiple"
></select>
<select
id=
"{{ member.username }}-selection"
class=
"__vote-selection grow w-full"
multiple=
"multiple"
></select>
</li>
</li>
{% endfor %}
{% endfor %}
</ul>
</ul>
<div>
</div>
</div>
</div>
</main>
</main>
<script>
<script>
const
RV_MEMBERS
=
{{
rv_members
|
safe
}};
const
RV_MEMBERS
=
{{
json_
rv_members
|
safe
}};
</script>
</script>
{% endblock %}
{% endblock %}
This diff is collapsed.
Click to expand it.
rv_voting_calc/views.py
+
56
−
3
View file @
0f65537e
import
json
import
json
import
typing
import
gql
import
gql
import
requests
import
requests
...
@@ -6,11 +7,12 @@ import requests
...
@@ -6,11 +7,12 @@ import requests
from
gql.transport.requests
import
RequestsHTTPTransport
from
gql.transport.requests
import
RequestsHTTPTransport
from
django.conf
import
settings
from
django.conf
import
settings
from
django.http
import
HttpResponseBadRequest
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.views.decorators.http
import
require_POST
# Create your views here.
def
index
(
reque
st
)
:
def
get_rv_members
()
->
li
st
:
transport
=
RequestsHTTPTransport
(
url
=
settings
.
CHOBOTNICE_API_URL
)
transport
=
RequestsHTTPTransport
(
url
=
settings
.
CHOBOTNICE_API_URL
)
client
=
gql
.
Client
(
client
=
gql
.
Client
(
transport
=
transport
,
transport
=
transport
,
...
@@ -44,12 +46,63 @@ def index(request):
...
@@ -44,12 +46,63 @@ def index(request):
# Sort alphabetically
# Sort alphabetically
rv_members
.
sort
(
key
=
lambda
value
:
value
[
"
displayName
"
])
rv_members
.
sort
(
key
=
lambda
value
:
value
[
"
displayName
"
])
return
rv_members
def
convert_rv_members_to_dict
(
source
:
list
)
->
dict
:
rv_members
=
{}
for
member
in
source
:
# Convert to username: {data}
rv_members
[
member
[
"
username
"
]]
=
{
"
displayName
"
:
member
[
"
displayName
"
],
"
officialLastName
"
:
member
[
"
officialLastName
"
]
}
return
rv_members
def
index
(
request
):
rv_members
=
get_rv_members
()
json_rv_members
=
json
.
dumps
(
convert_rv_members_to_dict
(
rv_members
))
return
render
(
return
render
(
request
,
request
,
"
rv_voting_calc/index.html
"
,
"
rv_voting_calc/index.html
"
,
{
{
"
rv_members
"
:
rv_members
,
"
rv_members
"
:
rv_members
,
# JS-Readable format
# JS-Readable format
"
json_rv_members
"
:
json
.
dumps
(
rv_members
),
"
json_rv_members
"
:
json
.
dumps
(
json_
rv_members
),
}
}
)
)
@require_POST
def
get_calculated_votes
(
request
):
votes
=
request
.
GET
.
get
(
"
votes
"
)
if
votes
is
None
:
return
HttpResponseBadRequest
(
"
Nebyly zadány žádné hlasy
"
)
try
:
votes
=
json
.
loads
(
votes
)
if
not
isinstance
(
votes
,
dict
):
raise
ValueError
except
ValueError
:
return
HttpResponseBadRequest
(
"
Formát hlasů není validní
"
)
rv_members
=
convert_rv_members_to_dict
(
get_rv_members
())
rv_member_names_to_clear
=
rv_members
.
keys
()
integrity_check_failed
=
False
for
key
,
value
in
votes
.
items
():
if
key
not
in
rv_member_names_to_clear
:
integrity_check_failed
=
True
break
if
not
isinstance
(
rv_member_names_to_clear
.
pop
(
key
)
This diff is collapsed.
Click to expand it.
static_src/rv_voting_calc.js
+
14
−
4
View file @
0f65537e
...
@@ -103,12 +103,22 @@ $(window).ready(
...
@@ -103,12 +103,22 @@ $(window).ready(
$
(
selection
).
trigger
(
"
change
"
);
$
(
selection
).
trigger
(
"
change
"
);
}
}
}
}
)
)
;
$
(
"
.__vote-selection
"
).
on
(
$
(
"
#count-votes
"
).
on
(
"
c
hange.select2
"
,
"
c
lick
"
,
event
=>
{
event
=>
{
console
.
log
(
"
change
"
);
let
votes
=
{};
for
(
const
username
of
Object
.
keys
(
RV_MEMBERS
))
{
votes
[
username
]
=
[];
for
(
const
data
of
$
(
`#
${
$
.
escapeSelector
(
username
)}
-selection`
).
select2
(
"
data
"
))
{
votes
[
username
].
push
(
data
.
id
);
}
}
console
.
log
(
votes
);
}
}
);
);
}
}
...
...
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