From 92927bfee703b3bfd21884d0e5815ee76bc5d97f Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Tue, 14 Jun 2016 15:34:04 +0200 Subject: [PATCH] mails: add subject field (#11289) --- .../alfortville/templates/alfortville/dg-table.html | 4 ++++ .../templates/alfortville/mail-table-waiting.html | 2 ++ welco/sources/mail/forms.py | 7 +++++++ welco/sources/mail/migrations/0010_mail_subject.py | 19 +++++++++++++++++++ welco/sources/mail/models.py | 17 ++++++++++++++--- welco/sources/mail/templates/welco/mail_home.html | 3 ++- welco/sources/mail/templates/welco/mail_summary.html | 4 ++++ welco/sources/mail/views.py | 2 ++ welco/static/css/style.css | 4 ++++ welco/static/js/welco.js | 4 ++++ 10 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 welco/sources/mail/migrations/0010_mail_subject.py diff --git a/welco/contrib/alfortville/templates/alfortville/dg-table.html b/welco/contrib/alfortville/templates/alfortville/dg-table.html index e11f5fb..73a7c46 100644 --- a/welco/contrib/alfortville/templates/alfortville/dg-table.html +++ b/welco/contrib/alfortville/templates/alfortville/dg-table.html @@ -18,6 +18,8 @@ + + @@ -27,6 +29,8 @@ {% for object in mails %} + + diff --git a/welco/contrib/alfortville/templates/alfortville/mail-table-waiting.html b/welco/contrib/alfortville/templates/alfortville/mail-table-waiting.html index 8e3911f..b131b74 100644 --- a/welco/contrib/alfortville/templates/alfortville/mail-table-waiting.html +++ b/welco/contrib/alfortville/templates/alfortville/mail-table-waiting.html @@ -14,6 +14,7 @@ + @@ -22,6 +23,7 @@ +
{% trans 'Scan Date' %}{% trans 'Post Date' %}{% trans 'Subject' %} {% trans 'User' %} {% trans 'Category' %} {% trans 'Related Forms' %}
{{object.creation_timestamp|date:"d F Y"|lower}}{{object.post_date|date:"d F Y"|lower}}{{object.subject|default:'-'}} {{object.contact_name }} {{object.categories|join:", " }} {% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %}
{% trans 'Scan Date' %} {% trans 'Post Date' %}{% trans 'Subject' %} {% trans 'Related Forms' %} {% trans 'Status' %}
{{object.creation_timestamp|date:"d F Y"|lower}} {{object.post_date|default:'-'}}{{object.subject|default:'-'}} {% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %} {% if object.status == 'done-qualif' %}En attente de validation DGS {% elif object.status == 'done-dgs' %}En attente de validation DGA diff --git a/welco/sources/mail/forms.py b/welco/sources/mail/forms.py index ef74d2a..7bda04b 100644 --- a/welco/sources/mail/forms.py +++ b/welco/sources/mail/forms.py @@ -16,7 +16,14 @@ from django import forms from django.utils.translation import ugettext_lazy as _ +from django.conf import settings class MailQualificationForm(forms.Form): post_date = forms.DateTimeField(label=_('Post Date (*)'), required=False) registered_mail_number = forms.CharField(label=_('Registered Mail Number'), required=False) + subject = forms.CharField(label='Subject', required=False, widget=forms.HiddenInput) + + def __init__(self, *args, **kwargs): + super(MailQualificationForm, self).__init__(*args, **kwargs) + if getattr(settings, 'XXX_ALFORTVILLE', False): + self.fields['subject'].widget = forms.TextInput() diff --git a/welco/sources/mail/migrations/0010_mail_subject.py b/welco/sources/mail/migrations/0010_mail_subject.py new file mode 100644 index 0000000..e7642f2 --- /dev/null +++ b/welco/sources/mail/migrations/0010_mail_subject.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mail', '0009_mail_scanner_category'), + ] + + operations = [ + migrations.AddField( + model_name='mail', + name='subject', + field=models.CharField(max_length=200, null=True, verbose_name='Subject'), + ), + ] diff --git a/welco/sources/mail/models.py b/welco/sources/mail/models.py index 64e5c6b..fb47815 100644 --- a/welco/sources/mail/models.py +++ b/welco/sources/mail/models.py @@ -17,6 +17,7 @@ import re import subprocess +from django.conf import settings from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse @@ -40,6 +41,9 @@ class Mail(models.Model): null=True, max_length=50) note = models.TextField(_('Note'), null=True) + # used only if settings.XXX_ALFORTVILLE == True + subject = models.CharField(_('Subject'), null=True, max_length=200) + scanner_category = models.CharField(max_length=100, blank=True, null=True) # common to all source types: @@ -57,9 +61,13 @@ class Mail(models.Model): return MailQualificationForm def get_qualification_form(self): - return self.get_qualification_form_class()({ + data = { 'post_date': self.post_date, - 'registered_mail_number': self.registered_mail_number}) + 'registered_mail_number': self.registered_mail_number, + } + if getattr(settings, 'XXX_ALFORTVILLE', False): + data['subject'] = self.subject + return self.get_qualification_form_class()(data) @classmethod def get_qualification_form_submit_url(cls): @@ -106,11 +114,14 @@ class Mail(models.Model): return categories.keys() def get_source_context(self, request): - return { + context = { 'channel': 'mail', 'post_date': self.post_date and self.post_date.strftime('%Y-%m-%d'), 'registered_mail_number': self.registered_mail_number, } + if getattr(settings, 'XXX_ALFORTVILLE', False): + context['subject'] = self.subject + return context @receiver(post_save, sender=Mail) diff --git a/welco/sources/mail/templates/welco/mail_home.html b/welco/sources/mail/templates/welco/mail_home.html index 5f07939..92848df 100644 --- a/welco/sources/mail/templates/welco/mail_home.html +++ b/welco/sources/mail/templates/welco/mail_home.html @@ -10,7 +10,8 @@
  • {{ mail.creation_timestamp|date:"d/m/Y" }} {{mail.contact_name}} {% for association in mail.associations.all %} diff --git a/welco/sources/mail/templates/welco/mail_summary.html b/welco/sources/mail/templates/welco/mail_summary.html index 7ba521a..0e6d9b2 100644 --- a/welco/sources/mail/templates/welco/mail_summary.html +++ b/welco/sources/mail/templates/welco/mail_summary.html @@ -7,6 +7,10 @@

    {% trans "Registered Mail Number:" %} {{object.registered_mail_number}}

    {% endif %} +{% if object.subject %} +

    {% trans "Subject:" %} {{object.subject}}

    +{% endif %} +

    diff --git a/welco/sources/mail/views.py b/welco/sources/mail/views.py index c420b0b..ddd122a 100644 --- a/welco/sources/mail/views.py +++ b/welco/sources/mail/views.py @@ -88,6 +88,8 @@ def qualification_save(request, *args, **kwargs): if form.is_valid(): mail.post_date = form.cleaned_data['post_date'] mail.registered_mail_number = form.cleaned_data['registered_mail_number'] + if 'subject' in form.cleaned_data: # XXX_ALFORTVILLE + mail.subject = form.cleaned_data['subject'] mail.save() return HttpResponseRedirect(reverse('qualif-zone') + '?source_type=%s&source_pk=%s' % (request.POST['source_type'], diff --git a/welco/static/css/style.css b/welco/static/css/style.css index 1845e8e..2a98090 100644 --- a/welco/static/css/style.css +++ b/welco/static/css/style.css @@ -474,6 +474,10 @@ form#note textarea { padding: 0.5ex 0.5ex; } +#source-mainarea input#id_subject { + width: 40em; +} + #source-mainarea button { position: relative; top: -2px; diff --git a/welco/static/js/welco.js b/welco/static/js/welco.js index de70454..32cd7ce 100644 --- a/welco/static/js/welco.js +++ b/welco/static/js/welco.js @@ -79,6 +79,7 @@ $(function() { $(this).addClass('active'); $('#id_post_date').val($(this).data('post-date')); $('#id_registered_mail_number').val($(this).data('registered-mail-number')); + $('#id_subject').val($(this).data('subject')); var source_pk = $('div.source .active[data-source-pk]').data('source-pk'); $('#postit > div.content').data('url', $('#postit > div.content').data('base-url') + '?mail=' + source_pk); $('#postit').trigger('welco:load-mail-note'); @@ -212,11 +213,13 @@ $(function() { $('.document').delegate('button.save', 'click', function() { var post_date = $('#id_post_date').val(); var registered_mail_number = $('#id_registered_mail_number').val(); + var subject = $('#id_subject').val(); var source_type = $('div.source div[data-source-type]').data('source-type'); var source_pk = $('div.source .active[data-source-pk]').data('source-pk'); $.ajax({url: $(this).data('action-url'), data: {post_date: post_date, registered_mail_number: registered_mail_number, + subject: subject, source_type: source_type, source_pk: source_pk}, method: 'POST', @@ -224,6 +227,7 @@ $(function() { success: function(data) { $('div.source .active').data('post-date', post_date); $('div.source .active').data('registered-mail-number', registered_mail_number); + $('div.source .active').data('subject', subject); $('#source-mainarea form').effect('highlight'); if ($('#id_post_date').length && !$('#id_post_date').val()) { $('div.qualif button.done').attr('disabled', 'disabled'); -- 2.8.1