Skip to content

Commit

Permalink
Uses Django Public Admin package
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed Apr 4, 2020
1 parent 350e46d commit c1045e6
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 161 deletions.
18 changes: 14 additions & 4 deletions jarbas/dashboard/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.db.models import Count, F, Sum
from django.db.models.functions import Concat
from django.utils.safestring import mark_safe
from public_admin.admin import PublicModelAdmin
from public_admin.sites import PublicAdminSite

from jarbas.chamber_of_deputies.models import (
Reimbursement,
Expand All @@ -18,16 +20,14 @@
from jarbas.dashboard.admin import list_filters, widgets
from jarbas.dashboard.admin.paginators import CachedCountPaginator
from jarbas.dashboard.admin.subquotas import Subquotas
from jarbas.public_admin.admin import PublicAdminModelAdmin
from jarbas.public_admin.sites import public_admin


ALL_FIELDS = sorted(Reimbursement._meta.fields, key=lambda f: f.verbose_name)
CUSTOM_WIDGETS = ('receipt_url', 'subquota_description', 'suspicions')
READONLY_FIELDS = (f.name for f in ALL_FIELDS if f.name not in CUSTOM_WIDGETS)


class ReimbursementModelAdmin(PublicAdminModelAdmin):
class ReimbursementModelAdmin(PublicModelAdmin):

list_display = (
'short_document_id',
Expand Down Expand Up @@ -183,7 +183,7 @@ def get_search_results(self, request, queryset, search_term):
return queryset, distinct


class ReimbursementSummaryModelAdmin(PublicAdminModelAdmin):
class ReimbursementSummaryModelAdmin(PublicModelAdmin):
change_list_template = 'dashboard/reimbursement_summary_change_list.html'
list_filter = (
list_filters.SuspiciousListFilter,
Expand Down Expand Up @@ -307,5 +307,15 @@ def changelist_view(self, request, extra=None):
return response


class JarbasPublicAdminSite(PublicAdminSite):
site_title = 'Dashboard'
site_header = 'Jarbas Dashboard'
index_title = 'Jarbas'


public_admin = JarbasPublicAdminSite(
public_apps=('chamber_of_deputies',),
public_models=('reimbursements',)
)
public_admin.register(Reimbursement, ReimbursementModelAdmin)
public_admin.register(ReimbursementSummary, ReimbursementSummaryModelAdmin)
15 changes: 15 additions & 0 deletions jarbas/dashboard/templates/templates/admin/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "admin/base.html" %}

{% block footer %}
<div id="footer"></div>
{% if google_analytics %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '{{ google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{% extends "admin/change_list.html" %}
{% load dashboard %}

{% block content_title %}
<h1>
Resumo dos reembolsos da CEAP
{% if year or month %}-{% endif %}
{% if month %}{{ month }}{% endif %}
{% if year and month %}/{% endif %}
{% if year %}{{ year }}{% endif %}
</h1>
{% endblock %}

{% block result_list %}
<div class="results">
<table>

<thead>
<tr>
<th>
<div class=”text”>
<a href=”#”>Categoria (sub-cota)</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>Número de reembolsos</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>Valor total</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>
<strong>% do total</strong>
</a>
</div>
</th>
</tr>
</thead>

<tbody>
{% for row in summary %}
<tr class=”{% cycle 'row1' 'row2' %}”>
<td>{{ row.subquota_description|translate_subquota }}</td>
<td>{{ row.total_reimbursements|brazilian_integer }}</td>
<td>{{ row.total_value|brazilian_reais }}</td>
<td>
<strong>
{{ row.total_value|default:0|percentof:summary_total.total_value }}
</strong>
</td>
</tr>
{% endfor %}
</tbody>

<tfoot>
<tr style=”font-weight:bold; border-top:2px solid #DDDDDD;”>
<td> Total </td>
<td>{{ summary_total.total_reimbursements|brazilian_integer }}</td>
<td>{{ summary_total.total_value|brazilian_reais }}</td>
<td>100%</td>
</tr>
</tfoot>

</table>
</div>

<p>&nbsp;</p>

{% if summary_over_time|length > 1 %}
<div class="results">
<h2>Reembolsos por período (por {{ chart_grouping|translate_chart_grouping }})</h2>
<div class="bar-chart">
{% for data in summary_over_time %}
<div class="bar" style="height:{{ data.percent }}%">
<div class="bar-tooltip">
{{ data.total|brazilian_reais }}<br>
{% if chart_grouping == 'year' %}
{{ data.chart_grouping|chart_grouping_as_date|date:"Y"}}
{% else %}
{{ data.chart_grouping|chart_grouping_as_date|date:"m/Y"}}
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>

</div>
{% endif %}

{% endblock %}

{% block pagination %}{% endblock %}
15 changes: 15 additions & 0 deletions jarbas/dashboard/templates/templates/templates/admin/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "admin/base.html" %}

{% block footer %}
<div id="footer"></div>
{% if google_analytics %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', '{{ google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{% extends "admin/change_list.html" %}
{% load dashboard %}

{% block content_title %}
<h1>
Resumo dos reembolsos da CEAP
{% if year or month %}-{% endif %}
{% if month %}{{ month }}{% endif %}
{% if year and month %}/{% endif %}
{% if year %}{{ year }}{% endif %}
</h1>
{% endblock %}

{% block result_list %}
<div class="results">
<table>

<thead>
<tr>
<th>
<div class=”text”>
<a href=”#”>Categoria (sub-cota)</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>Número de reembolsos</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>Valor total</a>
</div>
</th>
<th>
<div class=”text”>
<a href=”#”>
<strong>% do total</strong>
</a>
</div>
</th>
</tr>
</thead>

<tbody>
{% for row in summary %}
<tr class=”{% cycle 'row1' 'row2' %}”>
<td>{{ row.subquota_description|translate_subquota }}</td>
<td>{{ row.total_reimbursements|brazilian_integer }}</td>
<td>{{ row.total_value|brazilian_reais }}</td>
<td>
<strong>
{{ row.total_value|default:0|percentof:summary_total.total_value }}
</strong>
</td>
</tr>
{% endfor %}
</tbody>

<tfoot>
<tr style=”font-weight:bold; border-top:2px solid #DDDDDD;”>
<td> Total </td>
<td>{{ summary_total.total_reimbursements|brazilian_integer }}</td>
<td>{{ summary_total.total_value|brazilian_reais }}</td>
<td>100%</td>
</tr>
</tfoot>

</table>
</div>

<p>&nbsp;</p>

{% if summary_over_time|length > 1 %}
<div class="results">
<h2>Reembolsos por período (por {{ chart_grouping|translate_chart_grouping }})</h2>
<div class="bar-chart">
{% for data in summary_over_time %}
<div class="bar" style="height:{{ data.percent }}%">
<div class="bar-tooltip">
{{ data.total|brazilian_reais }}<br>
{% if chart_grouping == 'year' %}
{{ data.chart_grouping|chart_grouping_as_date|date:"Y"}}
{% else %}
{{ data.chart_grouping|chart_grouping_as_date|date:"m/Y"}}
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>

</div>
{% endif %}

{% endblock %}

{% block pagination %}{% endblock %}
2 changes: 1 addition & 1 deletion jarbas/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from jarbas.public_admin.sites import public_admin
from jarbas.dashboard.admin import public_admin


urlpatterns = [
Expand Down
Empty file removed jarbas/public_admin/__init__.py
Empty file.
30 changes: 0 additions & 30 deletions jarbas/public_admin/admin.py

This file was deleted.

61 changes: 0 additions & 61 deletions jarbas/public_admin/sites.py

This file was deleted.

Empty file.
Loading

0 comments on commit c1045e6

Please sign in to comment.