diff --git a/biscuit/core/menus.py b/biscuit/core/menus.py index 3bd91b4927c81224f4e981f2a27e42c5bc82d706..199f417c49dbbd52e4764d566026269e313122b6 100644 --- a/biscuit/core/menus.py +++ b/biscuit/core/menus.py @@ -14,3 +14,7 @@ Menu.add_item('main', MenuItem('Logout', Menu.add_item('main', MenuItem(_('Interfaces'), '#', check=lambda request: request.user.is_authenticated)) + +Menu.add_item('main', MenuItem(_('Persons'), + reverse('persons'), + check=lambda request: request.user.is_authenticated)) diff --git a/biscuit/core/settings.py b/biscuit/core/settings.py index ca412fb119d7080567dbda9e7645923d1618427e..50fb1409d5bddb59c19a90598fac0845567a5907 100644 --- a/biscuit/core/settings.py +++ b/biscuit/core/settings.py @@ -29,6 +29,7 @@ INSTALLED_APPS = [ 'bootstrap4', 'fa', 'django_any_js', + 'django_tables2', 'menu', 'phonenumber_field', 'biscuit.core' diff --git a/biscuit/core/tables.py b/biscuit/core/tables.py new file mode 100644 index 0000000000000000000000000000000000000000..5d6f480c2031ec85750c017a3ed1c89d1c5b3412 --- /dev/null +++ b/biscuit/core/tables.py @@ -0,0 +1,11 @@ +from django.utils.translation import ugettext_lazy as _ +import django_tables2 as tables +#from django_tables2.utils import A + + +class PersonsTable(tables.Table): + class Meta: + attrs = {'class': 'table table-striped table-bordered table-hover table-responsive-xl'} + + first_name = tables.Column(verbose_name=_('First name')) + last_name = tables.Column(verbose_name=_('Last name')) diff --git a/biscuit/core/templates/core/persons.html b/biscuit/core/templates/core/persons.html new file mode 100644 index 0000000000000000000000000000000000000000..d74e93612be689c77775aa1dd4c59f960a3fea24 --- /dev/null +++ b/biscuit/core/templates/core/persons.html @@ -0,0 +1,14 @@ +{% extends "core/base.html" %} +{% load bootstrap4 i18n %} +{% load render_table from django_tables2 %} + +{% block page_title %}{% blocktrans %}Persons{% endblocktrans %}{% endblock %} + +{% block content %} + <h2> + {% blocktrans %}List of all persons{% endblocktrans %} + </h2> + + {% render_table persons_table %} + +{% endblock %} diff --git a/biscuit/core/urls.py b/biscuit/core/urls.py index 885f72bcc499776c6af2897b4e2f849d23b94e35..1fac42e0994d5ae949178446c18d85a717e213f2 100644 --- a/biscuit/core/urls.py +++ b/biscuit/core/urls.py @@ -9,6 +9,7 @@ from . import views urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), + path('persons', views.persons, name='persons'), path('', views.index, name='index'), ] diff --git a/biscuit/core/views.py b/biscuit/core/views.py index bd5305193788016888c304f779eb2e2045c51324..e4c0929c431a37fea0ec3136363a02c58b1bde69 100644 --- a/biscuit/core/views.py +++ b/biscuit/core/views.py @@ -1,6 +1,23 @@ +from django.contrib.auth.decorators import login_required from django.shortcuts import render - +from django_tables2 import RequestConfig +from .models import Person +from .tables import PersonsTable def index(request): context = {} return render(request, 'core/index.html', context) + +@login_required +def persons(request): + context = {} + + # Get all upcoming persons + persons = Person.objects.all() + + # Build table + persons_table = PersonsTable(persons) + RequestConfig(request).configure(persons_table) + context['persons_table'] = persons_table + + return render(request, 'core/persons.html', context) diff --git a/setup.py b/setup.py index b50c818d4c5034b2d4ff4a76af48c1cbac42c845..29598bf11ac6a1f55906d9d6079ca6651a4f6876 100755 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ setup( 'django-local-settings', 'django-phonenumber-field[phonenumbers]', 'django-simple-menu', + 'django-tables2', 'Pillow' ], classifiers=[