Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 6d1b41ff authored by chirac's avatar chirac

Vues pour gérer la liste des articles

parent 387515d4
...@@ -82,3 +82,35 @@ class EditFactureForm(NewFactureForm): ...@@ -82,3 +82,35 @@ class EditFactureForm(NewFactureForm):
self.fields['prix'].label = 'Prix unitaire' self.fields['prix'].label = 'Prix unitaire'
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire" self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
self.fields.pop('article') self.fields.pop('article')
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = '__all__'
def __init__(self, *args, **kwargs):
super(ArticleForm, self).__init__(*args, **kwargs)
self.fields['name'].label = "Désignation de l'article"
class DelArticleForm(ModelForm):
articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
fields = ['articles']
model = Article
class PaiementForm(ModelForm):
class Meta:
model = Paiement
fields = ['moyen']
def __init__(self, *args, **kwargs):
super(PaiementForm, self).__init__(*args, **kwargs)
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
class DelPaiementForm(ModelForm):
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['moyen']
model = Paiement
...@@ -5,6 +5,8 @@ from . import views ...@@ -5,6 +5,8 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^new_facture/(?P<userid>[0-9]+)$', views.new_facture, name='new-facture'), url(r'^new_facture/(?P<userid>[0-9]+)$', views.new_facture, name='new-facture'),
url(r'^edit_facture/(?P<factureid>[0-9]+)$', views.edit_facture, name='edit-facture'), url(r'^edit_facture/(?P<factureid>[0-9]+)$', views.edit_facture, name='edit-facture'),
url(r'^add_article/$', views.add_article, name='add-article'),
url(r'^del_article/$', views.del_article, name='del-article'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]
......
...@@ -6,9 +6,9 @@ from django.shortcuts import render_to_response, get_object_or_404 ...@@ -6,9 +6,9 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.template import Context, RequestContext, loader from django.template import Context, RequestContext, loader
from django.contrib import messages from django.contrib import messages
from django.db.models import Max from django.db.models import Max, ProtectedError
from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article, Cotisation from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article, Cotisation, Article, ArticleForm, DelArticleForm, Paiement, PaiementForm, DelPaiementForm
from users.models import User from users.models import User
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
...@@ -81,6 +81,23 @@ def edit_facture(request, factureid): ...@@ -81,6 +81,23 @@ def edit_facture(request, factureid):
return redirect("/cotisations/") return redirect("/cotisations/")
return form({'factureform': facture_form}, 'cotisations/facture.html', request) return form({'factureform': facture_form}, 'cotisations/facture.html', request)
def add_article(request):
article = ArticleForm(request.POST or None)
if article.is_valid():
article.save()
messages.success(request, "L'article a été ajouté")
return redirect("/cotisations/")
return form({'factureform': article}, 'cotisations/facture.html', request)
def del_article(request):
article = DelArticleForm(request.POST or None)
if article.is_valid():
article_del = article.cleaned_data['articles']
article_del.delete()
messages.success(request, "Le/les articles ont été supprimé")
return redirect("/cotisations/")
return form({'factureform': article}, 'cotisations/facture.html', request)
def index(request): def index(request):
facture_list = Facture.objects.order_by('date').reverse() facture_list = Facture.objects.order_by('date').reverse()
return render(request, 'cotisations/index.html', {'facture_list': facture_list}) return render(request, 'cotisations/index.html', {'facture_list': facture_list})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment