Skip to content
Snippets Groups Projects
Commit fa4f70eb authored by sks444's avatar sks444
Browse files

Add table download csv button and category queations to partners page

parent 3dc5afbf
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,20 @@ class PartnerPage(BasePage):
def get_absolute_url(self):
return self.url
@property
def category_questions(self):
category_questions = {}
if not self.investments.exists():
return
for investment in self.investments.all():
for category in investment.categories.all():
if category.name in category_questions.keys():
if category.value not in category_questions[category.name]:
category_questions[category.name].append(category.value)
else:
category_questions[category.name] = [category.value]
return category_questions
def current_year():
return datetime.date.today().year
......
......@@ -80,6 +80,7 @@ class InvestmentTable(tables.Table):
year = tables.Column(verbose_name='Year')
status = tables.Column(accessor='partner__status', verbose_name='Status')
amount_committed = tables.Column(verbose_name='Amount committed (US$)')
description = tables.Column(visible=False)
class Meta:
model = Investment
......
......@@ -2,6 +2,7 @@
{% load static %}
{% load render_table from django_tables2 %}
{% load querystring from django_tables2 %}
{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/apply/fancybox.css' %}">
......@@ -11,7 +12,6 @@
{% block content %}
{% block table %}
{% include "partner/includes/table_filter_and_search.html" with filter_form=filter_form search_term=search_term use_search=True filter_action=filter_action %}
{% render_table table %}
{% endblock %}
{% endblock %}
......
{% load querystring from django_tables2 %}
<div class="wrapper wrapper--table-actions js-table-actions">
<div class="actions-bar">
{# Left #}
<div class="actions-bar__inner actions-bar__inner--left">
{% if heading %}
<h4 class="heading heading--normal heading--no-margin">{{ heading }}</h4>
{% endif %}
<a class="button button--primary simplified__button" href="{% querystring '_export'='csv' %}">Download CSV</a>
</div>
{# Right #}
......@@ -16,7 +16,7 @@
<button class="button button--search" type="submit" aria-label="Search">
<svg class="icon icon--magnifying-glass icon--search"><use xlink:href="#magnifying-glass"></use></svg>
</button>
<input class="input input--search input--secondary" type="text" placeholder="Search {{ search_placeholder|default:"investments" }}" name="query"{% if search_term %} value="{{ search_term }}"{% endif %} aria-label="Search input">
<input class="input input--search input--secondary" type="text" placeholder="Search {{ search_placeholder|default:"by partner" }}" name="query"{% if search_term %} value="{{ search_term }}"{% endif %} aria-label="Search input">
</form>
{% endif %}
</div>
......
......@@ -8,14 +8,17 @@
{{ page.description|richtext }}
<p class="list list--contact"><span>Status: </span>{{ page.get_status_display }}</p>
<p class="list list--contact"><span>Status</span><br>{{ page.get_status_display }}</p><br>
{% if page.web_url %}
<p class="list list--contact"><span>Website:</span> <a href="{{ page.web_url }}">{{ page.web_url }}</a></p>
<p class="list list--contact"><span>Website</span><br><a href="{{ page.web_url }}">{{ page.web_url }}</a></p><br>
{% endif %}
<p class="list list--contact"><span>Total Investments: </span>US$ {{ total_investments }}</p>
{% for key, value in page.category_questions.items %}
<p class="list list--contact"><span>{{ key }}</span><br>{{ value|join:', ' }}</p><br>
{% endfor %}
<p class="list list--contact"><span>Total Investments: </span>US$ {{ total_investments }}</p>
</div>
<div>
......
from django_filters.views import FilterView
from django_tables2.paginators import LazyPaginator
from django_tables2.views import SingleTableMixin
from django_tables2.export.views import ExportMixin
from .models import Investment
from .tables import InvestmentFilterAndSearch, InvestmentTable
class InvestmentTableView(SingleTableMixin, FilterView):
class InvestmentTableView(ExportMixin, SingleTableMixin, FilterView):
model = Investment
table_class = InvestmentTable
filterset_class = InvestmentFilterAndSearch
filter_action = ''
paginator_class = LazyPaginator
table_pagination = {'per_page': 25}
export_name = 'investments'
template_name = 'partner/investments.html'
def get_table_kwargs(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment