diff --git a/README.md b/README.md index c1a9d5a..9e90bd5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Ce portail minimaliste permet aux utilisateurs de s'identifier. Leurs mac sont c ## Installation des dépendances -L'installation comporte 2 parties : le serveur web où se trouve le depot portail_captif ainsi que toutes ses dépendances, et le serveur bdd (mysql ou pgsql). Ces 2 serveurs peuvent en réalité être la même machine, ou séparés (recommandé en production). +L'installation comporte 2 parties : le serveur web où se trouve le depot med ainsi que toutes ses dépendances, et le serveur bdd (mysql ou pgsql). Ces 2 serveurs peuvent en réalité être la même machine, ou séparés (recommandé en production). Le serveur web sera nommé serveur A, le serveur bdd serveur B . ### Prérequis sur le serveur A @@ -49,19 +49,19 @@ Sur le serveur B, installer mysql ou postgresql, dans la version jessie ou stret ### Installation sur le serveur principal A -Cloner le dépot portail_captif à partir du gitlab, par exemple dans /var/www/portail_captif. -Ensuite, il faut créer le fichier settings_local.py dans le sous dossier portail_captif, un settings_local.example.py est présent. Les options sont commentées, et des options par défaut existent. +Cloner le dépot med à partir du gitlab, par exemple dans /var/www/med. +Ensuite, il faut créer le fichier settings_local.py dans le sous dossier med, un settings_local.example.py est présent. Les options sont commentées, et des options par défaut existent. En particulier, il est nécessaire de générer un login/mdp admin pour le ldap et un login/mdp pour l'utilisateur sql (cf ci-dessous), à mettre dans settings_local.py ### Installation du serveur mysql/postgresql sur B -Sur le serveur mysql ou postgresl, il est nécessaire de créer une base de donnée portail_captif, ainsi qu'un user portail_captif et un mot de passe associé. Ne pas oublier de faire écouter le serveur mysql ou postgresql avec les acl nécessaire pour que A puisse l'utiliser. +Sur le serveur mysql ou postgresl, il est nécessaire de créer une base de donnée med, ainsi qu'un user med et un mot de passe associé. Ne pas oublier de faire écouter le serveur mysql ou postgresql avec les acl nécessaire pour que A puisse l'utiliser. Voici les étapes à éxecuter pour mysql : - * CREATE DATABASE portail_captif; + * CREATE DATABASE med; * CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; - * GRANT ALL PRIVILEGES ON portail_captif.* TO 'newuser'@'localhost'; + * GRANT ALL PRIVILEGES ON med.* TO 'newuser'@'localhost'; * FLUSH PRIVILEGES; Si les serveurs A et B ne sont pas la même machine, il est nécessaire de remplacer localhost par l'ip avec laquelle A contacte B dans les commandes du dessus. @@ -71,7 +71,7 @@ Une fois ces commandes effectuées, ne pas oublier de vérifier que newuser et p Normalement à cette étape, le ldap et la bdd sql sont configurées correctement. -Il faut alors lancer dans le dépot portail_captif '''python3 manage.py migrate''' qui va structurer initialement la base de données. +Il faut alors lancer dans le dépot med '''python3 manage.py migrate''' qui va structurer initialement la base de données. Les migrations sont normalement comitées au fur et à mesure, néanmoins cette étape peut crasher, merci de reporter les bugs. ## Démarer le site web @@ -81,13 +81,12 @@ Pour apache2 : * apt install apache2 * apt install libapache2-mod-wsgi-py3 (pour le module wsgi) -portail_captif/wsgi.py permet de fonctionner avec apache2 en production +med/wsgi.py permet de fonctionner avec apache2 en production Pour nginx : * apt install nginx * apt install gunicorn3 -Utilisez alors un site nginx qui proxifie vers une socket gunicorn. Ensuite, utilisez les fichier portail_captif.service et portail_captif.socket avec systemd pour lancer le sous process gunicorn, présents dans portail_captif/ . ## Configuration avancée diff --git a/manage.py b/manage.py index ce55269..04edf65 100755 --- a/manage.py +++ b/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portail_captif.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "med.settings") from django.core.management import execute_from_command_line diff --git a/portail_captif/__init__.py b/med/__init__.py similarity index 100% rename from portail_captif/__init__.py rename to med/__init__.py diff --git a/portail_captif/context_processors.py b/med/context_processors.py similarity index 89% rename from portail_captif/context_processors.py rename to med/context_processors.py index 46aadd3..ad6ea7c 100644 --- a/portail_captif/context_processors.py +++ b/med/context_processors.py @@ -24,9 +24,11 @@ from .settings import SITE_NAME def context_user(request): user = request.user - is_admin = user.is_admin if hasattr(user,'is_admin') else False + is_perm = user.has_perms(['perm']) + is_bureau = user.has_perms(['bureau']) return { - 'is_admin' : is_admin, + 'is_perm' : is_perm, + 'is_bureau': is_bureau, 'request_user': user, 'site_name': SITE_NAME, } diff --git a/portail_captif/login.py b/med/login.py similarity index 100% rename from portail_captif/login.py rename to med/login.py diff --git a/portail_captif/settings.py b/med/settings.py similarity index 93% rename from portail_captif/settings.py rename to med/settings.py index a594044..38c18a6 100644 --- a/portail_captif/settings.py +++ b/med/settings.py @@ -21,7 +21,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -Django settings for portail_captif project. +Django settings for med project. Generated by 'django-admin startproject' using Django 1.8.13. @@ -45,7 +45,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Auth definition PASSWORD_HASHERS = ( - 'portail_captif.login.SSHAPasswordHasher', + 'med.login.SSHAPasswordHasher', 'django.contrib.auth.hashers.PBKDF2PasswordHasher', ) @@ -65,7 +65,9 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'bootstrap3', 'users', - 'portail_captif', + 'med', + 'media', + 'search', 'reversion' ) @@ -80,7 +82,7 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.security.SecurityMiddleware', ) -ROOT_URLCONF = 'portail_captif.urls' +ROOT_URLCONF = 'med.urls' TEMPLATES = [ { @@ -96,13 +98,13 @@ TEMPLATES = [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.request', - 'portail_captif.context_processors.context_user', + 'med.context_processors.context_user', ], }, }, ] -WSGI_APPLICATION = 'portail_captif.wsgi.application' +WSGI_APPLICATION = 'med.wsgi.application' # Internationalization diff --git a/portail_captif/settings_local.example.py b/med/settings_local.example.py similarity index 100% rename from portail_captif/settings_local.example.py rename to med/settings_local.example.py diff --git a/portail_captif/templates/portail_captif/aff_history.html b/med/templates/med/aff_history.html similarity index 100% rename from portail_captif/templates/portail_captif/aff_history.html rename to med/templates/med/aff_history.html diff --git a/portail_captif/templates/portail_captif/history.html b/med/templates/med/history.html similarity index 90% rename from portail_captif/templates/portail_captif/history.html rename to med/templates/med/history.html index 0b1abcc..3785f25 100644 --- a/portail_captif/templates/portail_captif/history.html +++ b/med/templates/med/history.html @@ -1,4 +1,4 @@ -{% extends "portail_captif/sidebar.html" %} +{% extends "med/sidebar.html" %} {% comment %} Re2o est un logiciel d'administration développé initiallement au rezometz. Il se veut agnostique au réseau considéré, de manière à être installable en @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block content %}

Historique de {{ object }}

- {% include "portail_captif/aff_history.html" with reversions=reversions %} + {% include "med/aff_history.html" with reversions=reversions %}


diff --git a/med/templates/med/index.html b/med/templates/med/index.html new file mode 100644 index 0000000..27860e8 --- /dev/null +++ b/med/templates/med/index.html @@ -0,0 +1,38 @@ +{% extends "med/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} +{% load staticfiles %} + +{% block title %}Accueil{% endblock %} + +{% block content %} +

Bienvenue sur {{ site_name }} !

+ +

Liens utiles

+ + +{% endblock %} + diff --git a/portail_captif/templates/portail_captif/sidebar.html b/med/templates/med/sidebar.html similarity index 100% rename from portail_captif/templates/portail_captif/sidebar.html rename to med/templates/med/sidebar.html diff --git a/portail_captif/test b/med/test similarity index 100% rename from portail_captif/test rename to med/test diff --git a/portail_captif/urls.py b/med/urls.py similarity index 92% rename from portail_captif/urls.py rename to med/urls.py index e6bd7e7..bc073ce 100644 --- a/portail_captif/urls.py +++ b/med/urls.py @@ -20,7 +20,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""portail_captif URL Configuration +"""med URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ @@ -46,4 +46,6 @@ urlpatterns = [ url('^', include('django.contrib.auth.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^users/', include('users.urls', namespace='users')), + url(r'^media/', include('media.urls', namespace='media')), + url(r'^search/', include('search.urls', namespace='search')), ] diff --git a/portail_captif/views.py b/med/views.py similarity index 91% rename from portail_captif/views.py rename to med/views.py index 6bcb704..e58ee37 100644 --- a/portail_captif/views.py +++ b/med/views.py @@ -24,7 +24,7 @@ from django.shortcuts import render from django.shortcuts import get_object_or_404 from django.template.context_processors import csrf from django.template import Context, RequestContext, loader -from portail_captif.settings import services_urls +from med.settings import services_urls def form(ctx, template, request): c = ctx @@ -40,4 +40,4 @@ def index(request): services[i][key] = s i = i + 1 if i < 2 else 0 - return form({'services_urls': services}, 'portail_captif/index.html', request) + return form({'services_urls': services}, 'med/index.html', request) diff --git a/portail_captif/wsgi.py b/med/wsgi.py similarity index 90% rename from portail_captif/wsgi.py rename to med/wsgi.py index a782b6b..54eb303 100644 --- a/portail_captif/wsgi.py +++ b/med/wsgi.py @@ -21,7 +21,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -WSGI config for portail_captif project. +WSGI config for med project. It exposes the WSGI callable as a module-level variable named ``application``. @@ -34,9 +34,8 @@ from django.core.wsgi import get_wsgi_application from os.path import dirname import sys -# On démarre le système du portail sys.path.append(dirname(dirname(__file__))) -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portail_captif.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "med.settings") application = get_wsgi_application() diff --git a/media/__init__.py b/media/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/media/admin.py b/media/admin.py new file mode 100644 index 0000000..c423547 --- /dev/null +++ b/media/admin.py @@ -0,0 +1,20 @@ + +from reversion.admin import VersionAdmin +from django.contrib import admin +from django.contrib.auth.models import Group + +from .models import Auteur, Emprunt, Media + +class AuteurAdmin(VersionAdmin): + list_display = ('nom',) + +class MediaAdmin(VersionAdmin): + list_display = ('titre','cote') + +class EmpruntAdmin(VersionAdmin): + list_display = ('media','user','date_emprunt', 'date_rendu', 'permanencier_emprunt', 'permanencier_rendu') + + +admin.site.register(Auteur, AuteurAdmin) +admin.site.register(Media, MediaAdmin) +admin.site.register(Emprunt, EmpruntAdmin) diff --git a/media/apps.py b/media/apps.py new file mode 100644 index 0000000..0550795 --- /dev/null +++ b/media/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MediaConfig(AppConfig): + name = 'media' diff --git a/users/management/commands/stop_portail.py b/media/forms.py old mode 100755 new mode 100644 similarity index 50% rename from users/management/commands/stop_portail.py rename to media/forms.py index 473d71e..9657d74 --- a/users/management/commands/stop_portail.py +++ b/media/forms.py @@ -1,3 +1,7 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# # Copyright © 2017 Gabriel Détraz # Copyright © 2017 Goulven Kermarec # Copyright © 2017 Augustin Lemesle @@ -15,27 +19,27 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Ce script est appellé avant le démarage du portail, il insère les bonnes règles -# dans l'iptables et active le routage -from django.core.management.base import BaseCommand, CommandError - - -from users.models import restore_iptables, create_ip_set, fill_ipset, disable_iptables, apply -from portail_captif.settings import AUTORIZED_INTERFACES - -class Command(BaseCommand): - help = 'Mets en place iptables et le set ip au démarage' - - def handle(self, *args, **options): - # Destruction de l'iptables - disable_iptables() - # Desactivation du routage sur les bonnes if - for interface in AUTORIZED_INTERFACES: - apply(["sudo", "-n", "sysctl", "net.ipv6.conf.%s.forwarding=0" % interface]) - apply(["sudo", "-n", "sysctl", "net.ipv4.conf.%s.forwarding=0" % interface]) +from django.forms import ModelForm, Form, ValidationError +from django import forms +from .models import Auteur, Media, Emprunt +class AuteurForm(ModelForm): + class Meta: + model = Auteur + fields = '__all__' +class MediaForm(ModelForm): + class Meta: + model = Media + fields = '__all__' +class EmpruntForm(ModelForm): + class Meta: + model = Emprunt + fields = ['media'] +class EditEmpruntForm(ModelForm): + class Meta: + model = Emprunt + fields = ['media', 'permanencier_emprunt', 'permanencier_rendu', 'date_rendu'] diff --git a/media/migrations/0001_initial.py b/media/migrations/0001_initial.py new file mode 100644 index 0000000..b79bfbd --- /dev/null +++ b/media/migrations/0001_initial.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-28 10:35 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Auteur', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nom', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Emprunt', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date_emprunt', models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')), + ('date_rendu', models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')), + ], + ), + migrations.CreateModel( + name='Media', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('titre', models.CharField(max_length=255)), + ('cote', models.CharField(max_length=31)), + ], + ), + migrations.AddField( + model_name='emprunt', + name='media', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='media.Media'), + ), + migrations.AddField( + model_name='emprunt', + name='permanencier_emprunt', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='user_permanencier_emprunt', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='emprunt', + name='permanencier_rendu', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='user_permanencier_rendu', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='emprunt', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/media/migrations/0002_media_auteur.py b/media/migrations/0002_media_auteur.py new file mode 100644 index 0000000..5b12caf --- /dev/null +++ b/media/migrations/0002_media_auteur.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-29 12:38 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='media', + name='auteur', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='media.Auteur'), + preserve_default=False, + ), + ] diff --git a/media/migrations/0003_auto_20170629_1536.py b/media/migrations/0003_auto_20170629_1536.py new file mode 100644 index 0000000..694cf6a --- /dev/null +++ b/media/migrations/0003_auto_20170629_1536.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-29 13:36 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0002_media_auteur'), + ] + + operations = [ + migrations.AlterField( + model_name='emprunt', + name='date_rendu', + field=models.DateTimeField(blank=True, help_text='%d/%m/%y %H:%M:%S'), + ), + migrations.AlterField( + model_name='emprunt', + name='permanencier_rendu', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, related_name='user_permanencier_rendu', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/media/migrations/0004_auto_20170629_1539.py b/media/migrations/0004_auto_20170629_1539.py new file mode 100644 index 0000000..2a5cbde --- /dev/null +++ b/media/migrations/0004_auto_20170629_1539.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-29 13:39 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0003_auto_20170629_1536'), + ] + + operations = [ + migrations.AlterField( + model_name='emprunt', + name='date_rendu', + field=models.DateTimeField(blank=True, help_text='%d/%m/%y %H:%M:%S', null=True), + ), + migrations.AlterField( + model_name='emprunt', + name='permanencier_rendu', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='user_permanencier_rendu', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/media/migrations/__init__.py b/media/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/media/models.py b/media/models.py new file mode 100644 index 0000000..ddc0ba3 --- /dev/null +++ b/media/models.py @@ -0,0 +1,29 @@ +from django.db import models + +class Auteur(models.Model): + nom = models.CharField(max_length=255) + + def __str__(self): + return self.nom + +class Media(models.Model): + titre = models.CharField(max_length=255) + cote = models.CharField(max_length=31) + auteur = models.ForeignKey('Auteur', on_delete=models.PROTECT) +# type = TODO + + def __str__(self): + return str(self.titre) + ' - ' + str(self.auteur) + +class Emprunt(models.Model): + media = models.ForeignKey('Media', on_delete=models.PROTECT) + user = models.ForeignKey('users.User', on_delete=models.PROTECT) + date_emprunt = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S') + date_rendu = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S', blank=True, null=True) + permanencier_emprunt = models.ForeignKey('users.User', on_delete=models.PROTECT, related_name='user_permanencier_emprunt') + permanencier_rendu = models.ForeignKey('users.User', on_delete=models.PROTECT, related_name='user_permanencier_rendu', blank=True, null=True) + + + + + diff --git a/media/templates/media/aff_auteurs.html b/media/templates/media/aff_auteurs.html new file mode 100644 index 0000000..c39441a --- /dev/null +++ b/media/templates/media/aff_auteurs.html @@ -0,0 +1,40 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + + + + + + + + {% for auteur in auteurs_list %} + + + + + {% endfor %} +
Nom
{{ auteur.nom }}{% include 'buttons/edit.html' with href='media:edit-auteur' id=auteur.id %} + {% include 'buttons/suppr.html' with href='media:del-auteur' id=auteur.id %} + {% include 'buttons/history.html' with href='media:history' name='auteur' id=auteur.id %}
diff --git a/media/templates/media/aff_emprunts.html b/media/templates/media/aff_emprunts.html new file mode 100644 index 0000000..dc9c8cb --- /dev/null +++ b/media/templates/media/aff_emprunts.html @@ -0,0 +1,66 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + + + + + + + + + + + + + {% for emprunt in emprunts_list %} + + + + + + + + + + {% endfor %} +
MediaUtilisateurDate empruntPermanencier empruntDate renduPermanencier rendu
{{ emprunt.media }} + {{ emprunt.user }} + {{ emprunt.date_emprunt }}{{ emprunt.permanencier_emprunt }}{% if not emprunt.date_rendu %} Retour{% else %}{{ emprunt.date_rendu }}{% endif %}{{ emprunt.permanencier_rendu }} + +
diff --git a/media/templates/media/aff_medias.html b/media/templates/media/aff_medias.html new file mode 100644 index 0000000..83fdb88 --- /dev/null +++ b/media/templates/media/aff_medias.html @@ -0,0 +1,44 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + + + + + + + + + + {% for media in medias_list %} + + + + + + + {% endfor %} +
TitreAuteurCote
{{ media.titre }}{{ media.auteur }}{{ media.cote }}{% include 'buttons/edit.html' with href='media:edit-media' id=media.id %} + {% include 'buttons/suppr.html' with href='media:del-media' id=media.id %} + {% include 'buttons/history.html' with href='media:history' name='media' id=media.id %}
diff --git a/media/templates/media/delete.html b/media/templates/media/delete.html new file mode 100644 index 0000000..1ca4061 --- /dev/null +++ b/media/templates/media/delete.html @@ -0,0 +1,40 @@ +{% extends "media/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Création et modification de media{% endblock %} + +{% block content %} + +
+ {% csrf_token %} +

Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?

+ {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %} +
+
+
+
+{% endblock %} diff --git a/media/templates/media/index_auteurs.html b/media/templates/media/index_auteurs.html new file mode 100644 index 0000000..fb8e304 --- /dev/null +++ b/media/templates/media/index_auteurs.html @@ -0,0 +1,39 @@ +{% extends "media/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Auteurs{% endblock %} + +{% block content %} +

Liste des auteurs

+ {% if is_perm %} + Ajouter un auteur + {% endif %} + {% include "media/aff_auteurs.html" with auteurs_list=auteurs_list %} +
+
+
+{% endblock %} diff --git a/media/templates/media/index_emprunts.html b/media/templates/media/index_emprunts.html new file mode 100644 index 0000000..16fb9f9 --- /dev/null +++ b/media/templates/media/index_emprunts.html @@ -0,0 +1,36 @@ +{% extends "media/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Emprunts{% endblock %} + +{% block content %} +

Liste des emprunts

+ {% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %} +
+
+
+{% endblock %} diff --git a/media/templates/media/index_medias.html b/media/templates/media/index_medias.html new file mode 100644 index 0000000..4c7a4b0 --- /dev/null +++ b/media/templates/media/index_medias.html @@ -0,0 +1,39 @@ +{% extends "media/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Media{% endblock %} + +{% block content %} +

Liste des medias

+ {% if is_perm %} + Ajouter un media + {% endif %} + {% include "media/aff_medias.html" with medias_list=medias_list %} +
+
+
+{% endblock %} diff --git a/media/templates/media/media.html b/media/templates/media/media.html new file mode 100644 index 0000000..fd0de88 --- /dev/null +++ b/media/templates/media/media.html @@ -0,0 +1,42 @@ +{% extends "media/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Création et modification de media{% endblock %} + +{% block content %} +{% bootstrap_form_errors mediaform %} + + +
+ {% csrf_token %} + {% bootstrap_form mediaform %} + {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} +
+
+
+
+{% endblock %} diff --git a/media/templates/media/sidebar.html b/media/templates/media/sidebar.html new file mode 100644 index 0000000..9f34165 --- /dev/null +++ b/media/templates/media/sidebar.html @@ -0,0 +1,41 @@ +{% extends "base.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + +{% block sidebar %} + + + Emprunts + + + + Auteurs + + + + Medias + +{% endblock %} + diff --git a/media/tests.py b/media/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/media/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/media/urls.py b/media/urls.py new file mode 100644 index 0000000..9cd5ae4 --- /dev/null +++ b/media/urls.py @@ -0,0 +1,45 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^add_auteur/$', views.add_auteur, name='add-auteur'), + url(r'^edit_auteur/(?P[0-9]+)$', views.edit_auteur, name='edit-auteur'), + url(r'^del_auteur/(?P[0-9]+)$', views.del_auteur, name='del-auteur'), + url(r'^index_auteurs/$', views.index_auteurs, name='index-auteurs'), + url(r'^history/(?Pauteur)/(?P[0-9]+)$', views.history, name='history'), + url(r'^add_media/$', views.add_media, name='add-media'), + url(r'^edit_media/(?P[0-9]+)$', views.edit_media, name='edit-media'), + url(r'^del_media/(?P[0-9]+)$', views.del_media, name='del-media'), + url(r'^index_medias/$', views.index_medias, name='index-medias'), + url(r'^history/(?Pmedia)/(?P[0-9]+)$', views.history, name='history'), + url(r'^add_emprunt/(?P[0-9]+)$', views.add_emprunt, name='add-emprunt'), + url(r'^retour_emprunt/(?P[0-9]+)$', views.retour_emprunt, name='retour-emprunt'), + url(r'^edit_emprunt/(?P[0-9]+)$', views.edit_emprunt, name='edit-emprunt'), + url(r'^del_emprunt/(?P[0-9]+)$', views.del_emprunt, name='del-emprunt'), + url(r'^index_emprunts/$', views.index, name='index'), + url(r'^history/(?Pemprunt)/(?P[0-9]+)$', views.history, name='history'), + url(r'^$', views.index, name='index'), +] diff --git a/media/views.py b/media/views.py new file mode 100644 index 0000000..7a6a391 --- /dev/null +++ b/media/views.py @@ -0,0 +1,252 @@ +from django.shortcuts import render, redirect +from django.http import HttpResponse +from django.shortcuts import get_object_or_404 +from django.template.context_processors import csrf +from django.template import Context, RequestContext, loader +from django.contrib import messages +from django.contrib.auth.decorators import login_required, permission_required +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.contrib.auth import authenticate, login +from django.views.decorators.csrf import csrf_exempt +from django.utils import timezone +from .forms import AuteurForm, MediaForm, EmpruntForm, EditEmpruntForm +from .models import Auteur, Media, Emprunt +from users.models import User +from django.db import transaction +from reversion import revisions as reversion +from reversion.models import Version + +from med.settings import PAGINATION_NUMBER as pagination_number + +def form(ctx, template, request): + c = ctx + c.update(csrf(request)) + return render(request, template, c) + +@login_required +@permission_required('perm') +def add_auteur(request): + auteur = AuteurForm(request.POST or None) + if auteur.is_valid(): + with transaction.atomic(), reversion.create_revision(): + auteur.save() + reversion.set_user(request.user) + reversion.set_comment("Création") + messages.success(request, "L'auteur a été ajouté") + return redirect("/media/index_auteurs/") + return form({'mediaform': auteur}, 'media/media.html', request) + +@login_required +@permission_required('perm') +def edit_auteur(request, auteurid): + try: + auteur_instance = Auteur.objects.get(pk=auteurid) + except Auteur.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_auteurs/") + auteur = AuteurForm(request.POST or None, instance=auteur_instance) + if auteur.is_valid(): + with transaction.atomic(), reversion.create_revision(): + auteur.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in auteur.changed_data)) + messages.success(request, "Auteur modifié") + return redirect("/media/index_auteurs/") + return form({'mediaform': auteur}, 'media/media.html', request) + +@login_required +@permission_required('perm') +def del_auteur(request, auteurid): + try: + auteur_instance = Auteur.objects.get(pk=auteurid) + except Auteur.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_auteurs/") + if request.method == "POST": + with transaction.atomic(), reversion.create_revision(): + auteur_instance.delete() + reversion.set_user(request.user) + messages.success(request, "L'auteur a été détruit") + return redirect("/media/index_auteurs") + return form({'objet': auteur_instance, 'objet_name': 'auteur'}, 'media/delete.html', request) + + +@login_required +@permission_required('perm') +def add_media(request): + media = MediaForm(request.POST or None) + if media.is_valid(): + with transaction.atomic(), reversion.create_revision(): + media.save() + reversion.set_user(request.user) + reversion.set_comment("Création") + messages.success(request, "Le media a été ajouté") + return redirect("/media/index_medias/") + return form({'mediaform': media}, 'media/media.html', request) + +@login_required +@permission_required('perm') +def edit_media(request, mediaid): + try: + media_instance = Media.objects.get(pk=mediaid) + except Media.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_medias/") + media = MediaForm(request.POST or None, instance=media_instance) + if media.is_valid(): + with transaction.atomic(), reversion.create_revision(): + media.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in media.changed_data)) + messages.success(request, "Media modifié") + return redirect("/media/index_medias/") + return form({'mediaform': media}, 'media/media.html', request) + +@login_required +@permission_required('perm') +def del_media(request, mediaid): + try: + media_instance = Media.objects.get(pk=mediaid) + except Media.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_medias/") + if request.method == "POST": + with transaction.atomic(), reversion.create_revision(): + media_instance.delete() + reversion.set_user(request.user) + messages.success(request, "Le media a été détruit") + return redirect("/media/index_medias") + return form({'objet': media_instance, 'objet_name': 'media'}, 'media/delete.html', request) + +@login_required +@permission_required('perm') +def add_emprunt(request, userid): + try: + user = User.objects.get(pk=userid) + except User.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_emprunts/") + emprunts_en_cours = Emprunt.objects.filter(date_rendu=None, user=user).count() + if emprunts_en_cours >= user.maxemprunt: + messages.error(request, "Maximum d'emprunts atteint de l'user %s" % user.maxemprunt) + return redirect("/media/index_emprunts/") + emprunt = EmpruntForm(request.POST or None) + if emprunt.is_valid(): + emprunt = emprunt.save(commit=False) + emprunt.user = user + emprunt.permanencier_emprunt = request.user + emprunt.date_emprunt = timezone.now() + with transaction.atomic(), reversion.create_revision(): + emprunt.save() + reversion.set_user(request.user) + reversion.set_comment("Création") + messages.success(request, "Le emprunt a été ajouté") + return redirect("/media/index_emprunts/") + return form({'mediaform': emprunt}, 'media/media.html', request) + +@login_required +@permission_required('perm') +def edit_emprunt(request, empruntid): + try: + emprunt_instance = Emprunt.objects.get(pk=empruntid) + except Emprunt.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_emprunts/") + emprunt = EditEmpruntForm(request.POST or None, instance=emprunt_instance) + if emprunt.is_valid(): + with transaction.atomic(), reversion.create_revision(): + emprunt.save() + reversion.set_user(request.user) + reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in emprunt.changed_data)) + messages.success(request, "Emprunt modifié") + return redirect("/media/index_emprunts/") + return form({'mediaform': emprunt}, 'media/media.html', request) + +@login_required +@permission_required('bureau') +def retour_emprunt(request, empruntid): + try: + emprunt_instance = Emprunt.objects.get(pk=empruntid) + except Emprunt.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_emprunts/") + with transaction.atomic(), reversion.create_revision(): + emprunt_instance.permanencier_rendu = request.user + emprunt_instance.date_rendu = timezone.now() + emprunt_instance.save() + reversion.set_user(request.user) + messages.success(request, "Retour enregistré") + return redirect("/media/index_emprunts/") + +@login_required +@permission_required('bureau') +def del_emprunt(request, empruntid): + try: + emprunt_instance = Emprunt.objects.get(pk=empruntid) + except Emprunt.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/media/index_emprunts/") + if request.method == "POST": + with transaction.atomic(), reversion.create_revision(): + emprunt_instance.delete() + reversion.set_user(request.user) + messages.success(request, "L'emprunt a été détruit") + return redirect("/media/index_emprunts") + return form({'objet': emprunt_instance, 'objet_name': 'emprunt'}, 'media/delete.html', request) + + + + +@login_required +def index_auteurs(request): + auteurs_list = Auteur.objects.all() + return render(request, 'media/index_auteurs.html', {'auteurs_list':auteurs_list}) + +@login_required +def index_medias(request): + medias_list = Media.objects.all() + return render(request, 'media/index_medias.html', {'medias_list':medias_list}) + + +@login_required +def index(request): + if request.user.has_perms(['perm']): + emprunts_list = Emprunt.objects.all() + else: + emprunts_list = Emprunt.objects.filter(user=request.user) + return render(request, 'media/index_emprunts.html', {'emprunts_list':emprunts_list}) + + +@login_required +def history(request, object, id): + if object == 'auteur': + try: + object_instance = Auteur.objects.get(pk=id) + except Auteur.DoesNotExist: + messages.error(request, "Auteur inexistant") + return redirect("/media/index_auteurs") + elif object == 'media': + try: + object_instance = Media.objects.get(pk=id) + except Media.DoesNotExist: + messages.error(request, "Media inexistant") + return redirect("/media/index_medias") + elif object == 'emprunt': + try: + object_instance = Emprunt.objects.get(pk=id) + except Emprunt.DoesNotExist: + messages.error(request, "Emprunt inexistant") + return redirect("/media/index_emprunts") + reversions = Version.objects.get_for_object(object_instance) + paginator = Paginator(reversions, pagination_number) + page = request.GET.get('page') + try: + reversions = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + reversions = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + reversions = paginator.page(paginator.num_pages) + return render(request, 'med/history.html', {'reversions': reversions, 'object': object_instance}) + diff --git a/portail_captif/portail_captif.service b/portail_captif/portail_captif.service deleted file mode 100644 index 0e5f345..0000000 --- a/portail_captif/portail_captif.service +++ /dev/null @@ -1,26 +0,0 @@ -[Unit] -Description=Crans Portail Captif -Requires=nginx.service -Requires=portail_captif.socket -After=nginx.service -After=network-online.target - -[Service] -Type=forking -User=root -Group=root -PIDFile=/run/portail_captif.pid -WorkingDirectory=/var/www/portail_captif/ -ExecStartPre=/usr/bin/python3 /var/www/portail_captif/manage.py start_portail -ExecStart=/usr/bin/gunicorn3 portail_captif.wsgi:application --pid=/run/portail_captif.pid --name www-data --user www-data --group www-data --daemon --log-file /var/log/gunicorn/portail_captif.log --log-level=info --bind=unix:///tmp/gunicorn-portail_captif.sock --workers=1 -ExecReload=/bin/kill -s HUP $MAINPID -ExecStop=/bin/kill -s TERM $MAINPID -ExecStopPost=/usr/bin/python3 /var/www/portail_captif/manage.py stop_portail -Restart=on-failure -RestartSec=65 -StartLimitInterval=60 -StartLimitBurst=2 - -[Install] -WantedBy=multi-user.target -Also=portail_captif.socket diff --git a/portail_captif/portail_captif.socket b/portail_captif/portail_captif.socket deleted file mode 100644 index 58971bd..0000000 --- a/portail_captif/portail_captif.socket +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Socket Portail Captif - -[Socket] -ListenStream=/tmp/gunicorn-portail_captif.sock - -[Install] -WantedBy=sockets.target diff --git a/portail_captif/templates/portail_captif/index.html b/portail_captif/templates/portail_captif/index.html deleted file mode 100644 index f3e408e..0000000 --- a/portail_captif/templates/portail_captif/index.html +++ /dev/null @@ -1,92 +0,0 @@ -{% extends "portail_captif/sidebar.html" %} -{% comment %} -Re2o est un logiciel d'administration développé initiallement au rezometz. Il -se veut agnostique au réseau considéré, de manière à être installable en -quelques clics. - -Copyright © 2017 Gabriel Détraz -Copyright © 2017 Goulven Kermarec -Copyright © 2017 Augustin Lemesle - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -{% endcomment %} - -{% load bootstrap3 %} -{% load staticfiles %} - -{% block title %}Accueil{% endblock %} - -{% block content %} -

Bienvenue sur {{ site_name }} !

- -

Bienvenue à toi ! Ce portail mis en place par le Cr@ns te permet d'accéder gratuitement à Internet sur le campus durant ton passage

- -
-
-logo -
-
- -
-
-
-
-
-

Inscription

-

Si vous n'avez pas de compte, inscrivez-vous pour bénéficier d'un accès à internet !

-

Inscription

-
-
-
-
-
-
-
-
-

Indentification

-

Si avez déjà un compte, identifiez-vous pour accèder à Internet

-

Identification

-
-
-
-
-
- -

Liens utiles

- -
-{% for col in services_urls %} -
- {% for key, s in col.items %} -
-
- {{ key }} -
-

{{ key }}

-

{{ s.description }}

-

Accéder

-
-
-
- {% endfor %} -
-{% endfor %} -
- -

Compte tenu des obligations de traçabilité des connexions à internet, vous vous engagez à fournir des informations exactes lors de votre inscription conformément à l'article 441-1 du nouveau code pénal. -Vous êtes seul responsable de l'utilisation du service, conformément aux articles L32 et L33 du code des postes et télécomunications éléctroniques.

- -{% endblock %} - diff --git a/search/__init__.py b/search/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/search/admin.py b/search/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/search/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/search/apps.py b/search/apps.py new file mode 100644 index 0000000..5726231 --- /dev/null +++ b/search/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SearchConfig(AppConfig): + name = 'search' diff --git a/search/forms.py b/search/forms.py new file mode 100644 index 0000000..aa79180 --- /dev/null +++ b/search/forms.py @@ -0,0 +1,49 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.db import models +from django import forms +from django.forms import Form +from django.forms import ModelForm + +CHOICES = ( + ('0', 'Actifs'), + ('1', 'Désactivés'), + ('2', 'Archivés'), +) + +CHOICES2 = ( + ('0', 'Utilisateurs'), + ('1', 'Media'), + ('2', 'Emprunts'), +) + + +class SearchForm(Form): + search_field = forms.CharField(label = 'Search', max_length = 100) + +class SearchFormPlus(Form): + search_field = forms.CharField(label = 'Search', max_length = 100, required=False) + filtre = forms.MultipleChoiceField(label="Filtre utilisateurs", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES) + affichage = forms.MultipleChoiceField(label="Filtre affichage", required=False, widget =forms.CheckboxSelectMultiple,choices=CHOICES2) + date_deb = forms.DateField(required=False, label="Date de début", help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y']) + date_fin = forms.DateField(required=False, help_text='DD/MM/YYYY', input_formats=['%d/%m/%Y'], label="Date de fin") diff --git a/search/migrations/__init__.py b/search/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/search/models.py b/search/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/search/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/search/templates/search/index.html b/search/templates/search/index.html new file mode 100644 index 0000000..5433210 --- /dev/null +++ b/search/templates/search/index.html @@ -0,0 +1,50 @@ +{% extends "search/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Résultats de la recherche{% endblock %} + +{% block content %} + {% if users_list %} +

Résultats dans les utilisateurs

+ {% include "users/aff_users.html" with users_list=users_list %} + {% endif%} + {% if emprunts_list %} +

Résultats dans les emprunt :

+ {% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %} + {% endif %} + {% if medias_list %} +

Résultats dans les media :

+ {% include "media/aff_medias.html" with medias_list=medias_list %} + {% endif %} + {% if not users_list and not emprunts_list and not medias_list %} +

Aucun résultat

+ {% endif %} +
(Seulement les {{ max_result }} premiers résultats sont affichés dans chaque catégorie)
+
+
+
+{% endblock %} diff --git a/search/templates/search/search.html b/search/templates/search/search.html new file mode 100644 index 0000000..adb5dd9 --- /dev/null +++ b/search/templates/search/search.html @@ -0,0 +1,43 @@ +{% extends "search/sidebar.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load bootstrap3 %} + +{% block title %}Recherche{% endblock %} + +{% block content %} +{% bootstrap_form_errors searchform %} + +
+ {% csrf_token %} + {% bootstrap_form searchform %} + {% bootstrap_button "Search" button_type="submit" icon="search" %} +
+
+
+
+
+
+{% endblock %} diff --git a/search/templates/search/sidebar.html b/search/templates/search/sidebar.html new file mode 100644 index 0000000..dbb1013 --- /dev/null +++ b/search/templates/search/sidebar.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + + +{% block sidebar %} + + + Recherche simple + + + + Recherche avancée + +{% endblock %} diff --git a/search/tests.py b/search/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/search/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/search/urls.py b/search/urls.py new file mode 100644 index 0000000..bee0785 --- /dev/null +++ b/search/urls.py @@ -0,0 +1,30 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.search, name='search'), + url(r'^avance/$', views.searchp, name='searchp'), +] diff --git a/search/views.py b/search/views.py new file mode 100644 index 0000000..84a5f37 --- /dev/null +++ b/search/views.py @@ -0,0 +1,109 @@ +# Re2o est un logiciel d'administration développé initiallement au rezometz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# App de recherche pour re2o +# Augustin lemesle, Gabriel Détraz, Goulven Kermarec +# Gplv2 +from django.shortcuts import render +from django.shortcuts import get_object_or_404 +from django.template.context_processors import csrf +from django.template import Context, RequestContext, loader +from django.contrib.auth.decorators import login_required + +from django.db.models import Q +from users.models import User +from search.forms import SearchForm, SearchFormPlus + +from media.models import Media, Emprunt + +def form(ctx, template, request): + c = ctx + c.update(csrf(request)) + return render(request, template, c) + +def search_result(search, type, request): + date_deb = None + date_fin = None + states=[] + aff=[] + if(type): + aff = search.cleaned_data['affichage'] + states = search.cleaned_data['filtre'] + date_deb = search.cleaned_data['date_deb'] + date_fin = search.cleaned_data['date_fin'] + date_query = Q() + if aff==[]: + aff = ['0','1','2'] + if date_deb != None: + date_query = date_query & Q(date_emprunt__gte=date_deb) + if date_fin != None: + date_query = date_query & Q(date_emprunt__lte=date_fin) + search = search.cleaned_data['search_field'] + query1 = Q() + for s in states: + query1 = query1 | Q(state = s) + + connexion = [] + + recherche = {'users_list': None, 'emprunts_list' : None, 'medias_list' : None} + + if request.user.has_perms(('perm',)): + query = Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search) + else: + query = (Q(user__pseudo__icontains = search) | Q(user__name__icontains = search) | Q(user__surname__icontains = search)) & Q(user = request.user) + + + for i in aff: + if i == '0': + query_user_list = Q(pseudo__icontains = search) | Q(name__icontains = search) | Q(surname__icontains = search) & query1 + if request.user.has_perms(('perm',)): + recherche['users_list'] = User.objects.filter(query_user_list).order_by('state', 'surname') + else : + recherche['users_list'] = User.objects.filter(query_user_list & Q(id=request.user.id)).order_by('state', 'surname') + if i == '1': + recherche['emprunts_list'] = Emprunt.objects.filter(query & date_query).order_by('date_emprunt').reverse() + if i == '2': + recherche['medias_list'] = Media.objects.filter(Q(auteur__nom__icontains = search) | Q(titre__icontains = search)) + search_display_page = 5 + + for r in recherche: + if recherche[r] != None: + recherche[r] = recherche[r][:search_display_page] + + recherche.update({'max_result': search_display_page}) + + return recherche + +@login_required +def search(request): + search = SearchForm(request.POST or None) + if search.is_valid(): + return form(search_result(search, False, request), 'search/index.html',request) + return form({'searchform' : search}, 'search/search.html', request) + +@login_required +def searchp(request): + search = SearchFormPlus(request.POST or None) + if search.is_valid(): + return form(search_result(search, True, request), 'search/index.html',request) + return form({'searchform' : search}, 'search/search.html', request) + diff --git a/templates/base.html b/templates/base.html index 15a6618..c157ada 100644 --- a/templates/base.html +++ b/templates/base.html @@ -54,10 +54,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,