From 1e592ad507e431f6ac6e729b5c0a38b249c660ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 10 Jun 2016 21:10:32 +0200 Subject: [PATCH] alfortville: make it possible for DG[AS] to mass validate (#11303) --- .../templates/alfortville/dg-table.html | 19 +++++--- welco/contrib/alfortville/urls.py | 4 +- welco/contrib/alfortville/views.py | 47 +++++++++++++++++++ welco/static/css/style.css | 10 ++++ 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/welco/contrib/alfortville/templates/alfortville/dg-table.html b/welco/contrib/alfortville/templates/alfortville/dg-table.html index a688d42..e11f5fb 100644 --- a/welco/contrib/alfortville/templates/alfortville/dg-table.html +++ b/welco/contrib/alfortville/templates/alfortville/dg-table.html @@ -10,6 +10,7 @@ {% block content %} +
{% if source.get_queryset %} @@ -20,24 +21,30 @@ {% trans 'User' %} {% trans 'Category' %} {% trans 'Related Forms' %} + {% for object in mails %} - {{object.creation_timestamp|date:"d F Y"|lower}} - {{object.contact_name }} - {{object.categories|join:", " }} - {% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %} + {{object.creation_timestamp|date:"d F Y"|lower}} + {{object.contact_name }} + {{object.categories|join:", " }} + {% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %} + {% endfor %}
+
+{% csrf_token %} + + {%else %}

{% trans 'There is currently no mail in this list.' %} diff --git a/welco/contrib/alfortville/urls.py b/welco/contrib/alfortville/urls.py index 6d22acd..648f512 100644 --- a/welco/contrib/alfortville/urls.py +++ b/welco/contrib/alfortville/urls.py @@ -18,11 +18,13 @@ from django.conf.urls import patterns, url from .views import (dgs, dga, copies, copies_ajax, table_info, table_avis, table_mandatory_avis, table_waiting, count_dgs, count_dga, count_info, - count_avis, count_mandatory_avis) + count_avis, count_mandatory_avis, dgs_qualif_many, dga_qualif_many) urlpatterns = patterns('', url(r'^dgs/(?Ptable/)?$', dgs, name='alfortville-dgs'), url(r'^dga/(?P
table/)?$', dga, name='alfortville-dga'), + url(r'^dgs/table/qualif-many$', dgs_qualif_many, name='alfortville-dgs-qualif-many'), + url(r'^dga/table/qualif-many$', dga_qualif_many, name='alfortville-dga-qualif-many'), url(r'^copies/(?P\w+)/$', copies, name='alfortville-copies'), url(r'^ajax/copies/(?P\w+)/$', copies_ajax, name='alfortville-copies-ajax'), url(r'^table/info/$', table_info, name='alfortville-table-info'), diff --git a/welco/contrib/alfortville/views.py b/welco/contrib/alfortville/views.py index 4076d8f..1823fe7 100644 --- a/welco/contrib/alfortville/views.py +++ b/welco/contrib/alfortville/views.py @@ -15,9 +15,12 @@ # along with this program. If not, see . import json +import logging +from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType +from django.core.urlresolvers import reverse from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ @@ -102,6 +105,50 @@ class Dga(DgHomeScreen): dga = login_required(Dga.as_view()) +class QualifMixin(object): + def get(self, request, *args, **kwargs): + return HttpResponseRedirect(self.get_redirect_url()) + + def post(self, request, *args, **kwargs): + source_pks = request.POST.getlist('pks') + logger = logging.getLogger(__name__) + validation_steps = settings.VALIDATION_STEPS.get('mail') + mail_content_type = ContentType.objects.get_for_model(Mail) + allowed_mails = [str(x.id) for x in self.source_klass(request).get_queryset()] + mail_ids = set(source_pks).intersection(set(allowed_mails)) + for mail in Mail.objects.filter(id__in=mail_ids): + if mail.status: + mail.status = validation_steps[ + validation_steps.index(mail.status)+1] + else: + mail.status = validation_steps[0] + if mail.status == validation_steps[-1]: + for association in Association.objects.filter( + source_type=mail_content_type, + source_pk=mail.id): + try: + association.push(request) + except Exception, e: + logger.exception('error pushing mail') + continue + mail.save() + return HttpResponseRedirect(self.get_redirect_url()) + + +class DgaQualifMany(QualifMixin, Dga): + def get_redirect_url(self): + return reverse('alfortville-dga', kwargs={'table': 'table/'}) + +dga_qualif_many = login_required(DgaQualifMany.as_view()) + + +class DgsQualifMany(QualifMixin, Dgs): + def get_redirect_url(self): + return reverse('alfortville-dgs', kwargs={'table': 'table/'}) + +dgs_qualif_many = login_required(DgsQualifMany.as_view()) + + class Copies(DetailView): model = Mail template_name = 'alfortville/copies.html' diff --git a/welco/static/css/style.css b/welco/static/css/style.css index 6b5bff7..1845e8e 100644 --- a/welco/static/css/style.css +++ b/welco/static/css/style.css @@ -695,3 +695,13 @@ div.add-formdef-reference button.add { ul.select-formdata li li:hover { background: #eee; } + +div#content .cell > div#dg-transmit { + margin: 2ex 0; + display: block; + text-align: right; +} + +div#content .cell > div#dg-transmit button { + margin-right: 1ex; +}