From d9ac4023e4b6e1ba7cacd1f0922fc3b450490633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 29 Mar 2016 16:56:27 +0200 Subject: [PATCH] alfortville: pester users about comments to write (#10093) --- debian/welco.cron.d | 4 ++ .../alfortville/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/send-avis-email.py | 48 +++++++++++++++++++ .../templates/alfortville/avis-email_body.txt | 9 ++++ .../alfortville/avis-email_subject.txt | 1 + 6 files changed, 62 insertions(+) create mode 100644 debian/welco.cron.d create mode 100644 welco/contrib/alfortville/management/__init__.py create mode 100644 welco/contrib/alfortville/management/commands/__init__.py create mode 100644 welco/contrib/alfortville/management/commands/send-avis-email.py create mode 100644 welco/contrib/alfortville/templates/alfortville/avis-email_body.txt create mode 100644 welco/contrib/alfortville/templates/alfortville/avis-email_subject.txt diff --git a/debian/welco.cron.d b/debian/welco.cron.d new file mode 100644 index 0000000..adb4540 --- /dev/null +++ b/debian/welco.cron.d @@ -0,0 +1,4 @@ +SHELL=/bin/sh +PATH=/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin + +0 7 * * 1-5 /usr/bin/welco-manage tenant_command send-avis-email --all-tenants diff --git a/welco/contrib/alfortville/management/__init__.py b/welco/contrib/alfortville/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/welco/contrib/alfortville/management/commands/__init__.py b/welco/contrib/alfortville/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/welco/contrib/alfortville/management/commands/send-avis-email.py b/welco/contrib/alfortville/management/commands/send-avis-email.py new file mode 100644 index 0000000..3bb2493 --- /dev/null +++ b/welco/contrib/alfortville/management/commands/send-avis-email.py @@ -0,0 +1,48 @@ +# welco - multichannel request processing +# Copyright (C) 2015-2016 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 . + +from django.conf import settings +from django.contrib.auth import get_user_model +from django.core.mail import EmailMessage, send_mass_mail +from django.core.management.base import BaseCommand, CommandError +from django.template.loader import render_to_string + +from hobo.agent.common.models import Role +from welco.contrib.alfortville.models import Inbox + + +class Command(BaseCommand): + def handle(self, *args, **kwargs): + ctx = {} + ctx.update(getattr(settings, 'TEMPLATE_VARS', {})) + + subject = render_to_string(['alfortville/avis-email_subject.txt'], ctx).strip() + message = render_to_string(['alfortville/avis-email_body.txt'], ctx) + mails = [] + + User = get_user_model() + for user in User.objects.all(): + user_roles = [x.uuid for x in Role.objects.filter(user=user)] + avis = Inbox.objects.filter( + role_slug__in=user_roles, + subtype__in=[Inbox.MANDATORY_AVIS, Inbox.AVIS], + done=False) + if avis.count() == 0: + continue + mails.append((subject, message, settings.DEFAULT_FROM_EMAIL, [user.email])) + + if mails: + send_mass_mail(mails) diff --git a/welco/contrib/alfortville/templates/alfortville/avis-email_body.txt b/welco/contrib/alfortville/templates/alfortville/avis-email_body.txt new file mode 100644 index 0000000..e60de9c --- /dev/null +++ b/welco/contrib/alfortville/templates/alfortville/avis-email_body.txt @@ -0,0 +1,9 @@ +Bonjour, + +Vous avez des avis à donner sur des courriers (avis requis et/ou avis +demandés). + +Pour prendre connaissance des courriers et déposer vos avis, merci de vous +rendre sur : + +{{ portal_agent_url }} diff --git a/welco/contrib/alfortville/templates/alfortville/avis-email_subject.txt b/welco/contrib/alfortville/templates/alfortville/avis-email_subject.txt new file mode 100644 index 0000000..8c7155f --- /dev/null +++ b/welco/contrib/alfortville/templates/alfortville/avis-email_subject.txt @@ -0,0 +1 @@ +Avis attendus sur des courriers