mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-27 01:13:46 +00:00
Permet d'ajouter un type de machine
This commit is contained in:
parent
b7745a3fe4
commit
3c98885d7b
7 changed files with 55 additions and 3 deletions
|
@ -31,3 +31,8 @@ Ensuite, effectuer les migrations. Un squelette de base de donnée, via un mysql
|
|||
## Mise en production avec apache
|
||||
|
||||
re2o/wsgi.py permet de fonctionner avec apache2 en production
|
||||
|
||||
## Fonctionnement avec les services
|
||||
|
||||
Pour charger les objets django, il suffit de faire User.objects.all() pour tous les users par exemple.
|
||||
Cependant, pour que les services fonctionnent de manière simple, des fonctions toutes prètes existent deja pour charger la liste des users autorisés à se connecter ( has_access(user)), etc. Ces fonctions sont personnalisables, et permettent un fonctionnement très simple des services.
|
||||
|
|
|
@ -66,7 +66,7 @@ def new_facture(request, userid):
|
|||
messages.success(request, "La cotisation a été prolongée pour l'adhérent %s " % user.name )
|
||||
else:
|
||||
messages.success(request, "La facture a été crée")
|
||||
return redirect("/cotisations/profil/" + userid)
|
||||
return redirect("/users/profil/" + userid)
|
||||
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
||||
|
||||
def edit_facture(request, factureid):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.forms import ModelForm, Form, ValidationError
|
||||
from .models import Machine, Interface
|
||||
from django import forms
|
||||
from .models import Machine, Interface, MachineType
|
||||
|
||||
class EditMachineForm(ModelForm):
|
||||
class Meta:
|
||||
|
@ -34,3 +35,19 @@ class NewInterfaceForm(EditInterfaceForm):
|
|||
class Meta(EditInterfaceForm.Meta):
|
||||
fields = ['mac_address','dns','details']
|
||||
|
||||
|
||||
class MachineTypeForm(ModelForm):
|
||||
class Meta:
|
||||
model = MachineType
|
||||
fields = ['type']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MachineTypeForm, self).__init__(*args, **kwargs)
|
||||
self.fields['type'].label = 'Type de machine à ajouter'
|
||||
|
||||
class DelMachineTypeForm(ModelForm):
|
||||
machinetypes = forms.ModelMultipleChoiceField(queryset=MachineType.objects.all(), label="Types de machines actuelles", widget=forms.CheckboxSelectMultiple)
|
||||
|
||||
class Meta:
|
||||
exclude = ['type']
|
||||
model = MachineType
|
||||
|
|
|
@ -5,12 +5,16 @@
|
|||
|
||||
{% block content %}
|
||||
{% bootstrap_form_errors machineform %}
|
||||
{% if interfaceform %}
|
||||
{% bootstrap_form_errors interfaceform %}
|
||||
{% endif %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form machineform %}
|
||||
{% if interfaceform %}
|
||||
{% bootstrap_form interfaceform %}
|
||||
{% endif %}
|
||||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
||||
</form>
|
||||
<br />
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block sidebar %}
|
||||
<p><a href="{% url "machines:add-machinetype" %}">Ajouter un type de machine</a></p>
|
||||
<p><a href="{% url "machines:del-machinetype" %}">Retirer un type de machine</a></p>
|
||||
{% endblock %}
|
||||
|
|
|
@ -6,5 +6,7 @@ urlpatterns = [
|
|||
url(r'^new_machine/(?P<userid>[0-9]+)$', views.new_machine, name='new-machine'),
|
||||
url(r'^edit_machine/(?P<interfaceid>[0-9]+)$', views.edit_machine, name='edit-machine'),
|
||||
url(r'^new_interface/(?P<machineid>[0-9]+)$', views.new_interface, name='new-interface'),
|
||||
url(r'^add_machinetype/$', views.add_machinetype, name='add-machinetype'),
|
||||
url(r'^del_machinetype/$', views.del_machinetype, name='del-machinetype'),
|
||||
url(r'^$', views.index, name='index'),
|
||||
]
|
||||
|
|
|
@ -6,8 +6,9 @@ from django.shortcuts import render_to_response, get_object_or_404
|
|||
from django.core.context_processors import csrf
|
||||
from django.template import Context, RequestContext, loader
|
||||
from django.contrib import messages
|
||||
from django.db.models import ProtectedError
|
||||
|
||||
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm
|
||||
from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, NewInterfaceForm, MachineTypeForm, DelMachineTypeForm
|
||||
from .models import Machine, Interface, IpList
|
||||
from users.models import User
|
||||
|
||||
|
@ -101,6 +102,27 @@ def new_interface(request, machineid):
|
|||
return redirect("/machines/")
|
||||
return form({'machineform': machine_form, 'interfaceform': interface_form}, 'machines/machine.html', request)
|
||||
|
||||
def add_machinetype(request):
|
||||
machinetype = MachineTypeForm(request.POST or None)
|
||||
if machinetype.is_valid():
|
||||
machinetype.save()
|
||||
messages.success(request, "Ce type de machine a été ajouté")
|
||||
return redirect("/machines/")
|
||||
return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request)
|
||||
|
||||
def del_machinetype(request):
|
||||
machinetype = DelMachineTypeForm(request.POST or None)
|
||||
if machinetype.is_valid():
|
||||
machinetype_dels = machinetype.cleaned_data['machinetypes']
|
||||
for machinetype_del in machinetype_dels:
|
||||
try:
|
||||
machinetype_del.delete()
|
||||
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)
|
||||
return redirect("/machines/")
|
||||
return form({'machineform': machinetype, 'interfaceform': None}, 'machines/machine.html', request)
|
||||
|
||||
def index(request):
|
||||
machine_list = Interface.objects.order_by('pk')
|
||||
return render(request, 'machines/index.html', {'machine_list': machine_list})
|
||||
|
|
Loading…
Reference in a new issue