diff --git a/biscuit/core/static/css/style.css b/biscuit/core/static/css/style.css new file mode 100644 index 0000000000000000000000000000000000000000..e74da43733d521bde563adfb94b4f4bf5a6465e4 --- /dev/null +++ b/biscuit/core/static/css/style.css @@ -0,0 +1,3 @@ +img.person-img { + max-height: 300px; +} diff --git a/biscuit/core/static/img/fallback.png b/biscuit/core/static/img/fallback.png new file mode 100644 index 0000000000000000000000000000000000000000..a39964ba07f9a6aea6b53943f8e79199cb204c87 Binary files /dev/null and b/biscuit/core/static/img/fallback.png differ diff --git a/biscuit/core/tables.py b/biscuit/core/tables.py index 5d6f480c2031ec85750c017a3ed1c89d1c5b3412..f4a8e508a4af78c69c81d75a77c00d2b1b3249e8 100644 --- a/biscuit/core/tables.py +++ b/biscuit/core/tables.py @@ -1,11 +1,11 @@ from django.utils.translation import ugettext_lazy as _ import django_tables2 as tables -#from django_tables2.utils import A +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')) + first_name = tables.LinkColumn('person_by_id', args=[A('id')]) + last_name = tables.LinkColumn('person_by_id', args=[A('id')]) diff --git a/biscuit/core/templates/core/base.html b/biscuit/core/templates/core/base.html index a55cafdddc8a1f8988fc69a43756851b1c05eb83..320c744556f6d6905c85ddfc11dbdceb7916ee41 100644 --- a/biscuit/core/templates/core/base.html +++ b/biscuit/core/templates/core/base.html @@ -5,8 +5,9 @@ {% block bootstrap4_title %}BiscuIT School Information System{% endblock %} {% block bootstrap4_extra_head %} + {% fa_css %} {% include_css "DataTables-Bootstrap4" %} - <link rel="stylesheet" href="{% static 'style.css' %}" /> + <link rel="stylesheet" href="{% static 'css/style.css' %}" /> <link rel="shortcut icon" href="#" /> {% endblock %} diff --git a/biscuit/core/templates/core/person.html b/biscuit/core/templates/core/person.html new file mode 100644 index 0000000000000000000000000000000000000000..af0dc931229f7db879629fee4e2c7e09f2193b61 --- /dev/null +++ b/biscuit/core/templates/core/person.html @@ -0,0 +1,83 @@ +{% extends "core/base.html" %} +{% load bootstrap4 font_awesome i18n staticfiles %} + +{% block content %} +<div class="col-sm-12 col-md-12"> + {% if person %} + <h2>{{ person.first_name }} {{ person.last_name }}</h2> + <p> + <a href="{{ '#' }}"> + {% blocktrans %}Edit person{% endblocktrans %} + </a> + </p> + <h3>{% blocktrans %}Contact details{% endblocktrans %}</h3> + <table class="table table-responsive-xl table-border table-striped"> + <tr> + <td rowspan="6"> + {% if person.photo %} + <img class="person-img" src="{{ person.photo.url }}" alt="{{ person.first_name }} {{ person.last_name }}" /> + {% else %} + <img class="person-img" src="{% static 'img/fallback.png' %}" alt="{{ person.first_name }} {{ person.last_name }}" /> + {% endif %} + </td> + <td>{% fa 'user' %}</td> + <td>{{ person.first_name }}</td> + <td>{{ person.additional_name }}</td> + <td>{{ person.last_name }}</td> + </tr> + <tr> + <td>{% fa 'venus-mars' %}</td> + <td colspan="3">{{ person.get_sex_display }}</td> + </tr> + <tr> + <td>{% fa 'fa-home' %}</td> + <td colspan="2">{{ person.street }} {{ person.housenumber }}</td> + <td colspan="2">{{ person.postal_code }} {{ person.place }}</td> + </tr> + <tr> + <td>{% fa 'phone-square' %}</td> + <td>{{ person.phone_number }}</td> + <td>{{ person.mobile_number }}</td> + </tr> + <tr> + <td>{% fa 'envelope' %}</td> + <td colspan="3">{{ person.email }}</td> + </tr> + <tr> + <td>{% fa 'gift' %}</td> + <td colspan="3">{{ person.date_of_birth|date }}</td> + </tr> + {% comment %} + <tr> + <td>{% fa 'graduation-cap' %}</td> + <td>Class</td> + <td>Teacher</td> + </tr> + {% endcomment %} + </table> + + {# Will be implemted soon #} + <table class="table table-responsive-xl table-border table-striped"> + <tr> + <td>Member</td> + <td> + <h4>Groups</h4> + <ul> + <li><a href="#">Foo</a></li> + <li><a href="#">Foo</a></li> + <li><a href="#">Foo</a></li> + <li><a href="#">Foo</a></li> + </td> + </tr> + </table> + {% else %} + <h2>{% blocktrans %}Person not found{% endblocktrans %}</h2> + + <p> + {% blocktrans %} + There is no person with this id. + {% endblocktrans %} + </p> + {% endif %} +</div> +{% endblock %} diff --git a/biscuit/core/urls.py b/biscuit/core/urls.py index 1fac42e0994d5ae949178446c18d85a717e213f2..781d9f223d413d394342370843f3dd084fb1a361 100644 --- a/biscuit/core/urls.py +++ b/biscuit/core/urls.py @@ -10,6 +10,8 @@ urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), path('persons', views.persons, name='persons'), + path('person', views.person, name='person'), + path('person/<int:id_>', views.person, name='person_by_id'), path('', views.index, name='index'), ] diff --git a/biscuit/core/views.py b/biscuit/core/views.py index e4c0929c431a37fea0ec3136363a02c58b1bde69..8154e4aaf62d21b0512a449216197ab856280545 100644 --- a/biscuit/core/views.py +++ b/biscuit/core/views.py @@ -1,6 +1,9 @@ from django.contrib.auth.decorators import login_required -from django.shortcuts import render +from django.utils.translation import gettext as _ +from django.http import Http404 +from django.shortcuts import redirect, render from django_tables2 import RequestConfig +from django.urls import reverse from .models import Person from .tables import PersonsTable @@ -21,3 +24,18 @@ def persons(request): context['persons_table'] = persons_table return render(request, 'core/persons.html', context) + +@login_required +def person(request, id_): + context = {} + + # Get person and check access + try: + person = Person.objects.get(pk=id_) + except Person.DoesNotExist as e: + # Turn not-found object into a 404 error + raise Http404 from e + + context['person'] = person + + return render(request, 'core/person.html', context)