2015-07-03 11:28:48 +02:00
|
|
|
# welco - multichannel request processing
|
|
|
|
# Copyright (C) 2015 Entr'ouvert
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-09-19 20:19:28 +02:00
|
|
|
import subprocess
|
|
|
|
|
2015-10-09 15:53:47 +02:00
|
|
|
from django.contrib.contenttypes import generic
|
2015-08-31 15:45:37 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2015-07-03 11:28:48 +02:00
|
|
|
from django.db import models
|
2015-09-19 20:19:28 +02:00
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.dispatch import receiver
|
2015-07-03 11:28:48 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2015-10-09 15:53:47 +02:00
|
|
|
from welco.qualif.models import Association
|
|
|
|
|
2015-07-03 11:28:48 +02:00
|
|
|
class Mail(models.Model):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Mail')
|
|
|
|
|
|
|
|
content = models.FileField(_('Content'))
|
2015-08-31 09:57:37 +02:00
|
|
|
post_date = models.DateField(_('Post Date'), null=True)
|
2015-10-10 18:21:37 +02:00
|
|
|
registered_mail_number = models.CharField(_('Registered Mail Number'),
|
|
|
|
null=True, max_length=50)
|
2015-10-11 14:38:41 +02:00
|
|
|
note = models.TextField(_('Note'), null=True)
|
2015-07-03 11:28:48 +02:00
|
|
|
|
2015-10-09 14:01:59 +02:00
|
|
|
# common to all source types:
|
|
|
|
status = models.CharField(_('Status'), blank=True, max_length=50)
|
|
|
|
contact_id = models.CharField(max_length=50, null=True)
|
2015-10-09 15:53:47 +02:00
|
|
|
associations = generic.GenericRelation(Association,
|
|
|
|
content_type_field='source_type', object_id_field='source_pk')
|
2015-10-09 14:01:59 +02:00
|
|
|
|
2015-07-03 11:28:48 +02:00
|
|
|
creation_timestamp = models.DateTimeField(auto_now_add=True)
|
|
|
|
last_update_timestamp = models.DateTimeField(auto_now=True)
|
2015-08-31 15:45:37 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_qualification_form_class(cls):
|
|
|
|
from .forms import MailQualificationForm
|
|
|
|
return MailQualificationForm
|
|
|
|
|
|
|
|
def get_qualification_form(self):
|
|
|
|
return self.get_qualification_form_class()({
|
|
|
|
'post_date': self.post_date,
|
2015-10-10 18:21:37 +02:00
|
|
|
'registered_mail_number': self.registered_mail_number})
|
2015-08-31 15:45:37 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_qualification_form_submit_url(cls):
|
|
|
|
return reverse('qualif-mail-save')
|
2015-09-19 20:19:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Mail)
|
|
|
|
def create_thumbnail(sender, instance, created, **kwargs):
|
|
|
|
if not created:
|
|
|
|
return
|
2015-09-21 15:15:21 +02:00
|
|
|
subprocess.call(['gm', 'convert', '-geometry', '200x',
|
2015-09-19 20:19:28 +02:00
|
|
|
instance.content.file.name, instance.content.file.name + '.png'])
|