mirror of
				https://gitlab.crans.org/mediatek/med.git
				synced 2025-11-04 16:02:29 +01:00 
			
		
		
		
	Initial commit, projet med
This commit is contained in:
		
							
								
								
									
										0
									
								
								media/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								media/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										20
									
								
								media/admin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								media/admin.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
							
								
								
									
										5
									
								
								media/apps.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								media/apps.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
from django.apps import AppConfig
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MediaConfig(AppConfig):
 | 
			
		||||
    name = 'media'
 | 
			
		||||
							
								
								
									
										45
									
								
								media/forms.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								media/forms.py
									
									
									
									
									
										Normal file
									
								
							@@ -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.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']
 | 
			
		||||
							
								
								
									
										62
									
								
								media/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								media/migrations/0001_initial.py
									
									
									
									
									
										Normal file
									
								
							@@ -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),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										22
									
								
								media/migrations/0002_media_auteur.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								media/migrations/0002_media_auteur.py
									
									
									
									
									
										Normal file
									
								
							@@ -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,
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										27
									
								
								media/migrations/0003_auto_20170629_1536.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								media/migrations/0003_auto_20170629_1536.py
									
									
									
									
									
										Normal file
									
								
							@@ -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),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										27
									
								
								media/migrations/0004_auto_20170629_1539.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								media/migrations/0004_auto_20170629_1539.py
									
									
									
									
									
										Normal file
									
								
							@@ -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),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										0
									
								
								media/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								media/migrations/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										29
									
								
								media/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								media/models.py
									
									
									
									
									
										Normal file
									
								
							@@ -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) 
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										40
									
								
								media/templates/media/aff_auteurs.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								media/templates/media/aff_auteurs.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <thead>
 | 
			
		||||
            <tr>
 | 
			
		||||
	    <th>Nom</th>
 | 
			
		||||
            <th></th>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        {% for auteur in auteurs_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>{{ auteur.nom }}</td>
 | 
			
		||||
            <td>{% 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 %}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
							
								
								
									
										66
									
								
								media/templates/media/aff_emprunts.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								media/templates/media/aff_emprunts.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <thead>
 | 
			
		||||
            <tr>
 | 
			
		||||
	    <th>Media</th>
 | 
			
		||||
 	    <th>Utilisateur</th>
 | 
			
		||||
 	    <th>Date emprunt</th>
 | 
			
		||||
	    <th>Permanencier emprunt</th>
 | 
			
		||||
 	    <th>Date rendu</th>
 | 
			
		||||
 	    <th>Permanencier rendu</th>
 | 
			
		||||
            <th></th>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        {% for emprunt in emprunts_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>{{ emprunt.media }}</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <a href="{% url 'users:profil' userid=emprunt.user.id %}"><b>{{ emprunt.user }}</b></a>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>{{ emprunt.date_emprunt }}</td>
 | 
			
		||||
            <td>{{ emprunt.permanencier_emprunt }}</td>
 | 
			
		||||
            <td>{% if not emprunt.date_rendu %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'media:retour-emprunt' emprunt.id  %}"><i class="glyphicon glyphicon-ok"></i> Retour</a>{% else %}{{ emprunt.date_rendu }}{% endif %}</td>
 | 
			
		||||
            <td>{{ emprunt.permanencier_rendu }}</td>
 | 
			
		||||
            <td>
 | 
			
		||||
             <div class="dropdown">
 | 
			
		||||
             <button class="btn btn-default dropdown-toggle" type="button" id="editionemprunt" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
 | 
			
		||||
             Modifier
 | 
			
		||||
             <span class="caret"></span>
 | 
			
		||||
             </button>
 | 
			
		||||
             <ul class="dropdown-menu" aria-labelledby="editionemprunt">
 | 
			
		||||
                 {% if is_perm %}
 | 
			
		||||
                 <li><a href="{% url 'media:edit-emprunt' emprunt.id %}"><i class="glyphicon glyphicon-edit"></i> Editer</a></li>
 | 
			
		||||
                 {% endif %}
 | 
			
		||||
                 {% if is_bureau %}
 | 
			
		||||
                 <li><a href="{% url 'media:del-emprunt' emprunt.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
 | 
			
		||||
                 {% endif %}
 | 
			
		||||
                 <li><a href="{% url 'media:history' 'emprunt' emprunt.id %}"><i class="glyphicon glyphicon-time"></i> Historique</a></li>
 | 
			
		||||
             </ul>
 | 
			
		||||
             </div>
 | 
			
		||||
             </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
							
								
								
									
										44
									
								
								media/templates/media/aff_medias.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								media/templates/media/aff_medias.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
 | 
			
		||||
    <table class="table table-striped">
 | 
			
		||||
        <thead>
 | 
			
		||||
            <tr>
 | 
			
		||||
	    <th>Titre</th>
 | 
			
		||||
            <th>Auteur</th>
 | 
			
		||||
	    <th>Cote</th>
 | 
			
		||||
            <th></th>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </thead>
 | 
			
		||||
        {% for media in medias_list %}
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>{{ media.titre }}</td>
 | 
			
		||||
            <td>{{ media.auteur }}</td>
 | 
			
		||||
            <td>{{ media.cote }}</td>
 | 
			
		||||
            <td>{% 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 %}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
							
								
								
									
										40
									
								
								media/templates/media/delete.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								media/templates/media/delete.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
 | 
			
		||||
<form class="form" method="post">
 | 
			
		||||
    {% csrf_token %}
 | 
			
		||||
    <h4>Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?</h4>
 | 
			
		||||
    {% bootstrap_button "Confirmer" button_type="submit" icon="trash" %}
 | 
			
		||||
</form>
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
							
								
								
									
										39
									
								
								media/templates/media/index_auteurs.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								media/templates/media/index_auteurs.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
  <h2>Liste des auteurs</h2>
 | 
			
		||||
  {% if is_perm %}
 | 
			
		||||
  <a class="btn btn-primary btn-sm" role="button" href="{% url 'media:add-auteur'  %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un auteur</a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
  {%  include "media/aff_auteurs.html" with  auteurs_list=auteurs_list %}
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
							
								
								
									
										36
									
								
								media/templates/media/index_emprunts.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								media/templates/media/index_emprunts.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
  <h2>Liste des emprunts</h2>
 | 
			
		||||
  {%  include "media/aff_emprunts.html" with  emprunts_list=emprunts_list %}
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
							
								
								
									
										39
									
								
								media/templates/media/index_medias.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								media/templates/media/index_medias.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
  <h2>Liste des medias</h2>
 | 
			
		||||
  {% if is_perm %}
 | 
			
		||||
  <a class="btn btn-primary btn-sm" role="button" href="{% url 'media:add-media'  %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un media</a>
 | 
			
		||||
  {% endif %}
 | 
			
		||||
  {%  include "media/aff_medias.html" with  medias_list=medias_list %}
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
							
								
								
									
										42
									
								
								media/templates/media/media.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								media/templates/media/media.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<form class="form" method="post">
 | 
			
		||||
    {% csrf_token %}
 | 
			
		||||
    {% bootstrap_form mediaform %}
 | 
			
		||||
    {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
 | 
			
		||||
</form>
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
  <br />
 | 
			
		||||
{% endblock %}
 | 
			
		||||
							
								
								
									
										41
									
								
								media/templates/media/sidebar.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								media/templates/media/sidebar.html
									
									
									
									
									
										Normal file
									
								
							@@ -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 %}
 | 
			
		||||
    <a class="list-group-item list-group-item-info" href="{% url "media:index" %}">
 | 
			
		||||
        <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
        Emprunts
 | 
			
		||||
    </a>
 | 
			
		||||
    <a class="list-group-item list-group-item-info" href="{% url "media:index-auteurs" %}">
 | 
			
		||||
        <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
        Auteurs
 | 
			
		||||
    </a>
 | 
			
		||||
    <a class="list-group-item list-group-item-info" href="{% url "media:index-medias" %}">
 | 
			
		||||
        <i class="glyphicon glyphicon-list"></i>
 | 
			
		||||
        Medias
 | 
			
		||||
    </a>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								media/tests.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								media/tests.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
from django.test import TestCase
 | 
			
		||||
 | 
			
		||||
# Create your tests here.
 | 
			
		||||
							
								
								
									
										45
									
								
								media/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								media/urls.py
									
									
									
									
									
										Normal file
									
								
							@@ -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<auteurid>[0-9]+)$', views.edit_auteur, name='edit-auteur'),
 | 
			
		||||
    url(r'^del_auteur/(?P<auteurid>[0-9]+)$', views.del_auteur, name='del-auteur'),
 | 
			
		||||
    url(r'^index_auteurs/$', views.index_auteurs, name='index-auteurs'),
 | 
			
		||||
    url(r'^history/(?P<object>auteur)/(?P<id>[0-9]+)$', views.history, name='history'),
 | 
			
		||||
    url(r'^add_media/$', views.add_media, name='add-media'),
 | 
			
		||||
    url(r'^edit_media/(?P<mediaid>[0-9]+)$', views.edit_media, name='edit-media'),
 | 
			
		||||
    url(r'^del_media/(?P<mediaid>[0-9]+)$', views.del_media, name='del-media'),
 | 
			
		||||
    url(r'^index_medias/$', views.index_medias, name='index-medias'),
 | 
			
		||||
    url(r'^history/(?P<object>media)/(?P<id>[0-9]+)$', views.history, name='history'),
 | 
			
		||||
    url(r'^add_emprunt/(?P<userid>[0-9]+)$', views.add_emprunt, name='add-emprunt'),
 | 
			
		||||
    url(r'^retour_emprunt/(?P<empruntid>[0-9]+)$', views.retour_emprunt, name='retour-emprunt'),
 | 
			
		||||
    url(r'^edit_emprunt/(?P<empruntid>[0-9]+)$', views.edit_emprunt, name='edit-emprunt'),
 | 
			
		||||
    url(r'^del_emprunt/(?P<empruntid>[0-9]+)$', views.del_emprunt, name='del-emprunt'),
 | 
			
		||||
    url(r'^index_emprunts/$', views.index, name='index'),
 | 
			
		||||
    url(r'^history/(?P<object>emprunt)/(?P<id>[0-9]+)$', views.history, name='history'),
 | 
			
		||||
    url(r'^$', views.index, name='index'),
 | 
			
		||||
]
 | 
			
		||||
							
								
								
									
										252
									
								
								media/views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										252
									
								
								media/views.py
									
									
									
									
									
										Normal file
									
								
							@@ -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})
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user