diff --git a/cotisations/urls.py b/cotisations/urls.py index d3e56f36..e16812b4 100644 --- a/cotisations/urls.py +++ b/cotisations/urls.py @@ -24,6 +24,7 @@ from __future__ import unicode_literals from django.conf.urls import url +import re2o from . import views urlpatterns = [ @@ -99,21 +100,11 @@ urlpatterns = [ views.index_paiement, name='index-paiement' ), - url(r'^history/(?Pfacture)/(?P[0-9]+)$', - views.history, - name='history' - ), - url(r'^history/(?Particle)/(?P[0-9]+)$', - views.history, - name='history' - ), - url(r'^history/(?Ppaiement)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Pbanque)/(?P[0-9]+)$', - views.history, - name='history' - ), + url( + r'history/(?P\w+)/(?P[0-9]+)$', + re2o.views.history, + name='history', + ), url(r'^control/$', views.control, name='control' diff --git a/cotisations/views.py b/cotisations/views.py index c5a63f51..cabaa8db 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -590,60 +590,3 @@ def index(request): return render(request, 'cotisations/index.html', { 'facture_list': facture_list }) - - -@login_required -def history(request, object_name, object_id): - """Affiche l'historique de chaque objet""" - if object_name == 'facture': - try: - object_instance = Facture.objects.get(pk=object_id) - except Facture.DoesNotExist: - messages.error(request, "Facture inexistante") - return redirect(reverse('cotisations:index')) - 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(reverse( - 'users:profil', - kwargs={'userid':str(request.user.id)} - )) - elif object_name == 'paiement' and request.user.has_perms(('cableur',)): - try: - object_instance = Paiement.objects.get(pk=object_id) - except Paiement.DoesNotExist: - messages.error(request, "Paiement inexistant") - return redirect(reverse('cotisations:index')) - elif object_name == 'article' and request.user.has_perms(('cableur',)): - try: - object_instance = Article.objects.get(pk=object_id) - except Article.DoesNotExist: - messages.error(request, "Article inexistante") - return redirect(reverse('cotisations:index')) - elif object_name == 'banque' and request.user.has_perms(('cableur',)): - try: - object_instance = Banque.objects.get(pk=object_id) - except Banque.DoesNotExist: - messages.error(request, "Banque inexistante") - return redirect(reverse('cotisations:index')) - else: - messages.error(request, "Objet inconnu") - return redirect(reverse('cotisations:index')) - options, _created = GeneralOption.objects.get_or_create() - pagination_number = options.pagination_number - 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, 're2o/history.html', { - 'reversions': reversions, - 'object': object_instance - }) diff --git a/re2o/views.py b/re2o/views.py index 7337b8f1..50502211 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -35,7 +35,7 @@ from reversion.models import Version from django.contrib import messages from preferences.models import Service from preferences.models import OptionalUser, GeneralOption -import users, preferences +import users, preferences, cotisations def form(ctx, template, request): """Form générique, raccourci importé par les fonctions views du site""" @@ -60,6 +60,10 @@ HISTORY_BIND = { 'listright' : users.models.ListRight, 'serviceuser' : users.models.ServiceUser, 'service' : preferences.models.Service, + 'facture' : cotisations.models.Facture, + 'article' : cotisations.models.Article, + 'paiement' : cotisations.models.Paiement, + 'banque' : cotisations.models.Banque, } @login_required