Add render button

This commit is contained in:
Yohann D'ANELLO 2020-03-21 07:36:07 +01:00
parent b030f5797f
commit 8ecaef0daf
4 changed files with 22 additions and 20 deletions

View File

@ -1,20 +1,25 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django_tables2 import tables
import django_tables2 as tables
from django_tables2 import A
from .models import Billing
class BillingTable(tables.Table):
id = tables.LinkColumn("treasury:billing_update", args=[A("pk")])
render = tables.LinkColumn("treasury:billing_render",
args=[A("pk")],
accessor="pk",
text="",
attrs={'a': {'class': 'fa fa-file-pdf-o'}})
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
model = Billing
template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'name', 'subject', 'acquitted', )
row_attrs = {
'class': 'table-row',
'data-href': lambda record: record.pk
}
fields = ('id', 'name', 'subject', 'acquitted', 'render', )

View File

@ -3,11 +3,12 @@
from django.urls import path
from .views import BillingCreateView, BillingListView, BillingUpdateView
from .views import BillingCreateView, BillingListView, BillingUpdateView, BillingRenderView
app_name = 'treasury'
urlpatterns = [
path('billing/', BillingListView.as_view(), name='billing'),
path('billing/create/', BillingCreateView.as_view(), name='billing_create'),
path('billing/<int:pk>/', BillingUpdateView.as_view(), name='billing_update'),
path('billing/render/<int:pk>/', BillingRenderView.as_view(), name='billing_render'),
]

View File

@ -3,6 +3,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import CreateView, UpdateView
from django.views.generic.base import View
from django_tables2 import SingleTableView
from .models import Billing
@ -32,4 +33,10 @@ class BillingUpdateView(LoginRequiredMixin, UpdateView):
"""
model = Billing
fields = '__all__'
# form_class = ClubForm
# form_class = BillingForm
class BillingRenderView(View):
"""
Render Billing
"""

View File

@ -3,19 +3,8 @@
{% load i18n %}
{% block content %}
{% render_table table %}
{% render_table table %}
<a class="btn btn-primary" href="{% url 'treasury:billing_create' %}">{% trans "New billing" %}</a>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
$(document).ready(function($) {
$(".table-row").click(function() {
window.document.location = $(this).data("href");
});
});
</script>
{% endblock %}