Projet

Général

Profil

0001-mails-add-subject-field-only-for-alfortville-flavour.patch

Thomas Noël, 21 juin 2016 23:12

Télécharger (11,3 ko)

Voir les différences:

Subject: [PATCH] mails: add subject field, only for alfortville flavour
 (#11289)

 .../alfortville/templates/alfortville/dg-table.html   |  4 ++++
 .../templates/alfortville/mail-table-waiting.html     |  2 ++
 welco/settings.py                                     |  4 ++++
 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                           |  1 +
 welco/static/css/style.css                            |  4 ++++
 welco/static/js/welco.js                              |  4 ++++
 11 files changed, 65 insertions(+), 4 deletions(-)
 create mode 100644 welco/sources/mail/migrations/0010_mail_subject.py
welco/contrib/alfortville/templates/alfortville/dg-table.html
18 18
<table class="main">
19 19
<thead>
20 20
 <th>{% trans 'Scan Date' %}</th>
21
 <th>{% trans 'Post Date' %}</th>
22
 <th>{% trans 'Subject' %}</th>
21 23
 <th>{% trans 'User' %}</th>
22 24
 <th>{% trans 'Category' %}</th>
23 25
 <th>{% trans 'Related Forms' %}</th>
......
27 29
{% for object in mails %}
28 30
<tr data-mail-id="{{object.id}}">
29 31
  <td class="r">{{object.creation_timestamp|date:"d F Y"|lower}}</td>
32
  <td class="r">{{object.post_date|date:"d F Y"|lower}}</td>
33
  <td class="r">{{object.subject|default:'-'}}</td>
30 34
  <td class="r">{{object.contact_name }}</td>
31 35
  <td class="r">{{object.categories|join:", " }}</td>
32 36
  <td class="r">{% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {%  endif %}{% endfor %}</td>
welco/contrib/alfortville/templates/alfortville/mail-table-waiting.html
14 14
<thead>
15 15
 <th>{% trans 'Scan Date' %}</th>
16 16
 <th>{% trans 'Post Date' %}</th>
17
 <th>{% trans 'Subject' %}</th>
17 18
 <th>{% trans 'Related Forms' %}</th>
18 19
 <th>{% trans 'Status' %}</th>
19 20
</thead>
......
22 23
<tr>
23 24
  <td>{{object.creation_timestamp|date:"d F Y"|lower}}</td>
24 25
  <td>{{object.post_date|default:'-'}}</td>
26
  <td>{{object.subject|default:'-'}}</td>
25 27
  <td>{% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {%  endif %}{% endfor %}</td>
26 28
  <td>{% if object.status == 'done-qualif' %}En attente de validation DGS
27 29
      {% elif object.status == 'done-dgs' %}En attente de validation DGA
welco/settings.py
193 193
    {'label': 'Wikipedia', 'url': 'https://fr.wikipedia.org'}
194 194
]
195 195

  
196
# enable/disable specific features
197
# ex: FLAVOURS = ['alfortville']
198
FLAVOURS = []
199

  
196 200
local_settings_file = os.environ.get('WELCO_SETTINGS_FILE',
197 201
        os.path.join(os.path.dirname(__file__), 'local_settings.py'))
198 202
if os.path.exists(local_settings_file):
welco/sources/mail/forms.py
16 16

  
17 17
from django import forms
18 18
from django.utils.translation import ugettext_lazy as _
19
from django.conf import settings
19 20

  
20 21
class MailQualificationForm(forms.Form):
21 22
    post_date = forms.DateTimeField(label=_('Post Date (*)'), required=False)
22 23
    registered_mail_number = forms.CharField(label=_('Registered Mail Number'), required=False)
24
    subject = forms.CharField(label='Subject', required=False, widget=forms.HiddenInput)
25

  
26
    def __init__(self, *args, **kwargs):
27
        super(MailQualificationForm, self).__init__(*args, **kwargs)
28
        if 'alfortville' in getattr(settings, 'FLAVOURS', []):
29
            self.fields['subject'].widget = forms.TextInput()
welco/sources/mail/migrations/0010_mail_subject.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3

  
4
from django.db import migrations, models
5

  
6

  
7
class Migration(migrations.Migration):
8

  
9
    dependencies = [
10
        ('mail', '0009_mail_scanner_category'),
11
    ]
12

  
13
    operations = [
14
        migrations.AddField(
15
            model_name='mail',
16
            name='subject',
17
            field=models.CharField(max_length=200, null=True, verbose_name='Subject'),
18
        ),
19
    ]
welco/sources/mail/models.py
17 17
import re
18 18
import subprocess
19 19

  
20
from django.conf import settings
20 21
from django.contrib.contenttypes.fields import GenericRelation
21 22
from django.contrib.contenttypes.models import ContentType
22 23
from django.core.urlresolvers import reverse
......
40 41
            null=True, max_length=50)
41 42
    note = models.TextField(_('Note'), null=True)
42 43

  
44
    # used only if settings.FLAVOURS contains 'alfortville'
45
    subject = models.CharField(_('Subject'), null=True, max_length=200)
46

  
43 47
    scanner_category = models.CharField(max_length=100, blank=True, null=True)
44 48

  
45 49
    # common to all source types:
......
57 61
        return MailQualificationForm
58 62

  
59 63
    def get_qualification_form(self):
60
        return self.get_qualification_form_class()({
64
        data = {
61 65
            'post_date': self.post_date,
62
            'registered_mail_number': self.registered_mail_number})
66
            'registered_mail_number': self.registered_mail_number,
67
        }
68
        if 'alfortville' in getattr(settings, 'FLAVOURS', []):
69
            data['subject'] = self.subject
70
        return self.get_qualification_form_class()(data)
63 71

  
64 72
    @classmethod
65 73
    def get_qualification_form_submit_url(cls):
......
106 114
        return categories.keys()
107 115

  
108 116
    def get_source_context(self, request):
109
        return {
117
        context = {
110 118
            'channel': 'mail',
111 119
            'post_date': self.post_date and self.post_date.strftime('%Y-%m-%d'),
112 120
            'registered_mail_number': self.registered_mail_number,
113 121
        }
122
        if 'alfortville' in getattr(settings, 'FLAVOURS', []):
123
            context['subject'] = self.subject
124
        return context
114 125

  
115 126

  
116 127
@receiver(post_save, sender=Mail)
welco/sources/mail/templates/welco/mail_home.html
10 10
			<li data-source-pk="{{ mail.id }}"
11 11
			    data-pdf-href="{{ mail.content.url }}"
12 12
			    data-post-date="{{ mail.post_date|date:"d/m/Y" }}"
13
			    data-registered-mail-number="{% firstof mail.registered_mail_number %}"
13
			    data-registered-mail-number="{{ mail.registered_mail_number|default:"" }}"
14
			    data-subject="{{ mail.subject|default:"" }}"
14 15
			    >{{ mail.creation_timestamp|date:"d/m/Y" }}
15 16
			    {{mail.contact_name}}
16 17
			    {% for association in mail.associations.all %}
welco/sources/mail/templates/welco/mail_summary.html
7 7
<p class="registered-mail-number">{% trans "Registered Mail Number:" %} {{object.registered_mail_number}}</p>
8 8
{% endif %}
9 9

  
10
{% if object.subject %}
11
<p class="subject">{% trans "Subject:" %} {{object.subject}}</p>
12
{% endif %}
13

  
10 14
<p class="thumbnail">
11 15
 <a href="{{ site_base }}{{ object.content.url }}" target="_blank">
12 16
 <img src="{{ site_base }}{{ object.content.url }}.png" alt=""/>
welco/sources/mail/views.py
88 88
    if form.is_valid():
89 89
        mail.post_date = form.cleaned_data['post_date']
90 90
        mail.registered_mail_number = form.cleaned_data['registered_mail_number']
91
        mail.subject = form.cleaned_data['subject']
91 92
        mail.save()
92 93
    return HttpResponseRedirect(reverse('qualif-zone') +
93 94
            '?source_type=%s&source_pk=%s' % (request.POST['source_type'],
welco/static/css/style.css
474 474
	padding: 0.5ex 0.5ex;
475 475
}
476 476

  
477
#source-mainarea input#id_subject {
478
	width: 40em;
479
}
480

  
477 481
#source-mainarea button {
478 482
	position: relative;
479 483
	top: -2px;
welco/static/js/welco.js
79 79
    $(this).addClass('active');
80 80
    $('#id_post_date').val($(this).data('post-date'));
81 81
    $('#id_registered_mail_number').val($(this).data('registered-mail-number'));
82
    $('#id_subject').val($(this).data('subject'));
82 83
    var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
83 84
    $('#postit > div.content').data('url', $('#postit > div.content').data('base-url') + '?mail=' + source_pk);
84 85
    $('#postit').trigger('welco:load-mail-note');
......
212 213
  $('.document').delegate('button.save', 'click', function() {
213 214
    var post_date = $('#id_post_date').val();
214 215
    var registered_mail_number = $('#id_registered_mail_number').val();
216
    var subject = $('#id_subject').val();
215 217
    var source_type = $('div.source div[data-source-type]').data('source-type');
216 218
    var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
217 219
    $.ajax({url: $(this).data('action-url'),
218 220
            data: {post_date: post_date,
219 221
                   registered_mail_number: registered_mail_number,
222
                   subject: subject,
220 223
                   source_type: source_type,
221 224
                   source_pk: source_pk},
222 225
            method: 'POST',
......
224 227
            success: function(data) {
225 228
                    $('div.source .active').data('post-date', post_date);
226 229
                    $('div.source .active').data('registered-mail-number', registered_mail_number);
230
                    $('div.source .active').data('subject', subject);
227 231
                    $('#source-mainarea form').effect('highlight');
228 232
                    if ($('#id_post_date').length && !$('#id_post_date').val()) {
229 233
                      $('div.qualif button.done').attr('disabled', 'disabled');
230
-