Commit 38a59b75 authored by chirac's avatar chirac
Browse files

Gestion de l'historique de tous les objets

parent 7bd2e318
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
class FactureAdmin(admin.ModelAdmin):
class FactureAdmin(VersionAdmin):
list_display = ('user','paiement','date','valid','control')
class VenteAdmin(admin.ModelAdmin):
class VenteAdmin(VersionAdmin):
list_display = ('facture','name','prix','number','iscotisation','duration')
class ArticleAdmin(admin.ModelAdmin):
class ArticleAdmin(VersionAdmin):
list_display = ('name','prix','iscotisation','duration')
class BanqueAdmin(admin.ModelAdmin):
class BanqueAdmin(VersionAdmin):
list_display = ('name',)
class PaiementAdmin(admin.ModelAdmin):
class PaiementAdmin(VersionAdmin):
list_display = ('moyen',)
class PaiementAdmin(admin.ModelAdmin):
list_display = ('moyen',)
class CotisationAdmin(admin.ModelAdmin):
class CotisationAdmin(VersionAdmin):
list_display = ('vente','date_start','date_end')
admin.site.register(Facture, FactureAdmin)
......
......@@ -14,7 +14,8 @@
<td>{{ article.prix }}</td>
<td>{{ article.cotisation }}</td>
<td>{{ article.duration }}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-article' article.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-article' article.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'cotisations:history' 'article' article.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -8,7 +8,8 @@
{% for banque in banque_list %}
<tr>
<td>{{ banque.name }}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-banque' banque.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-banque' banque.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'cotisations:history' 'banque' banque.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -8,6 +8,7 @@
<th>Date</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
{% for facture in facture_list %}
......@@ -17,9 +18,23 @@
<td>{{ facture.prix_total }}</td>
<td>{{ facture.paiement }}</td>
<td>{{ facture.date }}</td>
<td>{% if is_cableur %}{% if facture.valid and not facture.control or is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-facture' facture.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a>{% endif %}{% endif %}</td>
<td>{% if is_cableur %}{% if facture.valid and not facture.control or is_trez %}<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:del-facture' facture.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a>{% else %}Facture controlée{% endif %}{% endif %}</td>
{% if is_cableur %}
<td><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editionfacture" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Modifier
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editionfacture">
{% if facture.valid and not facture.control or is_trez %}
<li><a href="{% url 'cotisations:edit-facture' facture.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a></li>
<li><a href="{% url 'cotisations:del-facture' facture.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
{% else %}
<li>Facture controlée</li>
{% endif %}
</ul></div></td>
{% endif %}
<td>{% if facture.valid %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:facture-pdf' facture.id %}"><i class="glyphicon glyphicon-save"></i> PDF</a>{% else %}Facture invalide{% endif %}</td>
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'cotisations:history' 'facture' facture.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -8,7 +8,8 @@
{% for paiement in paiement_list %}
<tr>
<td>{{ paiement.moyen }}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-paiement' paiement.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
<td>{% if is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-paiement' paiement.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'cotisations:history' 'paiement' paiement.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -7,7 +7,7 @@
<h2>Liste des banques</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:add-banque' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une banque</a>
{% if is_trez %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:del-banque' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs banques</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:del-banque' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs banques</a>
{% endif %}
{% include "cotisations/aff_banque.html" with banque_list=banque_list %}
<br />
......
......@@ -7,7 +7,7 @@
<h2>Liste des types de paiements</h2>
{% if is_trez %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:add-paiement' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de paiement</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:del-paiement' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de paiements</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:del-paiement' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de paiements</a>
{% endif %}
{% include "cotisations/aff_paiement.html" with paiement_list=paiement_list %}
<br />
......
......@@ -20,6 +20,10 @@ urlpatterns = [
url(r'^index_article/$', views.index_article, name='index-article'),
url(r'^index_banque/$', views.index_banque, name='index-banque'),
url(r'^index_paiement/$', views.index_paiement, name='index-paiement'),
url(r'^history/(?P<object>facture)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>article)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>banque)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^control/$', views.control, name='control'),
url(r'^$', views.index, name='index'),
]
......
......@@ -8,8 +8,10 @@ from django.template import Context, RequestContext, loader
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib import messages
from django.db.models import Max, ProtectedError
from django.db import transaction
from django.forms import modelformset_factory, formset_factory
import os
from reversion import revisions as reversion
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
......@@ -56,13 +58,19 @@ def new_facture(request, userid):
articles = article_formset
# Si au moins un article est rempli
if any(art.cleaned_data for art in articles):
new_facture.save()
with transaction.atomic(), reversion.create_revision():
new_facture.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
for art_item in articles:
if art_item.cleaned_data:
article = art_item.cleaned_data['article']
quantity = art_item.cleaned_data['quantity']
new_vente = Vente.objects.create(facture=new_facture, name=article.name, prix=article.prix, iscotisation=article.iscotisation, duration=article.duration, number=quantity)
new_vente.save()
with transaction.atomic(), reversion.create_revision():
new_vente.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
if art_item.cleaned_data['article'].iscotisation:
create_cotis(new_vente, user, art_item.cleaned_data['article'].duration*art_item.cleaned_data['quantity'])
if any(art_item.cleaned_data['article'].iscotisation for art_item in articles if art_item.cleaned_data):
......@@ -130,8 +138,11 @@ def edit_facture(request, factureid):
vente_form_set = modelformset_factory(Vente, fields=('name','number'), extra=0, max_num=len(ventes_objects))
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
if facture_form.is_valid() and vente_form.is_valid():
facture_form.save()
vente_form.save()
with transaction.atomic(), reversion.create_revision():
facture_form.save()
vente_form.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for form in vente_form for field in facture_form.changed_data + form.changed_data))
messages.success(request, "La facture a bien été modifiée")
return redirect("/cotisations/")
return form({'factureform': facture_form, 'venteform': vente_form}, 'cotisations/edit_facture.html', request)
......@@ -148,7 +159,9 @@ def del_facture(request, factureid):
messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
return redirect("/cotisations/")
if request.method == "POST":
facture.delete()
with transaction.atomic(), reversion.create_revision():
facture.delete()
reversion.set_user(request.user)
messages.success(request, "La facture a été détruite")
return redirect("/cotisations/")
return form({'objet': facture, 'objet_name': 'facture'}, 'cotisations/delete.html', request)
......@@ -158,7 +171,10 @@ def del_facture(request, factureid):
def add_article(request):
article = ArticleForm(request.POST or None)
if article.is_valid():
article.save()
with transaction.atomic(), reversion.create_revision():
article.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "L'article a été ajouté")
return redirect("/cotisations/index_article/")
return form({'factureform': article}, 'cotisations/facture.html', request)
......@@ -173,7 +189,10 @@ def edit_article(request, articleid):
return redirect("/cotisations/index_article/")
article = ArticleForm(request.POST or None, instance=article_instance)
if article.is_valid():
article.save()
with transaction.atomic(), reversion.create_revision():
article.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in article.changed_data))
messages.success(request, "Type d'article modifié")
return redirect("/cotisations/index_article/")
return form({'factureform': article}, 'cotisations/facture.html', request)
......@@ -184,7 +203,9 @@ def del_article(request):
article = DelArticleForm(request.POST or None)
if article.is_valid():
article_del = article.cleaned_data['articles']
article_del.delete()
with transaction.atomic(), reversion.create_revision():
article_del.delete()
reversion.set_user(request.user)
messages.success(request, "Le/les articles ont été supprimé")
return redirect("/cotisations/index_article")
return form({'factureform': article}, 'cotisations/facture.html', request)
......@@ -194,7 +215,10 @@ def del_article(request):
def add_paiement(request):
paiement = PaiementForm(request.POST or None)
if paiement.is_valid():
paiement.save()
with transaction.atomic(), reversion.create_revision():
paiement.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Le moyen de paiement a été ajouté")
return redirect("/cotisations/index_paiement/")
return form({'factureform': paiement}, 'cotisations/facture.html', request)
......@@ -209,7 +233,10 @@ def edit_paiement(request, paiementid):
return redirect("/cotisations/index_paiement/")
paiement = PaiementForm(request.POST or None, instance=paiement_instance)
if paiement.is_valid():
paiement.save()
with transaction.atomic(), reversion.create_revision():
paiement.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in paiement.changed_data))
messages.success(request, "Type de paiement modifié")
return redirect("/cotisations/index_paiement/")
return form({'factureform': paiement}, 'cotisations/facture.html', request)
......@@ -222,7 +249,10 @@ def del_paiement(request):
paiement_dels = paiement.cleaned_data['paiements']
for paiement_del in paiement_dels:
try:
paiement_del.delete()
with transaction.atomic(), reversion.create_revision():
paiement_del.delete()
reversion.set_user(request.user)
reversion.set_comment("Destruction")
messages.success(request, "Le moyen de paiement a été supprimé")
except ProtectedError:
messages.error(request, "Le moyen de paiement %s est affecté à au moins une facture, vous ne pouvez pas le supprimer" % paiement_del)
......@@ -234,7 +264,10 @@ def del_paiement(request):
def add_banque(request):
banque = BanqueForm(request.POST or None)
if banque.is_valid():
banque.save()
with transaction.atomic(), reversion.create_revision():
banque.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "La banque a été ajoutée")
return redirect("/cotisations/index_banque/")
return form({'factureform': banque}, 'cotisations/facture.html', request)
......@@ -249,7 +282,10 @@ def edit_banque(request, banqueid):
return redirect("/cotisations/index_banque/")
banque = BanqueForm(request.POST or None, instance=banque_instance)
if banque.is_valid():
banque.save()
with transaction.atomic(), reversion.create_revision():
banque.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in banque.changed_data))
messages.success(request, "Banque modifiée")
return redirect("/cotisations/index_banque/")
return form({'factureform': banque}, 'cotisations/facture.html', request)
......@@ -262,7 +298,10 @@ def del_banque(request):
banque_dels = banque.cleaned_data['banques']
for banque_del in banque_dels:
try:
banque_del.delete()
with transaction.atomic(), reversion.create_revision():
banque_del.delete()
reversion.set_user(request.user)
reversion.set_comment("Destruction")
messages.success(request, "La banque a été supprimée")
except ProtectedError:
messages.error(request, "La banque %s est affectée à au moins une facture, vous ne pouvez pas la supprimer" % banque_del)
......@@ -303,3 +342,38 @@ def index_banque(request):
def index(request):
facture_list = Facture.objects.order_by('date').reverse()
return render(request, 'cotisations/index.html', {'facture_list': facture_list})
@login_required
def history(request, object, id):
if object == 'facture':
try:
object_instance = Facture.objects.get(pk=id)
except Facture.DoesNotExist:
messages.error(request, "Facture inexistante")
return redirect("/cotisations/")
if not request.user.has_perms(('cableur',)) and object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id))
elif object == 'paiement' and request.user.has_perms(('cableur',)):
try:
object_instance = Paiement.objects.get(pk=id)
except Paiement.DoesNotExist:
messages.error(request, "Paiement inexistant")
return redirect("/cotisations/")
elif object == 'article' and request.user.has_perms(('cableur',)):
try:
object_instance = Article.objects.get(pk=id)
except Article.DoesNotExist:
messages.error(request, "Article inexistante")
return redirect("/cotisations/")
elif object == 'banque' and request.user.has_perms(('cableur',)):
try:
object_instance = Banque.objects.get(pk=id)
except Banque.DoesNotExist:
messages.error(request, "Banque inexistante")
return redirect("/cotisations/")
else:
messages.error(request, "Objet inconnu")
return redirect("/cotisations/")
reversions = reversion.get_for_object(object_instance)
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import Machine, MachineType, IpList, Interface, Extension
class MachineAdmin(admin.ModelAdmin):
class MachineAdmin(VersionAdmin):
list_display = ('user','name','active')
class MachineTypeAdmin(admin.ModelAdmin):
class MachineTypeAdmin(VersionAdmin):
list_display = ('type','extension')
class ExtensionAdmin(admin.ModelAdmin):
class ExtensionAdmin(VersionAdmin):
list_display = ('name',)
class IpListAdmin(admin.ModelAdmin):
class IpListAdmin(VersionAdmin):
list_display = ('ipv4',)
class InterfaceAdmin(admin.ModelAdmin):
class InterfaceAdmin(VersionAdmin):
list_display = ('machine','type','dns','mac_address','ipv4','details')
admin.site.register(Machine, MachineAdmin)
......
......@@ -3,12 +3,14 @@
<tr>
<th>Extension</th>
<th></th>
<th></th>
</tr>
</thead>
{% for extension in extension_list %}
<tr>
<td>{{ extension.name }}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-extension' extension.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'machines:history' 'extension' extension.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -9,7 +9,8 @@
<tr>
<td><p>{{ machine.user }}</p>
<p><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-interface' machine.id %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une interface</p></a>
<p><a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-machine' machine.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer la machine</a></p></td>
<p><a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-machine' machine.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer la machine</a></p>
<p><a class="btn btn-info btn-sm" role="button" href="{% url 'machines:history' 'machine' machine.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></p></td>
<td><table class="table table-striped">
<thead>
<tr>
......@@ -33,6 +34,7 @@
</button>
<ul class="dropdown-menu" aria-labelledby="editioninterface">
<li><a href="{% url 'machines:edit-interface' interface.id %}"><i class="glyphicon glyphicon-hdd"></i> Editer</a></li>
<li><a href="{% url 'machines:history' 'interface' interface.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></li>
<li><a href="{% url 'machines:del-interface' interface.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
</ul></div></td>
</tr>
......
......@@ -4,6 +4,7 @@
<th>Type de machine</th>
<th>Extension</th>
<th></th>
<th></th>
</tr>
</thead>
{% for type in machinetype_list %}
......@@ -11,6 +12,7 @@
<td>{{ type.type }}</td>
<td>{{ type.extension }}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:edit-machinetype' type.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>{% endif %}</td>
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'machines:history' 'machinetype' type.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr>
{% endfor %}
</table>
......
......@@ -7,7 +7,7 @@
<h2>Liste des extensions</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-extension' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une extension</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-extension' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs extensions</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-extension' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs extensions</a>
{% endif %}
{% include "machines/aff_extension.html" with extension_list=extension_list %}
<br />
......
......@@ -7,7 +7,7 @@
<h2>Liste des types de machines</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-machinetype' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de machine</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:del-machinetype' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de machines</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-machinetype' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de machines</a>
{% endif %}
{% include "machines/aff_machinetype.html" with machinetype_list=machinetype_list %}
<br />
......
......@@ -16,6 +16,10 @@ urlpatterns = [
url(r'^edit_extension/(?P<extensionid>[0-9]+)$', views.edit_extension, name='edit-extension'),
url(r'^del_extension/$', views.del_extension, name='del-extension'),
url(r'^index_extension/$', views.index_extension, name='index-extension'),
url(r'^history/(?P<object>machine)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>interface)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>machinetype)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>extension)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'),
url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'),
url(r'^rest/dns-ip/$', views.dns_ip, name='dns-ip'),
......
......@@ -10,9 +10,11 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import ProtectedError
from django.forms import ValidationError
from django.db import transaction
from rest_framework.renderers import JSONRenderer
from machines.serializers import InterfaceSerializer
from reversion import revisions as reversion
import re
......@@ -52,7 +54,9 @@ def assign_ips(user):
for machine in machines:
if not machine.ipv4:
interface = assign_ipv4(machine)
interface.save()
with transaction.atomic(), reversion.create_revision():
reversion.set_comment("Assignation ipv4")
interface.save()
return
def free_ip():
......@@ -68,7 +72,9 @@ def assign_ipv4(interface):
def unassign_ipv4(interface):
interface.ipv4 = None
interface.save()
with transaction.atomic(), reversion.create_revision():
reversion.set_comment("Désassignation ipv4")
interface.save()
def form(ctx, template, request):
c = ctx
......@@ -92,13 +98,19 @@ def new_machine(request, userid):
new_machine.user = user
new_interface = interface.save(commit=False)
if full_domain_validator(request, new_interface):
new_machine.save()
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_interface.machine = new_machine
if free_ip() and not new_interface.ipv4:
new_interface = assign_ipv4(new_interface)
elif not new_interface.ipv4:
messages.error(request, u"Il n'y a plus d'ip disponibles")
new_interface.save()
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "La machine a été crée")
return redirect("/users/profil/" + userid)
return form({'machineform': machine, 'interfaceform': interface}, 'machines/machine.html', request)
......@@ -123,8 +135,14 @@ def edit_interface(request, interfaceid):
new_interface = interface_form.save(commit=False)
new_machine = machine_form.save(commit=False)
if full_domain_validator(request, new_interface):
new_machine.save()
new_interface.save()
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data))
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in interface_form.changed_data))
messages.success(request, "La machine a été modifiée")
return redirect("/users/profil/" + str(interface.machine.user.id))
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
......@@ -141,7 +159,9 @@ def del_machine(request, machineid):
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id))
if request.method == "POST":
machine.delete()
with transaction.atomic(), reversion.create_revision():
machine.delete()
reversion.set_user(request.user)
messages.success(request, "La machine a été détruite")
return redirect("/users/profil/" + str(request.user.id))
return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request)
......@@ -166,7 +186,10 @@ def new_interface(request, machineid):
new_interface = assign_ipv4(new_interface)
elif not new_interface.ipv4:
messages.error(request, u"Il n'y a plus d'ip disponibles")
new_interface.save()
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "L'interface a été ajoutée")
return redirect("/users/profil/" + str(request.user.id))
return form({'interfaceform': interface_form}, 'machines/machine.html', request)
......@@ -183,7 +206,9 @@ def del_interface(request, interfaceid):
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id))
if request.method == "POST":
interface.delete()
with transaction.atomic(), reversion.create_revision():
interface.delete()
reversion.set_user(request.user)
messages.success(request, "L'interface a été détruite")
return redirect("/users/profil/" + str(request.user.id))
return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request)
......@@ -193,7 +218,10 @@ def del_interface(request, interfaceid):
def add_machinetype(request):
machinetype = MachineTypeForm(request.POST or None)
if machinetype.is_valid():
machinetype.save()
with transaction.atomic(), reversion.create_revision():
machinetype.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Ce type de machine a été ajouté")
return redirect("/machines/index_machinetype")
return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request)
......@@ -208,7 +236,10 @@ def edit_machinetype(request, machinetypeid):
return redirect("/machines/index_machinetype/")
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
if machinetype.is_valid():
machinetype.save()
with transaction.atomic(), reversion.create_revision():
machinetype.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machinetype.changed_data))
messages.success(request, "Type de machine modifié")
return redirect("/machines/index_machinetype/")
return form({'machineform': machinetype}, 'machines/machine.html', request)
......@@ -221,7 +252,9 @@ def del_machinetype(request):
machinetype_dels = machinetype.cleaned_data['machinetypes']
for machinetype_del in machinetype_dels:
try:
machinetype_del.delete()
with transaction.atomic(), reversion.create_revision():
machinetype_del.delete()
reversion.set_user(request.user)
messages.success(request, "Le type de machine a été supprimé")
except ProtectedError:
messages.error(request, "Le type de machine %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % machinetype_del)
......@@ -233,7 +266,10 @@ def del_machinetype(request):
def add_extension(request):
extension = ExtensionForm(request.POST or None)
if extension.is_valid():
extension.save()