general: redo submission, support for dgs & dga screen for alfortville
This commit is contained in:
parent
30e1c9cc43
commit
80909756fa
|
@ -1,81 +0,0 @@
|
|||
{% extends "welco/base.html" %}
|
||||
{% load i18n static %}
|
||||
|
||||
{% block bodyargs %}class="dgs-home"{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="dgs-page">
|
||||
|
||||
<div class="dgs-view">
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="objects-list">
|
||||
{% for formdef in formdefs %}
|
||||
{% if formdef.associations|length %}
|
||||
<div><a href="#">{{ formdef.formdef.name }}</a><span class="badge">{{ formdef.associations|length }}</span>
|
||||
<table class="dgs-summary" style="display: none;">
|
||||
{% for asso in formdef.associations %}
|
||||
<tr data-mail-pk="{{asso.source.id}}" data-qualif-pk="{{ asso.id }}" data-pdf-href="{{ asso.source.content.url }}">
|
||||
<td class="datetime">{{ asso.source.creation_timestamp }}</td>
|
||||
<td class="info"><a rel="popup" data-inplace-submit="true"
|
||||
href="{% url 'alfortville-copies' pk=asso.id %}">Pour info :
|
||||
<span>{{asso.info}}</span></a></td>
|
||||
<td class="avis"><a rel="popup" data-inplace-submit="true"
|
||||
href="{% url 'alfortville-copies' pk=asso.id %}">Pour avis :
|
||||
<span>{{asso.avis}}</span></a></td>
|
||||
<td><input name="validated" value="{{asso.id}}" type="checkbox"></input></td>
|
||||
</tr>
|
||||
<tr style="display: none" class="comments-row">
|
||||
<td colspan="4">
|
||||
<textarea name="comment-{{asso.id}}" rows="2" style="width: 80%;"
|
||||
placeholder="{% trans 'Comments' %}"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button>{% trans 'Submit' %}</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="dgs-viewer">
|
||||
<iframe id="pdf-viewer" src="{% url 'mail-viewer' %}" style="width: 100%;
|
||||
height: 100%; border: 0;">
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
$('div.objects-list div > a').on('click', function() {
|
||||
$(this).parent().find('table').toggle();
|
||||
return false;
|
||||
});
|
||||
$('a[rel=popup]').on('gadjo:dialog-done', function() {
|
||||
var $tr = $(this).parents('tr');
|
||||
var qualif_pk = $tr.data('qualif-pk');
|
||||
$.getJSON(
|
||||
'/ajax/copies/' + qualif_pk + '/',
|
||||
function(data) {
|
||||
$tr.find('td.info a span').text(data.info);
|
||||
$tr.find('td.avis a span').text(data.avis);
|
||||
}
|
||||
);
|
||||
});
|
||||
$('tr[data-pdf-href]').on('click', function() {
|
||||
$(this).next().toggle();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import dgs, copies, copies_ajax, table_info, table_avis
|
||||
from .views import dgs, dga, copies, copies_ajax, table_info, table_avis
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('^dgs/$', dgs, name='alfortville-dgs'),
|
||||
url('^dga/$', dga, name='alfortville-dga'),
|
||||
url('^copies/(?P<pk>\w+)/$', copies, name='alfortville-copies'),
|
||||
url('^ajax/copies/(?P<pk>\w+)/$', copies_ajax, name='alfortville-copies-ajax'),
|
||||
url('^table/info/$', table_info, name='alfortville-table-info'),
|
||||
|
|
|
@ -27,49 +27,32 @@ from django.views.generic import TemplateView, DetailView
|
|||
from .models import Inbox
|
||||
|
||||
from welco.sources.mail.models import Mail
|
||||
from welco.sources.mail.views import Home as MailHome
|
||||
from welco.utils import get_wcs_data
|
||||
from welco.views import Home as HomeScreen
|
||||
|
||||
class Dgs(TemplateView):
|
||||
template_name = 'alfortville/dgs.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
roles_by_slug = {}
|
||||
for role in get_wcs_data('api/roles').get('data'):
|
||||
roles_by_slug[role['slug']] = role
|
||||
context = super(Dgs, self).get_context_data(**kwargs)
|
||||
formdefs = []
|
||||
for formdef in FormdefReference.objects.order_by('reference'):
|
||||
formdefs.append({
|
||||
'formdef': formdef,
|
||||
'associations': list(formdef.association_set.filter(triaged=True, formdatas=None))
|
||||
})
|
||||
for association in formdefs[-1]['associations']:
|
||||
avis = []
|
||||
info = []
|
||||
for inbox in Inbox.objects.filter(qualif=association):
|
||||
if inbox.subtype == inbox.AVIS:
|
||||
avis.append(roles_by_slug[inbox.role_slug]['text'])
|
||||
else:
|
||||
info.append(roles_by_slug[inbox.role_slug]['text'])
|
||||
association.avis = ', '.join(avis)
|
||||
association.info = ', '.join(info)
|
||||
context['formdefs'] = formdefs
|
||||
context['request'] = self.request
|
||||
return context
|
||||
class DgsMailHome(MailHome):
|
||||
def get_queryset(self):
|
||||
return Mail.objects.filter(status='done-qualif')
|
||||
|
||||
def post(self, request):
|
||||
for valid_id in request.POST.getlist('validated'):
|
||||
assoc = Association.objects.get(id=valid_id)
|
||||
assoc.comments = request.POST['comment-%s' % valid_id]
|
||||
assoc.save()
|
||||
context = assoc.source.get_source_context(request)
|
||||
context['comments'] = assoc.comments
|
||||
assoc.push(request, context=context)
|
||||
return HttpResponseRedirect(reverse('alfortville-dgs'))
|
||||
class Dgs(HomeScreen):
|
||||
source_klass = DgsMailHome
|
||||
|
||||
dgs = login_required(Dgs.as_view())
|
||||
|
||||
|
||||
class DgaMailHome(MailHome):
|
||||
def get_queryset(self):
|
||||
# XXX: filter on formdefs related to the current user
|
||||
return Mail.objects.filter(status='done-dgs')
|
||||
|
||||
class Dga(HomeScreen):
|
||||
source_klass = DgaMailHome
|
||||
|
||||
dga = login_required(Dga.as_view())
|
||||
|
||||
|
||||
class Copies(DetailView):
|
||||
model = Mail
|
||||
template_name = 'alfortville/copies.html'
|
||||
|
|
|
@ -32,15 +32,16 @@ class Association(models.Model):
|
|||
formdef_reference = models.CharField(max_length=250, null=True)
|
||||
formdata_id = models.CharField(max_length=250, null=True)
|
||||
|
||||
def push(self, request, context):
|
||||
def push(self, request, context=None):
|
||||
# push validated request to wcs
|
||||
if context:
|
||||
context = context.copy()
|
||||
context['user_id'] = self.user_id
|
||||
else:
|
||||
context = {}
|
||||
context['user_id'] = self.source.contact_id
|
||||
|
||||
if self.formdef_reference:
|
||||
self.formdata_id = push_wcs_formdata(request, self.formdef_reference, context)
|
||||
self.save()
|
||||
self.formdata_id = push_wcs_formdata(request, self.formdef_reference, context)
|
||||
self.save()
|
||||
|
||||
@property
|
||||
def formdef_name(self):
|
||||
|
|
|
@ -164,6 +164,9 @@ HAYSTACK_CONNECTIONS = {
|
|||
|
||||
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
|
||||
|
||||
# VALIDATION_STEPS = ['done-qualif']
|
||||
VALIDATION_STEPS = ['done-qualif', 'done-dgs', 'done-dga']
|
||||
|
||||
|
||||
local_settings_file = os.environ.get('WELCO_SETTINGS_FILE',
|
||||
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
|
||||
|
|
|
@ -55,10 +55,12 @@ class Home(object):
|
|||
def __init__(self, request):
|
||||
self.request = request
|
||||
|
||||
def get_queryset(self):
|
||||
return Mail.objects.exclude(status__startswith='done-')
|
||||
|
||||
def render(self):
|
||||
context = RequestContext(self.request)
|
||||
context['mails'] = Mail.objects.exclude(status__startswith='done-'
|
||||
).order_by('creation_timestamp')
|
||||
context['mails'] = self.get_queryset().order_by('creation_timestamp')
|
||||
context['source_type'] = ContentType.objects.get_for_model(Mail)
|
||||
context['form'] = MailQualificationForm()
|
||||
context['source_form_url'] = Mail.get_qualification_form_submit_url()
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<button class="add">{% trans 'Add' %}</button>
|
||||
</div>
|
||||
{% if associations|length %}
|
||||
<button class="done" data-action-url="{% url 'qualif-done' %}">{% trans 'Done' %}</button>
|
||||
<button class="done" data-action-url="{% url 'qualif-done' %}">{% trans 'Submit' %}</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
import json
|
||||
import urllib
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
@ -111,7 +112,16 @@ def qualification_done(request):
|
|||
source_class = ContentType.objects.get(
|
||||
id=request.POST['source_type']).model_class()
|
||||
source_object = source_class.objects.get(id=request.POST['source_pk'])
|
||||
source_object.status = 'done-qualif'
|
||||
if source_object.status:
|
||||
source_object.status = settings.VALIDATION_STEPS[
|
||||
settings.VALIDATION_STEPS.index(source_object.status)+1]
|
||||
else:
|
||||
source_object.status = settings.VALIDATION_STEPS[0]
|
||||
if source_object.status == settings.VALIDATION_STEPS[-1]:
|
||||
for association in Association.objects.filter(
|
||||
source_type=request.POST['source_type'],
|
||||
source_pk=request.POST['source_pk']):
|
||||
association.push(request)
|
||||
source_object.save()
|
||||
response = HttpResponse(content_type='application/json')
|
||||
json.dump({'result': 'ok'}, response, indent=2)
|
||||
|
|
Loading…
Reference in New Issue