mails: add subject field, only for alfortville flavour (#11289)

This commit is contained in:
Thomas NOËL 2016-06-14 15:34:04 +02:00 committed by Frédéric Péters
parent 59faf92760
commit e48cfe16e9
12 changed files with 68 additions and 5 deletions

View File

@ -18,6 +18,8 @@
<table class="main">
<thead>
<th>{% trans 'Scan Date' %}</th>
<th>{% trans 'Post Date' %}</th>
<th>{% trans 'Subject' %}</th>
<th>{% trans 'User' %}</th>
<th>{% trans 'Category' %}</th>
<th>{% trans 'Related Forms' %}</th>
@ -27,6 +29,8 @@
{% for object in mails %}
<tr data-mail-id="{{object.id}}">
<td class="r">{{object.creation_timestamp|date:"d F Y"|lower}}</td>
<td class="r">{{object.post_date|date:"d F Y"|lower}}</td>
<td class="r">{{object.subject|default:'-'}}</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>

View File

@ -14,6 +14,7 @@
<thead>
<th>{% trans 'Scan Date' %}</th>
<th>{% trans 'Post Date' %}</th>
<th>{% trans 'Subject' %}</th>
<th>{% trans 'Related Forms' %}</th>
<th>{% trans 'Status' %}</th>
</thead>
@ -22,6 +23,7 @@
<tr>
<td>{{object.creation_timestamp|date:"d F Y"|lower}}</td>
<td>{{object.post_date|default:'-'}}</td>
<td>{{object.subject|default:'-'}}</td>
<td>{% for association in object.associations.all %}{{association.formdef_name}}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td>{% if object.status == 'done-qualif' %}En attente de validation DGS
{% elif object.status == 'done-dgs' %}En attente de validation DGA

View File

@ -193,6 +193,10 @@ COUNTER_LINKS = [
{'label': 'Wikipedia', 'url': 'https://fr.wikipedia.org'}
]
# enable/disable specific features
# ex: FLAVOURS = ['alfortville']
FLAVOURS = []
local_settings_file = os.environ.get('WELCO_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):

View File

@ -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 'alfortville' in getattr(settings, 'FLAVOURS', []):
self.fields['subject'].widget = forms.TextInput()

View File

@ -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'),
),
]

View File

@ -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.FLAVOURS contains 'alfortville'
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 'alfortville' in getattr(settings, 'FLAVOURS', []):
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 'alfortville' in getattr(settings, 'FLAVOURS', []):
context['subject'] = self.subject
return context
@receiver(post_save, sender=Mail)

View File

@ -10,7 +10,8 @@
<li data-source-pk="{{ mail.id }}"
data-pdf-href="{{ mail.content.url }}"
data-post-date="{{ mail.post_date|date:"d/m/Y" }}"
data-registered-mail-number="{% firstof mail.registered_mail_number %}"
data-registered-mail-number="{{ mail.registered_mail_number|default:"" }}"
data-subject="{{ mail.subject|default:"" }}"
>{{ mail.creation_timestamp|date:"d/m/Y" }}
{{mail.contact_name}}
{% for association in mail.associations.all %}
@ -31,6 +32,7 @@
{% if reject_url %}
<button data-action-url="{{reject_url}}" class="reject">Rejeter (illisible)</button>
{% endif %}
<br style="clear: both;">
</form>
<div id="postit" style="display: none">
<div class="hbar"></div>

View File

@ -7,6 +7,10 @@
<p class="registered-mail-number">{% trans "Registered Mail Number:" %} {{object.registered_mail_number}}</p>
{% endif %}
{% if object.subject %}
<p class="subject">{% trans "Subject:" %} {{object.subject}}</p>
{% endif %}
<p class="thumbnail">
<a href="{{ site_base }}{{ object.content.url }}" target="_blank">
<img src="{{ site_base }}{{ object.content.url }}.png" alt=""/>

View File

@ -88,6 +88,7 @@ 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']
mail.subject = form.cleaned_data['subject']
mail.save()
return HttpResponseRedirect(reverse('qualif-zone') +
'?source_type=%s&source_pk=%s' % (request.POST['source_type'],

View File

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

View File

@ -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');

View File

@ -36,7 +36,8 @@ $('div.cell').delegate('h2', 'click', function() {
$(window).on('resize', function() {
if ($('.top iframe').length == 1) {
$('.top iframe').css('height', 'calc(100% - 4em)');
var top_form_height = $('.top form').height();
$('.top iframe').css('height', 'calc(100% - ' + top_form_height + 'px)');
} else {
$('iframe').css('height', '100%');
}