Commit aca1d2de authored by erdnaxe's avatar erdnaxe 🎇

Merge index views

parent be96a61f
Pipeline #1406 failed with stage
in 3 minutes and 9 seconds
...@@ -9,7 +9,7 @@ Elle permet de gérer les medias, bd, jeux, emprunts, ainsi que les adhérents d ...@@ -9,7 +9,7 @@ Elle permet de gérer les medias, bd, jeux, emprunts, ainsi que les adhérents d
## Licence ## Licence
Ce projet est sous la licence GNU public license v2.0. Ce projet est sous la licence GNU public license v3.0.
## Développement ## Développement
......
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.admin import AdminSite
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from media.models import Emprunt
class DatabaseAdmin(AdminSite):
index_title = _('Welcome to the Mediatek database')
@never_cache
def index(self, request, extra_context=None):
"""
Add borrowed item to admin index
"""
response = super().index(request, extra_context)
# User is always authenticated
user_borrowed = Emprunt.objects.filter(user=request.user)
response.context_data["borrowed_items"] = user_borrowed
return response
admin_site = DatabaseAdmin()
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.views import password_reset from django.contrib.auth.views import password_reset
from django.views.generic import RedirectView from django.views.generic import RedirectView
from media.views import index from media.views import index
from .admin import admin_site
urlpatterns = [ urlpatterns = [
url(r'^$', index, name='index'), url(r'^$', index, name='index'),
...@@ -24,6 +24,6 @@ urlpatterns = [ ...@@ -24,6 +24,6 @@ urlpatterns = [
url(r'^accounts/', include('django.contrib.auth.urls')), url(r'^accounts/', include('django.contrib.auth.urls')),
url(r'^accounts/profile/', url(r'^accounts/profile/',
RedirectView.as_view(pattern_name='index')), RedirectView.as_view(pattern_name='index')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^database/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls), url(r'^database/', admin_site.urls),
] ]
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay # Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from reversion.admin import VersionAdmin from reversion.admin import VersionAdmin
from med.admin import admin_site
from .models import Auteur, Emprunt, Jeu, Media from .models import Auteur, Emprunt, Jeu, Media
...@@ -29,7 +29,7 @@ class JeuAdmin(VersionAdmin): ...@@ -29,7 +29,7 @@ class JeuAdmin(VersionAdmin):
'nombre_joueurs_max', 'comment') 'nombre_joueurs_max', 'comment')
admin.site.register(Auteur, AuteurAdmin) admin_site.register(Auteur, AuteurAdmin)
admin.site.register(Media, MediaAdmin) admin_site.register(Media, MediaAdmin)
admin.site.register(Emprunt, EmpruntAdmin) admin_site.register(Emprunt, EmpruntAdmin)
admin.site.register(Jeu, JeuAdmin) admin_site.register(Jeu, JeuAdmin)
...@@ -8,6 +8,7 @@ from django.db import transaction ...@@ -8,6 +8,7 @@ from django.db import transaction
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.template.context_processors import csrf from django.template.context_processors import csrf
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from reversion import revisions as reversion from reversion import revisions as reversion
from users.models import User from users.models import User
...@@ -70,13 +71,11 @@ def retour_emprunt(request, empruntid): ...@@ -70,13 +71,11 @@ def retour_emprunt(request, empruntid):
def index(request): def index(request):
""" """
Home page with user's borrowed items Home page which redirect to admin when logged in
""" """
if request.user.is_authenticated: if request.user.is_authenticated:
borrowed_items = Emprunt.objects.filter(user=request.user) return redirect('admin:index')
else: else:
borrowed_items = [] return render(request, 'admin/index.html', {
'title': _('Welcome to the Mediatek database'),
return render(request, 'media/index.html', { })
'borrowed_items': borrowed_items,
})
...@@ -25,10 +25,9 @@ SPDX-License-Identifier: GPL-3.0-or-later ...@@ -25,10 +25,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block userlinks %} {% block userlinks %}
{% if user.is_authenticated %} {% if available_apps %}
{% if available_apps %} {# When in admin site, list all admin pages and documentation #}
{# When in admin site, list all admin pages and documentation #} <span class="dropdown">
<span class="dropdown">
<a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a> <a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a>
<span class="dropdown-content"> <span class="dropdown-content">
{% for app in available_apps %} {% for app in available_apps %}
...@@ -47,10 +46,11 @@ SPDX-License-Identifier: GPL-3.0-or-later ...@@ -47,10 +46,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %} {% endif %}
</span> </span>
</span> / </span> /
{% elif user.is_staff %} {% else %}
{# When not in admin site, but user is staff then add a link #} {# When not in admin site, but user is staff then add a link #}
<a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a> / <a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a> /
{% endif %} {% endif %}
{% if user.is_authenticated %}
<a href="{% url 'logout' %}">{% trans 'Log out' %}</a> <a href="{% url 'logout' %}">{% trans 'Log out' %}</a>
{% else %} {% else %}
<a href="{% url 'login' %}">{% trans 'Log in' %}</a> <a href="{% url 'login' %}">{% trans 'Log in' %}</a>
......
{% extends "admin/base_site.html" %} {% extends "admin/index.html" %}
{% comment %} {% comment %}
SPDX-License-Identifier: GPL-3.0-or-later SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %} {% endcomment %}
{% load i18n static %} {% load i18n static %}
{% block title %}Base de donnée de la Mediatek{% endblock %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}"/>
{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %}{{ block.super }} dashboard{% endblock %}
{% block breadcrumbs %}{% endblock %}
{% block content %} {% block content %}
<div id="content-main"> <div id="content-main">
<h1>Bienvenue sur la base de données de la Mediatek.</h1> <h2>Welcome to procrastination haven !</h2>
<h1>Welcome to procrastination heaven !</h1>
<p> <p>
Le site va subir progressivement des mises à jour pendant ces vacances. Le site va subir progressivement des mises à jour pendant ces vacances.
Si vous rencontrez des instabilités, Si vous rencontrez des instabilités,
veuillez nous faire remonter les problèmes <a href="mailto:a@crans.org,club-med@crans.org">au webmaster</a>. veuillez nous faire remonter les problèmes <a href="mailto:a@crans.org,club-med@crans.org">au webmaster</a>.
</p> </p>
{% if app_list %}
{% for app in app_list %}
<div class="app-{{ app.app_label }} module">
<table>
<caption>
<a href="{{ app.app_url }}" class="section"
title="{% blocktrans with name=app.name %}Models in the {{ name }} application{% endblocktrans %}">{{ app.name }}</a>
</caption>
{% for model in app.models %}
<tr class="model-{{ model.object_name|lower }}">
{% if model.admin_url %}
<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
{% else %}
<th scope="row">{{ model.name }}</th>
{% endif %}
{% if model.add_url %}
<td><a href="{{ model.add_url }}" class="addlink">{% trans 'Add' %}</a></td>
{% else %}
<td>&nbsp;</td>
{% endif %}
{% if model.admin_url %}
<td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
{% else %}
<td>&nbsp;</td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
{% endfor %}
{% endif %}
<img src="{% static "images/splash.png" %}" class="poulpy" alt="Poulpy"> <img src="{% static "images/splash.png" %}" class="poulpy" alt="Poulpy">
</div> </div>
{% endblock %} {% endblock %}
{% block sidebar %} {% block sidebar %}
<div id="content-related"> <div id="content-related">
<div class="module" id="recent-actions-module"> <div class="module" id="recent-actions-module">
...@@ -51,7 +73,8 @@ SPDX-License-Identifier: GPL-3.0-or-later ...@@ -51,7 +73,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
<li><strong>{% trans 'last login' %}</strong> : {{ user.last_login }}</li> <li><strong>{% trans 'last login' %}</strong> : {{ user.last_login }}</li>
<li><strong>{% trans 'address' %}</strong> : {{ user.address }}</li> <li><strong>{% trans 'address' %}</strong> : {{ user.address }}</li>
<li><strong>{% trans 'phone number' %}</strong> : {{ user.telephone }}</li> <li><strong>{% trans 'phone number' %}</strong> : {{ user.telephone }}</li>
<li><strong>{% trans 'groups' %}</strong> : {% for g in user.groups.all %}{{ g.name }} {% endfor %}</li> <li><strong>{% trans 'groups' %}</strong> : {% for g in user.groups.all %}{{ g.name }} {% endfor %}
</li>
<li><strong>{% trans 'maximum borrowed' %}</strong> : {{ user.maxemprunt }}</li> <li><strong>{% trans 'maximum borrowed' %}</strong> : {{ user.maxemprunt }}</li>
<li> <li>
<strong>{% trans 'membership for current year' %}</strong> : <strong>{% trans 'membership for current year' %}</strong> :
...@@ -73,9 +96,38 @@ SPDX-License-Identifier: GPL-3.0-or-later ...@@ -73,9 +96,38 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% else %} {% else %}
<p>{% trans 'No current borrowed items.' %}</p> <p>{% trans 'No current borrowed items.' %}</p>
{% endif %} {% endif %}
<h3>{% trans 'My actions' %}</h3>
{% load log %}
{% get_admin_log 10 as admin_log for_user user %}
{% if not admin_log %}
<p>{% trans 'None available' %}</p>
{% else %}
<ul class="actionlist">
{% for entry in admin_log %}
<li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
{% if entry.is_deletion or not entry.get_admin_url %}
{{ entry.object_repr }}
{% else %}
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %}
<br/>
{% if entry.content_type %}
<span class="mini quiet">{% filter capfirst %}
{{ entry.content_type }}{% endfilter %}</span>
{% else %}
<span class="mini quiet">{% trans 'Unknown content' %}</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% else %} {% else %}
<p>{% trans 'You are not logged in.' %}</p> <p>{% trans 'You are not logged in.' %}</p>
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
...@@ -13,6 +13,7 @@ from reversion.admin import VersionAdmin ...@@ -13,6 +13,7 @@ from reversion.admin import VersionAdmin
from .forms import UserCreationAdminForm from .forms import UserCreationAdminForm
from .models import Adhesion, Clef, User from .models import Adhesion, Clef, User
from med.admin import admin_site
class ClefAdmin(VersionAdmin): class ClefAdmin(VersionAdmin):
...@@ -122,6 +123,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): ...@@ -122,6 +123,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
actions_btn.allow_tags = True actions_btn.allow_tags = True
admin.site.register(User, UserAdmin) admin_site.register(User, UserAdmin)
admin.site.register(Adhesion, AdhesionAdmin) admin_site.register(Adhesion, AdhesionAdmin)
admin.site.register(Clef, ClefAdmin) admin_site.register(Clef, ClefAdmin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment