alfortville: make it possible for DG[AS] to mass validate (#11303)

This commit is contained in:
Frédéric Péters 2016-06-10 21:10:32 +02:00
parent 5a68d5e7bc
commit 1e592ad507
4 changed files with 73 additions and 7 deletions

View File

@ -10,6 +10,7 @@
{% block content %}
<form method="post" action="qualif-many">
<div class="source-mail all">
<div class="cell document top">
{% if source.get_queryset %}
@ -20,24 +21,30 @@
<th>{% trans 'User' %}</th>
<th>{% trans 'Category' %}</th>
<th>{% trans 'Related Forms' %}</th>
<td></td>
</thead>
<tbody>
{% for object in mails %}
<tr data-mail-id="{{object.id}}">
<td>{{object.creation_timestamp|date:"d F Y"|lower}}</td>
<td>{{object.contact_name }}</td>
<td>{{object.categories|join:", " }}</td>
<td>{% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td class="r">{{object.creation_timestamp|date:"d F Y"|lower}}</td>
<td class="r">{{object.contact_name }}</td>
<td class="r">{{object.categories|join:", " }}</td>
<td class="r">{% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td><input type="checkbox" name="pks" value="{{object.id}}"/></td>
</tr>
{% endfor %}
</tbody>
<script>
$('tr').click(function() {
window.open('../?' + $(this).data('mail-id'), target='_welco_dg');
$('td.r').click(function() {
window.open('../?' + $(this).parent().data('mail-id'), target='_welco_dg');
});
</script>
</table>
</div>
<div id="dg-transmit">
{% csrf_token %}
<button>Transmettre</button>
</form>
{%else %}
<p class="no-mail-table">
{% trans 'There is currently no mail in this list.' %}

View File

@ -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/(?P<table>table/)?$', dgs, name='alfortville-dgs'),
url(r'^dga/(?P<table>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<pk>\w+)/$', copies, name='alfortville-copies'),
url(r'^ajax/copies/(?P<pk>\w+)/$', copies_ajax, name='alfortville-copies-ajax'),
url(r'^table/info/$', table_info, name='alfortville-table-info'),

View File

@ -15,9 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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'

View File

@ -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;
}