Skip to content

Commit

Permalink
Add an expandable section of voting domains
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Nov 6, 2024
1 parent 7095517 commit 821a85b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<details>
<summary
class="collapsible-title"
title="Deschide pentru a vedea domeniile de votare"
>
<h2 class="section-title uppercase ">
{{ section_title }} ({{ counters.ngos_accepted }})
<span class="icon">&#10095;</span>
</h2>
</summary>

<div class="container filter-card-content">

<ul>
{% for domain_details in page_obj %}

<div>
<a
class="inline-subtle-link underlined"
href="#{{ domain_details.domain_key }}">
{{ domain_details.domain.name|upper }}
({{ domain_details.organizations|length }})
</a>
</div>

{% endfor %}
</ul>

</div>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% for section_details in page_obj %}

<h3 class="section-title">
<h3 id="{{ section_details.domain_key }}" class="section-title">
{{ section_details.domain.name }} ({{ section_details.organizations|length }})
</h3>

Expand Down
46 changes: 30 additions & 16 deletions backend/hub/templates/hub/ngo/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,46 @@
value="{{ current_search }}"
aria-label="{% trans 'Search...' %}"
placeholder="{% trans 'Search...' %}">
<label class="search-icon">
<span class="icon is-small is-right">
<i class="fas fa-search"></i>
</span>
<input type="submit" style="display: none;"/>
</label>
<span class="icon is-small is-right">
<i class="fas fa-search" aria-label="search-icon"></i>
</span>
<input
type="submit"
style="display: none;"
aria-label="{% trans 'Search...' %}"
/>
</p>
</div>
</form>
</div>

<h2 class="section-title uppercase">
{% trans "Registered organizations" %} ({{ counters.ngos_accepted }})
</h2>

{% trans "Registered organizations" as section_title %}

{% if page_obj and VOTING_DOMAIN_ENABLED %}

{% include "hub/ngo/components/expandable_voting_domains.html" with section_title=section_title %}

{% else %}

<h2 class="section-title uppercase">
{{ section_title }} ({{ counters.ngos_accepted }})
</h2>

{% endif %}


<div class="container">
{% if page_obj %}

<div class="is-multiline infinite-container">
{% if VOTING_DOMAIN_ENABLED %}
{% include "hub/ngo/components/ngos_listing_by_voting_domain.html" %}
{% else %}
{% include "hub/ngo/components/ngos_listing.html" %}
{% endif %}

{% if VOTING_DOMAIN_ENABLED %}
{% include "hub/ngo/components/ngos_listing_by_voting_domain.html" %}
{% else %}
{% include "hub/ngo/components/ngos_listing.html" %}
{% endif %}

</div>

{% include "hub/shared/pagination.html" with page_obj=page_obj domain=current_domain %}
Expand Down
40 changes: 28 additions & 12 deletions backend/hub/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import unicodedata
from datetime import datetime
from typing import Dict, List, Optional, Union
from urllib.parse import unquote
Expand Down Expand Up @@ -37,6 +38,7 @@
)
from hub.models import (
FLAG_CHOICES,
SETTINGS_CHOICES,
BlogPost,
Candidate,
CandidateConfirmation,
Expand All @@ -46,7 +48,6 @@
Domain,
FeatureFlag,
Organization,
SETTINGS_CHOICES,
)
from hub.workers.update_organization import update_organization

Expand Down Expand Up @@ -244,24 +245,39 @@ class OrganizationListView(SearchMixin):
paginate_by = 9
template_name = "hub/ngo/list.html"

@staticmethod
def _filter_letter(char: str) -> bool:
if char.isalpha():
return True
elif char == " ":
return True

return False

def group_organizations_by_domain(self, queryset) -> List[Dict[str, Union[Domain, List[Organization]]]]:
organizations_by_domain: Dict[Domain, List[Organization]] = {}

for organization in queryset:
domain_name: Domain = organization.voting_domain
if domain_name not in organizations_by_domain:
organizations_by_domain[domain_name] = []
domain: Domain = organization.voting_domain
if domain not in organizations_by_domain:
organizations_by_domain[domain] = []

organizations_by_domain[domain_name].append(organization)
organizations_by_domain[domain].append(organization)

# dictionary to list of dictionaries
organizations_by_domain_list = [
{
"domain": domain,
"organizations": sorted(organizations, key=lambda org: org.name),
}
for domain, organizations in organizations_by_domain.items()
]
organizations_by_domain_list = []
for domain, organizations in organizations_by_domain.items():
snake_case_domain_key = "".join(filter(self._filter_letter, domain.name)).lower().replace(" ", "_")
normalized_domain_key = unicodedata.normalize("NFKD", snake_case_domain_key).encode("ascii", "ignore")

organizations_by_domain_list.append(
{
"domain": domain,
"domain_key": normalized_domain_key.decode("utf-8"),
"organizations": sorted(organizations, key=lambda org: org.name),
}
)

organizations_by_domain_list = sorted(organizations_by_domain_list, key=lambda x: x["domain"].pk)

return organizations_by_domain_list
Expand Down
46 changes: 46 additions & 0 deletions backend/static_extras/css/hub.css
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,49 @@ hr.tight {
border-color: #ffdd57;
color: #5c4a00;
}

.collapsible-title {
overflow: hidden;
cursor: pointer;
}

.active, .collapsible-title:hover {
background-color: #ffdd57;
}

.collapsible-content {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #f1f1f1;
}

details {
user-select: none;
}

details>summary span.icon {
width: 24px;
height: 24px;
transition: all 0.3s;
margin-left: auto;
font: inherit;
font-size: 1em;
}

summary span.icon {
transform: rotate(90deg);
}

details[open] summary span.icon {
transform: rotate(270deg);
}

summary {
display: flex;
cursor: pointer;
}

summary::-webkit-details-marker {
display: none;
}

0 comments on commit 821a85b

Please sign in to comment.