Skip to content

Commit 9c1d8b9

Browse files
authored
Frontend stuff (#222)
* split out vote button snippet from bill templates * Update to bootstrap 5 * minor tweaks, see twbs/bootstrap#41596 * Activate tooltips globally * split up css files * Add api link to base template * Add permission checking for bill api * Validate API vote data * Update tests * Improve API error messages * Update bootstrap version * Add annotation for user bill vote * Improve view permissions * Fix coverage * Improve vote validation * Fix user vote display on account pages
1 parent 70f0a10 commit 9c1d8b9

38 files changed

Lines changed: 698 additions & 412 deletions

config/settings/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
THIRD_PARTY_APPS = [
6666
"crispy_forms",
67-
"crispy_bootstrap4",
67+
"crispy_bootstrap5",
6868
"allauth",
6969
"allauth.account",
7070
"allauth.socialaccount",
@@ -199,8 +199,8 @@
199199
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
200200

201201
# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
202-
CRISPY_TEMPLATE_PACK = "bootstrap4"
203-
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
202+
CRISPY_TEMPLATE_PACK = "bootstrap5"
203+
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
204204

205205
# FIXTURES
206206
# ------------------------------------------------------------------------------

democrasite/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Global test fixtures for the project."""
22

33
import pytest
4+
from rest_framework.test import APIClient
45
from rest_framework.test import APIRequestFactory
56

67
from democrasite.users.models import User
@@ -28,3 +29,9 @@ def user() -> User:
2829
def api_rf():
2930
"""Return a RequestFactory for use in API tests."""
3031
return APIRequestFactory()
32+
33+
34+
@pytest.fixture
35+
def api_client():
36+
"""Return a RequestFactory for use in API tests."""
37+
return APIClient()

democrasite/static/css/about.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.about-page p {
2+
text-align: justify;
3+
text-align-last: center;
4+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
.note-create {
3+
position: fixed;
4+
bottom: 10px;
5+
right: 5%;
6+
}
7+
8+
.note a:not(.stretched-link) {
9+
z-index: 2;
10+
position: relative;
11+
}
12+
13+
.note-interaction-wrapper {
14+
width: 2em;
15+
}
16+
17+
.note-interaction:hover {
18+
opacity: 75%;
19+
}
20+
21+
.person-follow {
22+
min-width: 6em;
23+
}
24+
25+
.person-unfollow::after {
26+
content: "Following";
27+
}
28+
29+
.person-unfollow:hover::after {
30+
content: "Unfollow";
31+
}
32+
33+
.person-unfollow:hover {
34+
color: var(--light);
35+
background-color: var(--secondary);
36+
}

democrasite/static/css/project.css

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,6 @@ body {
1818
border-color: #eed3d7;
1919
}
2020

21-
/* Prevent styling vote links on expired bills */
22-
.inactive a.vote {
23-
cursor: default;
24-
text-decoration: none;
25-
}
26-
27-
.inactive a.vote.text-success {
28-
color: var(--green) !important;
29-
}
30-
31-
.inactive a.vote.text-danger {
32-
color: var(--red) !important;
33-
}
34-
35-
.git-pull-link {
36-
text-decoration: none !important;
37-
}
38-
39-
.progress {
40-
height: 5px;
41-
}
42-
43-
.about-page p {
44-
text-align: justify;
45-
text-align-last: center;
46-
}
47-
48-
.note-create {
49-
position: fixed;
50-
bottom: 10px;
51-
right: 5%;
52-
}
53-
54-
.note a:not(.stretched-link) {
55-
z-index: 2;
56-
position: relative;
57-
}
58-
59-
/* TODO: remove when upgrading to Bootstrap 5 */
60-
.note-interaction:hover {
61-
opacity: 75%;
62-
text-decoration: none;
63-
}
64-
65-
.person-follow {
66-
min-width: 6em;
67-
}
68-
69-
.person-unfollow::after {
70-
content: "Following";
71-
}
72-
73-
.person-unfollow:hover::after {
74-
content: "Unfollow";
75-
}
76-
77-
.person-unfollow:hover {
78-
color: var(--light);
79-
background-color: var(--secondary);
21+
.icon-link > .bi {
22+
box-sizing: content-box;
8023
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
/* Prevent styling vote links on expired bills */
3+
.inactive a.vote {
4+
cursor: default;
5+
text-decoration: none;
6+
}
7+
8+
.inactive a.vote.text-success {
9+
color: var(--green) !important;
10+
}
11+
12+
.inactive a.vote.text-danger {
13+
color: var(--red) !important;
14+
}
15+
16+
.git-pull-link {
17+
text-decoration: none !important;
18+
}
19+
20+
.progress {
21+
height: 5px;
22+
}

democrasite/static/js/bill.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

democrasite/static/js/project.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
// project-wide js goes here
2+
3+
const tooltipTriggerList = document.querySelectorAll(
4+
'[data-bs-toggle="tooltip"]'
5+
);
6+
const tooltipList = [...tooltipTriggerList].map(
7+
(tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)
8+
);

democrasite/static/js/vote.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
/** This script contains the voting logic and is thus only loaded for logged-in users */
22

3+
function update_progress(_, pbar) {
4+
let votes = $(pbar).siblings(".vote");
5+
let yes_votes = parseInt(votes.children(".num-yes-votes").text());
6+
let no_votes = parseInt(votes.children(".num-no-votes").text());
7+
$(pbar)
8+
.children()
9+
.first()
10+
.css("width", ((100 * yes_votes) / (yes_votes + no_votes) || 0) + "%");
11+
12+
$(pbar)
13+
.children()
14+
.last()
15+
.css("width", ((100 * no_votes) / (yes_votes + no_votes) || 0) + "%");
16+
}
17+
318
$(document).ready(function () {
419
const csrftoken = $("[name=csrfmiddlewaretoken]")[0].value;
520
console.log(csrftoken);
@@ -15,11 +30,11 @@ $(document).ready(function () {
1530
data: { vote: $(this).attr("value") },
1631
context: $(this),
1732
}).done(function (data) {
18-
this.toggleClass("font-weight-bold");
19-
this.siblings(".vote").removeClass("font-weight-bold");
33+
this.toggleClass("fw-bold");
34+
this.siblings(".vote").removeClass("fw-bold");
2035
num = this.attr("id").split("-").slice(-1)[0];
21-
$("#num-yes-votes-" + num).text(data["yes-votes"]);
22-
$("#num-no-votes-" + num).text(data["no-votes"]);
36+
$("#num-vote-yes-" + num).text(data["yes-votes"]);
37+
$("#num-vote-no-" + num).text(data["no-votes"]);
2338
update_progress(0, this.siblings(".progress"));
2439
});
2540
});

democrasite/templates/activitypub/base.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
{% endif %}
5252
{% endblock content %}
5353

54+
{% block extra_css %}
55+
<link href="{% static 'css/activitypub.css' %}" rel="stylesheet" />
56+
{% endblock extra_css %}
57+
5458
{% if user.person %}
5559
{% block inline_javascript %}
5660
<script type="text/javascript" src="{% static 'js/note_interact.js' %}"></script>

0 commit comments

Comments
 (0)