diff --git a/welco/kb/__init__.py b/welco/kb/__init__.py index adda67f..06dc027 100644 --- a/welco/kb/__init__.py +++ b/welco/kb/__init__.py @@ -13,3 +13,5 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +default_app_config = 'welco.kb.apps.KbAppConfig' diff --git a/welco/settings.py b/welco/settings.py index 9d8721f..5421f2a 100644 --- a/welco/settings.py +++ b/welco/settings.py @@ -42,7 +42,7 @@ INSTALLED_APPS = ( 'haystack', 'taggit', 'welco.sources.counter', - 'welco.sources.mail.apps.AppConfig', + 'welco.sources.mail', 'welco.sources.phone', 'welco.qualif', 'welco.kb', diff --git a/welco/sources/mail/__init__.py b/welco/sources/mail/__init__.py index e69de29..94c300e 100644 --- a/welco/sources/mail/__init__.py +++ b/welco/sources/mail/__init__.py @@ -0,0 +1,55 @@ +# welco - multichannel request processing +# Copyright (C) 2018 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 . + +import django.apps + + +class AppConfig(django.apps.AppConfig): + name = 'welco.sources.mail' + + def get_before_urls(self): + from . import urls + + return urls.urlpatterns + + def ready(self): + from django.db.models import signals + + from welco.qualif.models import Association + + signals.post_save.connect(self.association_post_save, sender=Association) + + def association_post_save(self, sender, instance, **kwargs): + from .utils import get_maarch + + if not instance.formdata_id: + return + source = instance.source + if not getattr(source, 'external_id', None): + return + external_id = source.external_id + if not external_id.startswith('maarch-'): + return + maarch_pk = int(external_id.split('-', 1)[-1]) + maarch = get_maarch() + maarch.set_grc_sent_status( + mail_pk=maarch_pk, + formdata_id=instance.formdata_id, + formdata_url_backoffice=instance.formdata_url_backoffice, + ) + + +default_app_config = 'welco.sources.mail.AppConfig' diff --git a/welco/sources/mail/apps.py b/welco/sources/mail/apps.py deleted file mode 100644 index 7aaf541..0000000 --- a/welco/sources/mail/apps.py +++ /dev/null @@ -1,52 +0,0 @@ -# welco - multichannel request processing -# Copyright (C) 2018 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 . - -import django.apps - - -class AppConfig(django.apps.AppConfig): - name = 'welco.sources.mail' - - def get_before_urls(self): - from . import urls - - return urls.urlpatterns - - def ready(self): - from django.db.models import signals - - from welco.qualif.models import Association - - signals.post_save.connect(self.association_post_save, sender=Association) - - def association_post_save(self, sender, instance, **kwargs): - from .utils import get_maarch - - if not instance.formdata_id: - return - source = instance.source - if not getattr(source, 'external_id', None): - return - external_id = source.external_id - if not external_id.startswith('maarch-'): - return - maarch_pk = int(external_id.split('-', 1)[-1]) - maarch = get_maarch() - maarch.set_grc_sent_status( - mail_pk=maarch_pk, - formdata_id=instance.formdata_id, - formdata_url_backoffice=instance.formdata_url_backoffice, - )