Skip to content

Commit

Permalink
Add menu to person based views
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Dec 24, 2024
1 parent ebe9799 commit e968bf2
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 30 deletions.
8 changes: 8 additions & 0 deletions src/votes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def url(self) -> str:
def votes_url(self, year: str = "all"):
return reverse("person_votes", kwargs={"person_id": self.id, "year": year})

def recent_years_with_votes(self):
items = (
self.rebellion_rates.filter(period_type=RebellionPeriodType.YEAR)
.order_by("-period_number")
.values_list("period_number", flat=True)
)
return [str(x) for x in items]

def rebellion_rate_df(self):
items = self.rebellion_rates.filter(
period_type=RebellionPeriodType.YEAR
Expand Down
50 changes: 35 additions & 15 deletions src/votes/templates/votes/person.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
{% extends "votes/base.html" %}
{% extends "votes/base_with_menu.html" %}

{% block title %}{{ settings.site_name }}{% endblock %}

{% block content.inner %}
<h1>{{ person.name }}</h1>
<h2>Options</h2>
<ul>
<li>
<a href="{% url 'person_votes' person.id 'all' %}">All recorded votes.</a>
</li>
{% for record in person.policy_distribution_groups %}
<li>
<a href="{% url 'person_policy' person.id record.chamber.slug record.party.slug record.period.slug.lower %}">Voting
record comparison with {{ record.party.name }} (Period: {{ record.period.description }})</a>
{% block content.title %}
<h1 id="top-header">{{ person.name }} - Votes and party alignment</h1>
{% endblock content.title %}

{% block content.menu %}
<p>
<a id="side-top-header"
class="nav-link h6 pl-0 mb-0"
href="#top"
style="display:none">{{ person.name }}</a>
</p>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0 {% if person_view == 'overview' %}active{% endif %}"
href="{% url 'person' person.id %}">Overview</a>
</li>
{% with person.policy_distribution_groups as pdg %}
{% if pdg %}
<li class="nav-item">
<ul class="nav flex-column py-2 border-top my-2">
{% for record in person.policy_distribution_groups %}
<li class="nav-item" class="nav-item">
<a class="nav-link h6 pl-0 mb-0"
href="{% url 'person_policy' person.id record.chamber.slug record.party.slug record.period.slug.lower %}">Voting summary - {{ record.party.name }} (Period: {{ record.period.description }})</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<h2>Votes and party alignment</h2>
{% endif %}
{% endwith %}
{% endblock content.menu %}

{% block content.inner %}
{% style_df person.rebellion_rate_df "Party alignment" %}
{% endblock content.inner %}

Expand All @@ -25,6 +42,9 @@ <h2>Votes and party alignment</h2>
href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.css" />
{% endblock extracss %}

{% block menujs.section %}
{% endblock menujs.section %}

{% block extrajs %}
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.js"></script>
<script>
Expand Down
36 changes: 31 additions & 5 deletions src/votes/templates/votes/person_policies.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
{% extends "votes/base.html" %}
{% extends "votes/base_with_menu.html" %}

{% block title %}{{ settings.site_name }}{% endblock %}

{% block content.title %}
<h1 id = "top-header">{{ person.name }} Voting Summary</h1>
<p>
Compared with {{ party.name }} {{ chamber.member_plural }} in {{ chamber.name }} for period: {{ period.description }}.
</p>
{% endblock content.title %}

{% block content.menu %}
<p>
<a id="side-top-header"
class="nav-link h6 pl-0 mb-0"
href="#top"
style="display:none">{{ person.name }} - {{ party.name }}</a>
</p>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0 {% if person_view == 'overview' %}active{% endif %}"
href="{% url 'person' person.id %}">Overview</a>
</li>
<hr />
{% for group in collection %}
{% if group|length > 0 %}
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0" href="#{{ group.slug }}">{{ group.name }}</a>
</li>
{% endif %}
{% endfor %}
{% endblock content.menu %}

{% block content.inner %}
<h1>{{ person.name }}</h1>
<p>Compared with {{ party.name }} {{ chamber.member_plural }} in {{ chamber.name }}</p>
<p>This list contains candidate policies that have not been finalised for feeding into TheyWorkForYou.</p>
{% for group in collection %}
{% if group|length > 0 %}
<h2>{{ group.name }}</h2>
<h2 class="section-header" id={{ group.slug }}>{{ group.name }}
</h2>
{% style_df group.as_df %}
{% endif %}
{% endfor %}
Expand Down
63 changes: 56 additions & 7 deletions src/votes/templates/votes/person_policy.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
{% extends "votes/base.html" %}
{% extends "votes/base_with_menu.html" %}

{% block title %}{{ settings.site_name }}{% endblock %}

{% block content.inner %}
{% block content.title %}
<h1>{{ policy.name }}</h1>
{% endblock content.title %}

{% block content.menu %}
<p>
<a id="side-top-header"
class="nav-link h6 pl-0 mb-0"
href="#top"
style="display:none">{{ person.name }} - {{ party.name }}</a>
</p>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0"
{% if person_view == 'overview' %}active{% endif %}
"
"
href="{% url 'person' person.id %}">Overview</a>
</li>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0"
{% if person_view == 'overview' %}active{% endif %}
"
"
href="{% url 'person_policy' person.id chamber.slug party.slug period.slug.lower %}">Back to policy list</a>
</li>
<hr />
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0" href="#description">Policy description</a>
</li>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0" href="#analysis">Analysis</a>
</li>
{% for vote_group, df in decision_links_and_votes.items %}
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0" href="#{{ vote_group }}">
{% if vote_group == "strong_votes" %}
Scoring Divisions
{% elif vote_group == "weak_votes" %}
Informative Divisions
{% elif vote_group == "strong_agreements" %}
Scoring Agreements
{% elif vote_group == "weak_agreements" %}
Informative Agreements
{% endif %}
</a>
</li>
{% endfor %}
{% endblock content.menu %}

{% block content.inner %}
<h2 class="section-header" id="description">Policy description</h2>
<p>{{ policy.policy_description }}</p>
</p>
View <a href="{{ policy.url }}">policy details</a>.
</p>
<h2>Analysis for {{ person.name }}</h2>
<h2 class="section-header" id="analysis">Analysis for {{ person.name }}</h2>
{% if own_distribution %}
<p>
<b>{{ person.name }}</b> {{ own_distribution.verbose_score.lower }} ({{ own_distribution.str_similarity_percentage }} aligned) {{ policy.context_description|safe }}.
Expand All @@ -21,21 +70,21 @@ <h2>Analysis for {{ person.name }}</h2>
{% endif %}
{% for vote_group, df in decision_links_and_votes.items %}
{% if vote_group == "strong_votes" %}
<h2>Scoring Divisions</h2>
<h2 class="section-header" id="{{ vote_group }}">Scoring Divisions</h2>
<div class = "group-desc">
{% markdown %}
Scoring divisions are used to calculate the headline alignment between a person and a policy.
{% endmarkdown %}
</div>
{% elif vote_group == "weak_votes" %}
<h2>Informative Divisions</h2>
<h2 class="section-header" id="{{ vote_group }}">Informative Divisions</h2>
<div class = "group-desc">
{% markdown %}
Informative votes are thematically related to a policy, but do not count towards the overall score.
{% endmarkdown %}
</div>
{% elif vote_group == "strong_agreements" %}
<h2>Scoring Agreements</h2>
<h2 class="section-header" id="{{ vote_group }}">Scoring Agreements</h2>
<div class = "group-desc">
{% markdown %}
Scoring agreements contribute to the headline alignment between a person and a policy.
Expand All @@ -44,7 +93,7 @@ <h2>Scoring Agreements</h2>
{% endmarkdown %}
</div>
{% elif vote_group == "weak_agreements" %}
<h2>Informative Agreements</h2>
<h2 class="section-header" id="{{ vote_group }}">Informative Agreements</h2>
<div class = "group-desc">
{% markdown %}
Scoring agreements are thematically related to a policy, but do not count towards the overall score.
Expand Down
32 changes: 29 additions & 3 deletions src/votes/templates/votes/person_votes.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
{% extends "votes/base.html" %}
{% extends "votes/base_with_menu.html" %}

{% block title %}{{ settings.site_name }}{% endblock %}

{% block content.title %}<h1 id="top-header">{{ person.name }} Votes: {{ period }}</h1>{% endblock %}

{% block content.menu %}
<p>
<a id="side-top-header"
class="nav-link h6 pl-0 mb-0"
href="#top"
style="display:none">{{ person.name }} Votes: {{ period }}</a>
</p>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0 {% if person_view == 'overview' %}active{% endif %}"
href="{% url 'person' person.id %}">Overview</a>
</li>
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0 {% if year == "all" %}active{% endif %}"
href="{% url 'person_votes' person.id "all" %}">All time</a>
</li>
{% for opt_year in person.recent_years_with_votes %}
<li class="nav-item">
<a class="nav-link h6 pl-0 mb-0 {% if opt_year == year %}active{% endif %}"
href="{% url 'person_votes' person.id opt_year %}">{{ opt_year }}</a>
</li>
{% endfor %}
{% endblock content.menu %}

{% block content.inner %}
<h1>{{ person.name }}</h1>
<h2>Votes: {{ period }}</h2>
{% style_df votes_df "Party alignment" %}
{% endblock content.inner %}

Expand All @@ -13,6 +36,9 @@ <h2>Votes: {{ period }}</h2>
href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.css" />
{% endblock extracss %}

{% block menujs.section %}
{% endblock menujs.section %}

{% block extrajs %}
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.js"></script>
<script>
Expand Down
3 changes: 3 additions & 0 deletions src/votes/views/helper_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_key(v: VoteDistribution) -> str:
groups.append(
PolicyDisplayGroup(
name="Significant Policies",
slug="significant",
paired_policies=sig_links,
url_base=url_base,
)
Expand All @@ -136,6 +137,7 @@ def get_key(v: VoteDistribution) -> str:
groups.append(
PolicyDisplayGroup(
name=slug_lookup[group_slug].description,
slug=group_slug,
paired_policies=grouped_items,
url_base=url_base,
)
Expand All @@ -148,6 +150,7 @@ class PolicyDisplayGroup(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)

name: str
slug: str
url_base: list[str | int]
paired_policies: list[PairedPolicy]

Expand Down
2 changes: 2 additions & 0 deletions src/votes/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class PersonPageView(TitleMixin, TemplateView):
def get_context_data(self, person_id: int, **kwargs):
context = super().get_context_data(**kwargs)
context["person"] = Person.objects.get(id=person_id)
context["person_view"] = "overview"
return context


Expand All @@ -339,6 +340,7 @@ def get_context_data(self, person_id: int, year: str, **kwargs):
context = super().get_context_data(**kwargs)

person = Person.objects.get(id=person_id)
context["year"] = year
context["person"] = person
if year == "all":
context["period"] = "All time"
Expand Down

0 comments on commit e968bf2

Please sign in to comment.