Skip to content

Commit

Permalink
Sort organizations by voting domain if it's enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Oct 28, 2024
1 parent c5b4393 commit c0481a7
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 135 deletions.
4 changes: 3 additions & 1 deletion backend/hub/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def hub_settings(_: WSGIRequest) -> Dict[str, Any]:
"CANDIDATE_VOTING_ENABLED": flags.get(FLAG_CHOICES.enable_candidate_voting, False),
"CANDIDATE_CONFIRMATION_ENABLED": flags.get(FLAG_CHOICES.enable_candidate_confirmation, False),
"RESULTS_ENABLED": flags.get(FLAG_CHOICES.enable_results_display, False),
"GLOBAL_SUPPORT_ENABLED": flags.get(FLAG_CHOICES.global_support_round, False),
"ORG_APPROVAL_ENABLED": flags.get(FLAG_CHOICES.enable_org_approval, False),
"ORG_REGISTRATION_ENABLED": flags.get(FLAG_CHOICES.enable_org_registration, False),
# Settings flags
"GLOBAL_SUPPORT_ENABLED": flags.get(FLAG_CHOICES.global_support_round, False),
"VOTING_DOMAIN_ENABLED": flags.get(FLAG_CHOICES.enable_voting_domain, False),
}
32 changes: 32 additions & 0 deletions backend/hub/templates/hub/ngo/components/ngo_listing_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load static %}

<div class="need is-flex container infinite-item">
<div class="card-image need-logo is-hidden-mobile">
<img src="{% if ngo.logo %}{{ ngo.logo.url }}{% else %}{% static 'images/logo-demo.png' %}{% endif %}" alt="{{ ngo.name }}">
</div>

<div class="card-info">
<div class="flex-align-center">
<div class="card-image need-logo is-hidden-tablet">
<img src="{% if ngo.logo %}{{ ngo.logo.url }}{% else %}{% static 'images/logo-demo.png' %}{% endif %}" alt="{{ ngo.name }}">
</div>
<div class="need-title is-hidden-tablet">{{ ngo.name }}</div>
</div>
<div class="need-title is-hidden-mobile">
<a class="has-text-black" href="{% url 'ngo-detail' ngo.pk %}">{{ ngo.name }}</a>
</div>

</div>

<div class="need-call2action">
<a
class="button is-flex has-background-success-dark has-text-weight-bold has-text-white"
href="{% url 'ngo-detail' ngo.pk %}">
Vizualizează
</a>
</div>

</div>

<hr class="is-hidden-tablet" style="margin: 0 10%;"/>
<hr class="is-hidden-mobile half-width"/>
5 changes: 5 additions & 0 deletions backend/hub/templates/hub/ngo/components/ngos_listing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% for ngo in page_obj %}

{% include "hub/ngo/components/ngo_listing_detail.html" %}

{% endfor %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<hr class="is-hidden-mobile "/>


{% for section_details in page_obj %}

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

{% for ngo in section_details.organizations %}

{% include "hub/ngo/components/ngo_listing_detail.html" %}

{% endfor %}

{% endfor %}

5 changes: 5 additions & 0 deletions backend/hub/templates/hub/ngo/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
</div>
<div class="need-title is-hidden-mobile">{{ ngo.name }}</div>

{% if "approve_organization" in user_permissions or "view_data_organization" in user_permissions and ngo.voting_domain %}
<div class="need-description">
<b>Domeniu: {{ ngo.voting_domain }}</b></div>
{% endif %}

{% if "approve_organization" in user_permissions or "view_data_organization" in user_permissions %}
<div class="need-description"><b>Stare aplicație: <span
class="status-{{ ngo.status }}">{% trans ngo.status.capitalize %}</span></b></div>
Expand Down
138 changes: 7 additions & 131 deletions backend/hub/templates/hub/ngo/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,141 +32,17 @@ <h2 class="section-title uppercase">
{% trans "Registered organizations" %} ({{ counters.ngos_accepted }})
</h2>

{% comment %}
<!-- <div class="container filter-container">
<div class="columns is-mobile">
<div class="column">
<div class="columns">
<div class="column is-narrow filter-dropdown is-marginless">
<div class="dropdown is-hoverable">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu1">
{% if current_county %}
<span>{{ current_county }}</span>
{% else %}
<span>{% trans "County" %}</span>
{% endif %}
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu1" role="menu">
<div class="dropdown-content">
<div class="dropdown-item">
<a href="{% spurl base='{{ request.get_full_path }}' remove_query_param='county' remove_query_param='page' %}"
class="dropdown-item">
{% trans "All" %}
</a>
</div>
{% for county in counties %}
<div class="dropdown-item">
<a href="{% spurl base='{{ request.get_full_path }}' set_query='county={{ county }}' remove_query_param='city' remove_query_param='page' %}"
class="dropdown-item {% if county == current_county %}is-active{% endif %}">
{{ county }}
</a>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<div class="column is-narrow filter-dropdown is-marginless">
<div class="dropdown is-hoverable">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu2">
{% if current_city %}
<span>{{ current_city_name }}</span>
{% else %}
<span>{% trans "City" %}</span>
{% endif %}
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu2" role="menu">
<div class="dropdown-content">
<div class="dropdown-item">
<a href="{% spurl base='{{ request.get_full_path }}' remove_query_param='city' remove_query_param='page' %}"
class="dropdown-item">
{% trans "All" %}
</a>
</div>
{% for city_id, city_name in cities %}
<div class="dropdown-item">
<a href="{% spurl base='{{ request.get_full_path }}' set_query='city={{ city_id }}' remove_query_param='page' %}"
class="dropdown-item {% if city_id == current_city %}is-active{% endif %}">
{{ city_name }}
</a>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="column">
<div class="columns">
<div class="column is-hidden-mobile">
<a class="button is-link is-outlined" href="{% url 'ngos' %}">{% trans "Reset filters" %}</a>
</div>
</div>
</div>
</div>
<a class="button is-link is-outlined is-hidden-tablet" href="{% url 'ngos' %}">
{% trans "Reset filters" %}
</a>
</div> -->
{% endcomment %}

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

<div class="is-multiline infinite-container">
{% for ngo in page_obj %}

<div class="need is-flex container infinite-item">
<div class="card-image need-logo is-hidden-mobile">
<img src="{% if ngo.logo %}{{ ngo.logo.url }}{% else %}{% static 'images/logo-demo.png' %}{% endif %}" alt="{{ ngo.name }}">
</div>

<div class="card-info">
<div class="flex-align-center">
<div class="card-image need-logo is-hidden-tablet">
<img src="{% if ngo.logo %}{{ ngo.logo.url }}{% else %}{% static 'images/logo-demo.png' %}{% endif %}" alt="{{ ngo.name }}">
</div>
<div class="need-title is-hidden-tablet">{{ ngo.name }}</div>
</div>
<div class="need-title is-hidden-mobile">
<a class="has-text-black" href="{% url 'ngo-detail' ngo.pk %}">{{ ngo.name }}</a>
</div>

{% comment %}
<div class="need-description is-hidden-mobile">{% trans 'Founders' %}: {{ ngo.founders }}</div>
<!-- <div class="need-description is-hidden-mobile">{% trans 'Domain' %}: {{ngo.domain}}</div> -->
<!-- <div class="need-description is-hidden-mobile"><b>Stare aplicație: <span
class="status-{{ngo.status}}">{% trans ngo.status.capitalize %}</span></b></div> -->
{% endcomment %}
</div>

<div class="need-call2action">
<a class="button is-flex has-background-success-dark has-text-weight-bold has-text-white"
href="{% url 'ngo-detail' ngo.pk %}">
Vizualizează
</a>
</div>

</div>
<hr class="is-hidden-tablet" style="margin: 0 10%;"/>
<hr class="is-hidden-mobile half-width"/>
{% endfor %}

{% 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
33 changes: 30 additions & 3 deletions backend/hub/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from datetime import datetime
from typing import Dict, Optional
from typing import Dict, List, Optional, Union
from urllib.parse import unquote

from django.conf import settings
Expand Down Expand Up @@ -192,6 +192,28 @@ class OrganizationListView(SearchMixin):
paginate_by = 9
template_name = "hub/ngo/list.html"

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] = []

organizations_by_domain[domain_name].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 = sorted(organizations_by_domain_list, key=lambda x: x["domain"].pk)

return organizations_by_domain_list

def get(self, request, *args, **kwargs):
response = super().get(request, *args, **kwargs)

Expand All @@ -204,9 +226,14 @@ def get_qs(self):
return Organization.objects.filter(status=Organization.STATUS.accepted)

def get_queryset(self):
qs = self.search(self.get_qs())
queryset = self.search(self.get_qs())
filters = {name: self.request.GET[name] for name in self.allow_filters if self.request.GET.get(name)}
return qs.filter(**filters)
queryset_filtered = queryset.filter(**filters)

if FeatureFlag.flag_enabled(SETTINGS_CHOICES.enable_voting_domain):
return self.group_organizations_by_domain(queryset_filtered)

return queryset_filtered

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down

0 comments on commit c0481a7

Please sign in to comment.