Merge index views
This commit is contained in:
parent
be96a61ff2
commit
aca1d2def6
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- 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 @@
|
||||||
# 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 = [
|
||||||
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 @@
|
||||||
# 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):
|
||||||
'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)
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
{% extends "admin/base_site.html" %}
|
|
||||||
{% comment %}
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
{% endcomment %}
|
|
||||||
|
|
||||||
{% 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 %}
|
|
||||||
<div id="content-main">
|
|
||||||
<h1>Bienvenue sur la base de données de la Mediatek.</h1>
|
|
||||||
<h1>Welcome to procrastination heaven !</h1>
|
|
||||||
<p>
|
|
||||||
Le site va subir progressivement des mises à jour pendant ces vacances.
|
|
||||||
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>.
|
|
||||||
</p>
|
|
||||||
<img src="{% static "images/splash.png" %}" class="poulpy" alt="Poulpy">
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block sidebar %}
|
|
||||||
<div id="content-related">
|
|
||||||
<div class="module" id="recent-actions-module">
|
|
||||||
{% if user.is_authenticated %}
|
|
||||||
<h2>{{ user.first_name }} {{ user.last_name }}</h2>
|
|
||||||
|
|
||||||
<h3>
|
|
||||||
{% trans 'My profile' %}
|
|
||||||
<small><a class="changelink" href="{% url 'users:edit-info' %}">
|
|
||||||
{% trans 'Edit' %}
|
|
||||||
</a></small>
|
|
||||||
</h3>
|
|
||||||
<ul>
|
|
||||||
<li><strong>{% trans 'username' %}</strong> : {{ user.username }}</li>
|
|
||||||
<li><strong>{% trans 'email' %}</strong> : {{ user.email }}</li>
|
|
||||||
<li><strong>{% trans 'comment' %}</strong> : {{ user.comment }}</li>
|
|
||||||
<li><strong>{% trans 'date joined' %}</strong> : {{ user.date_joined }}</li>
|
|
||||||
<li><strong>{% trans 'last login' %}</strong> : {{ user.last_login }}</li>
|
|
||||||
<li><strong>{% trans 'address' %}</strong> : {{ user.address }}</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 'maximum borrowed' %}</strong> : {{ user.maxemprunt }}</li>
|
|
||||||
<li>
|
|
||||||
<strong>{% trans 'membership for current year' %}</strong> :
|
|
||||||
{% if user.is_adherent %}
|
|
||||||
<span style="color:green">{% trans 'yes' %}</span>
|
|
||||||
{% else %}
|
|
||||||
<span style="color:red">{% trans 'no' %}</span>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>{% trans 'Current borrowed items' %}</h3>
|
|
||||||
{% if borrowed_items %}
|
|
||||||
<ul>
|
|
||||||
{% for emprunt in borrowed_items %}
|
|
||||||
<li>{{ emprunt.media }} ({% trans 'since' %} {{ emprunt.date_emprunt }})</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% else %}
|
|
||||||
<p>{% trans 'No current borrowed items.' %}</p>
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
<p>{% trans 'You are not logged in.' %}</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -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):
|
||||||
|
|
||||||
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,7 +25,6 @@ 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">
|
||||||
|
@ -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>
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
{% extends "admin/index.html" %}
|
||||||
|
{% comment %}
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% load i18n static %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div id="content-main">
|
||||||
|
<h2>Welcome to procrastination haven !</h2>
|
||||||
|
<p>
|
||||||
|
Le site va subir progressivement des mises à jour pendant ces vacances.
|
||||||
|
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>.
|
||||||
|
</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> </td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if model.admin_url %}
|
||||||
|
<td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
|
||||||
|
{% else %}
|
||||||
|
<td> </td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<img src="{% static "images/splash.png" %}" class="poulpy" alt="Poulpy">
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
<div id="content-related">
|
||||||
|
<div class="module" id="recent-actions-module">
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<h2>{{ user.first_name }} {{ user.last_name }}</h2>
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
{% trans 'My profile' %}
|
||||||
|
<small><a class="changelink" href="{% url 'users:edit-info' %}">
|
||||||
|
{% trans 'Edit' %}
|
||||||
|
</a></small>
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>{% trans 'username' %}</strong> : {{ user.username }}</li>
|
||||||
|
<li><strong>{% trans 'email' %}</strong> : {{ user.email }}</li>
|
||||||
|
<li><strong>{% trans 'comment' %}</strong> : {{ user.comment }}</li>
|
||||||
|
<li><strong>{% trans 'date joined' %}</strong> : {{ user.date_joined }}</li>
|
||||||
|
<li><strong>{% trans 'last login' %}</strong> : {{ user.last_login }}</li>
|
||||||
|
<li><strong>{% trans 'address' %}</strong> : {{ user.address }}</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 'maximum borrowed' %}</strong> : {{ user.maxemprunt }}</li>
|
||||||
|
<li>
|
||||||
|
<strong>{% trans 'membership for current year' %}</strong> :
|
||||||
|
{% if user.is_adherent %}
|
||||||
|
<span style="color:green">{% trans 'yes' %}</span>
|
||||||
|
{% else %}
|
||||||
|
<span style="color:red">{% trans 'no' %}</span>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>{% trans 'Current borrowed items' %}</h3>
|
||||||
|
{% if borrowed_items %}
|
||||||
|
<ul>
|
||||||
|
{% for emprunt in borrowed_items %}
|
||||||
|
<li>{{ emprunt.media }} ({% trans 'since' %} {{ emprunt.date_emprunt }})</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>{% trans 'No current borrowed items.' %}</p>
|
||||||
|
{% 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 %}
|
||||||
|
<p>{% trans 'You are not logged in.' %}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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):
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue