summary: include avis

This commit is contained in:
Frédéric Péters 2015-10-11 17:40:51 +02:00
parent d71e590d63
commit d22ed473a4
3 changed files with 41 additions and 0 deletions

View File

@ -19,6 +19,8 @@ from django.contrib.contenttypes import generic
from django.db import models
from django.utils.translation import ugettext_lazy as _
from welco.utils import get_wcs_data
class Inbox(models.Model):
INFO = 1
@ -36,3 +38,7 @@ class Inbox(models.Model):
source = generic.GenericForeignKey('source_type', 'source_pk')
done = models.BooleanField(default=False)
comments = models.TextField(blank=True, verbose_name=_('Comments'))
def role_name(self):
return [x for x in get_wcs_data('api/roles').get('data')
if x['slug'] == self.role_slug][0]['name']

View File

@ -17,6 +17,7 @@
import subprocess
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.signals import post_save
@ -59,6 +60,20 @@ class Mail(models.Model):
def get_qualification_form_submit_url(cls):
return reverse('qualif-mail-save')
# TODO: get_avis() and get_mandatory_avis() are custom to alfortville,
# they shouldn't appear in this file.
def get_avis(self):
from welco.contrib.alfortville.models import Inbox
return Inbox.objects.filter(subtype=Inbox.AVIS,
source_type=ContentType.objects.get_for_model(Mail),
source_pk=self.id).exclude(comments__isnull=True).exclude(comments__exact='')
def get_mandatory_avis(self):
from welco.contrib.alfortville.models import Inbox
return Inbox.objects.filter(subtype=Inbox.MANDATORY_AVIS,
source_type=ContentType.objects.get_for_model(Mail),
source_pk=self.id)
@receiver(post_save, sender=Mail)
def create_thumbnail(sender, instance, created, **kwargs):

View File

@ -13,3 +13,23 @@
{% endfor %}
</ul>
{% endif %}
{% if object.get_avis|length %}
<strong>{% trans "Avis" %}</strong>
<ul>
{% for avis in object.get_avis %}
<li>{{avis.role_name}}: {% firstof avis.comments '-' %}</li>
{% endfor %}
</ul>
{% endif %}
{% if object.get_mandatory_avis|length %}
<strong>{% trans "Mandatory Avis" %}</strong>
<ul>
{% for avis in object.get_mandatory_avis %}
<li>{{avis.role_name}}:
{% if avis.comments %}{{ avis.comments }}{% else %}{% trans 'Waiting for avis.' %}{% endif %}</li>
{% endfor %}
</ul>
{% endif %}