def test_template_does_not_exists(self):
     """ checks that fails gracefully when localized content does not exists """
     self._create_template()
     self.assertIsNotNone(MailTemplate.get_template("welcome"))
     # this should log an error and return the default template
     template = MailTemplate.get_template("welcome", lang="es")
     self.assertEquals(template.subject, "Welcome")
     self.assertEquals(template.message,
                       "Welcome to our site. We are glad to see you.")
    def test_retrieve_bcc_cached_invalidation(self):
        """ invalidate cached bcc and add new bcc email """
        self.test_retrieve_bcc_cached()

        bcc = MailBcc.objects.create(email="*****@*****.**")
        template = MailTemplate.get_template("welcome")
        template.bcc_email.add(bcc)
        template.save()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, ["*****@*****.**"])
Exemplo n.º 3
0
    def test_retrieve_bcc_cached_invalidation(self):
        """ invalidate cached bcc and add new bcc email """
        self.test_retrieve_bcc_cached()

        bcc = MailBcc.objects.create(email="*****@*****.**")
        template = MailTemplate.get_template("welcome")
        template.bcc_email.add(bcc)
        template.save()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, ["*****@*****.**"])
Exemplo n.º 4
0
    def test_retrieve_from_cached_invalidation(self):
        """ invalidate cached from and add new email from """
        self.test_retrieve_from_cached()

        mail_from = MailFromEmail.objects.create(
            name="root", email="*****@*****.**", pk=1)
        template = MailTemplate.get_template("welcome")
        template.from_email = mail_from
        template.save()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(
                template.from_email.get_mail_from, "root <*****@*****.**>")
Exemplo n.º 5
0
    def test_retrieve_bcc_cached_invalidation_cache(self):
        """ check cached bcc with email """
        self.test_retrieve_bcc_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, ["*****@*****.**"])
Exemplo n.º 6
0
    def test_retrieve_auth_cached_invalidation_parent_cached(self):
        self.test_retrieve_auth_cached_invalidation_parent()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.auth_credentials), 6)
            self.assertEquals(template.auth_credentials['port'], 587)
    def test_retrieve_auth_cached_invalidation_parent_cached(self):
        self.test_retrieve_auth_cached_invalidation_parent()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.auth_credentials), 6)
            self.assertEquals(template.auth_credentials['port'], 587)
    def test_retrieve_localized_template_from_cache(self):
        """ create template + localized template, and checks queries """
        self._create_localized_template()

        with self.assertNumQueries(4):
            template = MailTemplate.get_template("welcome", lang="es")
            self.assertEquals(template.subject, "Bienvenido")
            self.assertEquals(template.message,
                              "Bienvenido a nuestro sitio. Nos alegra verte.")

        # ensures 0 queries are made after caching the localized template
        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome", lang="es")
            self.assertEquals(template.subject, "Bienvenido")
            self.assertEquals(template.message,
                              "Bienvenido a nuestro sitio. Nos alegra verte.")
Exemplo n.º 9
0
def send_db_mail(slug, recipient, *args, **kwargs):
    from dbmail.defaults import CELERY_QUEUE, SEND_MAX_TIME, ENABLE_CELERY
    from dbmail.models import MailTemplate
    from dbmail.send_mail import SendMail

    args = (slug, recipient) + args
    send_after = kwargs.pop('send_after', None)
    send_at_date = kwargs.pop('send_at_date', None)
    _use_celery = kwargs.pop('use_celery', ENABLE_CELERY)
    use_celery = ENABLE_CELERY and _use_celery

    if celery_supported() and use_celery is True:
        import tasks

        template = MailTemplate.get_template(slug=slug)
        max_retries = kwargs.get('max_retries', None)
        send_after = send_after if send_after else template.interval
        if max_retries is None and template.num_of_retries:
            kwargs['max_retries'] = template.num_of_retries

        options = {
            'args': args, 'kwargs': kwargs,
            'queue': kwargs.pop('queue', CELERY_QUEUE),
            'time_limit': kwargs.get('time_limit', SEND_MAX_TIME),
            'priority': template.priority,
        }

        if send_at_date is not None and isinstance(send_at_date, datetime):
            options.update({'eta': send_at_date})
        if send_after is not None:
            options.update({'countdown': send_after})
        if template.is_active:
            return tasks.send_db_mail.apply_async(**options)
    else:
        return SendMail(*args, **kwargs).send(is_celery=False)
    def test_retrieve_bcc_cached_invalidation_cache(self):
        """ check cached bcc with email """
        self.test_retrieve_bcc_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, ["*****@*****.**"])
Exemplo n.º 11
0
    def test_retrieve_from_cached_invalidation_cache(self):
        """ check cached from with email """
        self.test_retrieve_from_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(
                template.from_email.get_mail_from, "root <*****@*****.**>")
    def test_retrieve_from_cached_invalidation_cache(self):
        """ check cached from with email """
        self.test_retrieve_from_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.from_email.get_mail_from,
                              "root <*****@*****.**>")
Exemplo n.º 13
0
    def test_retrieve_auth_cached_invalidation(self):
        self.test_retrieve_auth_cached()

        credentials = MailFromEmailCredential.objects.create(
            host="localhost", port=25, id=1)
        credentials.save()

        mail_from = MailFromEmail.objects.create(
            name="root", email="*****@*****.**", credential=credentials)

        template = MailTemplate.get_template("welcome")
        template.from_email = mail_from
        template.save()

        with self.assertNumQueries(4):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.auth_credentials), 6)
            self.assertEquals(template.auth_credentials['port'], 25)
 def test_base_template_cleans_cache_after_saving(self):
     self._create_template_with_base()
     # calling get_template will cache this template with his base
     template = MailTemplate.get_template("welcome_with_base")
     self.assertTrue(template.slug in cache)
     # calling .save() on the base template should clear the cache
     template.base.message = "Different message"
     template.base.save()
     self.assertFalse(template.slug in cache)
Exemplo n.º 15
0
    def test_retrieve_file_cached_invalidation(self):
        self.test_retrieve_file_cached()

        attachment = MailFile.objects.create(
            template_id=1, name="report.xls", filename="", pk=1)
        attachment.save()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.files_list, [attachment])
    def test_retrieve_auth_cached_delete(self):
        self.test_retrieve_auth_cached_invalidation_parent_cached()

        credentials = MailFromEmailCredential.objects.get(pk=1)
        credentials.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.auth_credentials, None)
            self.assertEquals(template.from_email, None)
Exemplo n.º 17
0
    def test_retrieve_auth_cached_delete(self):
        self.test_retrieve_auth_cached_invalidation_parent_cached()

        credentials = MailFromEmailCredential.objects.get(pk=1)
        credentials.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.auth_credentials, None)
            self.assertEquals(template.from_email, None)
    def test_retrieve_file_delete(self):
        self.test_retrieve_file_cached_invalidation_cache()

        attachment = MailFile.objects.get(pk=1)
        attachment.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.files_list, [])

        self._retrieve_named_template_and_check_num_queries(0)
    def test_retrieve_auth_cached_invalidation_parent(self):
        self.test_retrieve_auth_cached_invalidation_cache()

        credentials = MailFromEmailCredential.objects.get(pk=1)
        credentials.port = 587
        credentials.save()

        with self.assertNumQueries(4):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.auth_credentials), 6)
            self.assertEquals(template.auth_credentials['port'], 587)
Exemplo n.º 20
0
    def test_retrieve_auth_cached_invalidation_parent(self):
        self.test_retrieve_auth_cached_invalidation_cache()

        credentials = MailFromEmailCredential.objects.get(pk=1)
        credentials.port = 587
        credentials.save()

        with self.assertNumQueries(4):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.auth_credentials), 6)
            self.assertEquals(template.auth_credentials['port'], 587)
Exemplo n.º 21
0
    def test_retrieve_file_delete(self):
        self.test_retrieve_file_cached_invalidation_cache()

        attachment = MailFile.objects.get(pk=1)
        attachment.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.files_list, [])

        self.__retrieve_named_template_and_check_num_queries(0)
Exemplo n.º 22
0
    def test_retrieve_named_template_with_cache_invalidation(self):
        """ invalidate cached template """
        self.test_retrieve_named_template_cached()

        template = MailTemplate.get_template("welcome")
        self.assertEquals(template.subject, "Welcome")

        template.subject = "Hello"
        template.save()

        self.__retrieve_named_template_and_check_num_queries(3)
        self.assertEquals(template.subject, "Hello")
Exemplo n.º 23
0
    def test_retrieve_from_delete(self):
        """ invalidate cached template when object was removed """
        self.test_retrieve_from_cached_invalidation_cache()

        mail_from = MailFromEmail.objects.get(pk=1)
        mail_from.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.from_email, None)

        self.__retrieve_named_template_and_check_num_queries(0)
    def test_retrieve_bcc_delete(self):
        """ invalidate cached template when object was removed """
        self.test_retrieve_bcc_cached_invalidation_cache()

        for bcc in MailBcc.objects.all():
            bcc.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, [])

        self._retrieve_named_template_and_check_num_queries(0)
    def test_retrieve_named_template_with_cache_invalidation(self):
        """ invalidate cached template """
        self.test_retrieve_named_template_cached()

        template = MailTemplate.get_template("welcome")
        self.assertEquals(template.subject, "Welcome")

        template.subject = "Hello"
        template.save()

        self._retrieve_named_template_and_check_num_queries(3)
        self.assertEquals(template.subject, "Hello")
    def test_retrieve_from_delete(self):
        """ invalidate cached template when object was removed """
        self.test_retrieve_from_cached_invalidation_cache()

        mail_from = MailFromEmail.objects.get(pk=1)
        mail_from.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.from_email, None)

        self._retrieve_named_template_and_check_num_queries(0)
Exemplo n.º 27
0
    def test_retrieve_bcc_delete(self):
        """ invalidate cached template when object was removed """
        self.test_retrieve_bcc_cached_invalidation_cache()

        for bcc in MailBcc.objects.all():
            bcc.delete()

        with self.assertNumQueries(3):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(template.bcc_list, [])

        self.__retrieve_named_template_and_check_num_queries(0)
 def test_mail_template_cleans_localized_template_from_cache_after_saving(
         self):
     self._create_localized_template()
     # calling get_template should cache the localized template ONLY
     localized_template = MailTemplate.get_template("welcome", lang="es")
     localized_cache_key = '{}-{}'.format(localized_template.slug, "es")
     self.assertTrue(localized_cache_key in cache)
     self.assertFalse(localized_template.slug in cache)
     # calling localized_template.save() should clear the cache
     localized_template.subject = "Change"
     localized_template.save()
     self.assertFalse(localized_cache_key in cache)
     self.assertFalse(localized_template.slug in cache)
Exemplo n.º 29
0
def db_sender(slug, recipient, *args, **kwargs):
    try:
        from django.utils.importlib import import_module
    except ImportError:
        from importlib import import_module

    from dbmail.defaults import (
        CELERY_QUEUE, SEND_MAX_TIME, ENABLE_CELERY, BACKEND, DEBUG)
    from dbmail.models import MailTemplate

    args = (slug, recipient) + args
    send_after = kwargs.pop('send_after', None)
    send_at_date = kwargs.pop('send_at_date', None)
    _use_celery = kwargs.pop('use_celery', ENABLE_CELERY)
    use_celery = ENABLE_CELERY and _use_celery
    backend = kwargs.get('backend', BACKEND['mail'])

    if celery_supported() and use_celery is True:
        import tasks

        template = MailTemplate.get_template(slug=slug)
        max_retries = kwargs.get('max_retries', None)
        send_after = send_after if send_after else template.interval
        if max_retries is None and template.num_of_retries:
            kwargs['max_retries'] = template.num_of_retries

        options = {
            'args': args, 'kwargs': kwargs,
            'queue': kwargs.pop('queue', CELERY_QUEUE),
            'time_limit': kwargs.get('time_limit', SEND_MAX_TIME),
            'priority': template.priority,
        }

        if send_at_date is not None and isinstance(send_at_date, datetime):
            options.update({'eta': send_at_date})
        if send_after is not None:
            options.update({'countdown': send_after})
        if template.is_active:
            return tasks.db_sender.apply_async(**options)
    else:
        module = import_module(backend)
        if DEBUG is True:
            return module.SenderDebug(*args, **kwargs).send(is_celery=False)
        return module.Sender(*args, **kwargs).send(is_celery=False)
Exemplo n.º 30
0
def db_sender(slug, recipient, *args, **kwargs):
    from django.utils.importlib import import_module
    from dbmail.defaults import (
        CELERY_QUEUE, SEND_MAX_TIME, ENABLE_CELERY, BACKEND, DEBUG)
    from dbmail.models import MailTemplate

    args = (slug, recipient) + args
    send_after = kwargs.pop('send_after', None)
    send_at_date = kwargs.pop('send_at_date', None)
    _use_celery = kwargs.pop('use_celery', ENABLE_CELERY)
    use_celery = ENABLE_CELERY and _use_celery
    backend = kwargs.get('backend', BACKEND['mail'])

    if celery_supported() and use_celery is True:
        import tasks

        template = MailTemplate.get_template(slug=slug)
        max_retries = kwargs.get('max_retries', None)
        send_after = send_after if send_after else template.interval
        if max_retries is None and template.num_of_retries:
            kwargs['max_retries'] = template.num_of_retries

        options = {
            'args': args, 'kwargs': kwargs,
            'queue': kwargs.pop('queue', CELERY_QUEUE),
            'time_limit': kwargs.get('time_limit', SEND_MAX_TIME),
            'priority': template.priority,
        }

        if send_at_date is not None and isinstance(send_at_date, datetime):
            options.update({'eta': send_at_date})
        if send_after is not None:
            options.update({'countdown': send_after})
        if template.is_active:
            return tasks.db_sender.apply_async(**options)
    else:
        module = import_module(backend)
        if DEBUG is True:
            return module.SenderDebug(*args, **kwargs).send(is_celery=False)
        return module.Sender(*args, **kwargs).send(is_celery=False)
def db_sender(slug, recipient, *args, **kwargs):
    from dbmail.defaults import (CELERY_QUEUE, SEND_MAX_TIME, ENABLE_CELERY,
                                 BACKEND, DEBUG)
    from dbmail.models import MailTemplate

    args = (slug, recipient) + args
    send_after = kwargs.pop('send_after', None)
    expiry = kwargs.pop('expiry', None)
    send_at_date = kwargs.pop('send_at_date', None)
    _use_celery = kwargs.pop('use_celery', ENABLE_CELERY)
    use_celery = ENABLE_CELERY and _use_celery
    backend = kwargs.get('backend', BACKEND['mail'])

    if celery_supported() and use_celery is True:
        import dbmail.tasks

        template = MailTemplate.get_template(slug=slug)
        max_retries = kwargs.get('max_retries', None)
        send_after = send_after if send_after else template.interval
        expiry = expiry if expiry else template.expiry
        if max_retries is None and template.num_of_retries:
            kwargs['max_retries'] = template.num_of_retries

        kwargs['time_limit'] = kwargs.get('time_limit', SEND_MAX_TIME),

        if send_at_date is not None and isinstance(send_at_date, datetime):
            kwargs.update({'eta': send_at_date})
        if expiry is not None:
            kwargs.update({'expires': expiry})
        if template.is_active:
            return dbmail.tasks.db_sender.apply_async(args,
                                                      kwargs,
                                                      countdown=send_after)
    else:
        module = import_module(backend)
        if DEBUG is True:
            return module.SenderDebug(*args, **kwargs).send(is_celery=False)
        return module.Sender(*args, **kwargs).send(is_celery=False)
Exemplo n.º 32
0
def send_db_mail(slug, recipient, *args, **kwargs):
    from dbmail.defaults import CELERY_QUEUE, SEND_MAX_TIME, ENABLE_CELERY
    from dbmail.models import MailTemplate
    from dbmail.send_mail import SendMail

    args = (slug, recipient) + args
    send_after = kwargs.pop('send_after', None)
    send_at_date = kwargs.pop('send_at_date', None)
    _use_celery = kwargs.pop('use_celery', ENABLE_CELERY)
    use_celery = ENABLE_CELERY and _use_celery

    if celery_supported() and use_celery is True:
        import tasks

        template = MailTemplate.get_template(slug=slug)
        max_retries = kwargs.get('max_retries', None)
        send_after = send_after if send_after else template.interval
        if max_retries is None and template.num_of_retries:
            kwargs['max_retries'] = template.num_of_retries

        options = {
            'args': args,
            'kwargs': kwargs,
            'queue': kwargs.pop('queue', CELERY_QUEUE),
            'time_limit': kwargs.get('time_limit', SEND_MAX_TIME),
            'priority': template.priority,
        }

        if send_at_date is not None and isinstance(send_at_date, datetime):
            options.update({'eta': send_at_date})
        if send_after is not None:
            options.update({'countdown': send_after})
        if template.is_active:
            return tasks.send_db_mail.apply_async(**options)
    else:
        return SendMail(*args, **kwargs).send(is_celery=False)
Exemplo n.º 33
0
 def clean_cache_view(self, request):
     MailTemplate.clean_cache()
     ApiKey.clean_cache()
     messages.success(request, _('Cache was successful removed'))
     return redirect('admin:dbmail_mailtemplate_changelist')
Exemplo n.º 34
0
 def clean_cache_view(self, request):
     MailTemplate.clean_cache()
     ApiKey.clean_cache()
     messages.success(request, _('Cache was successful removed'))
     return redirect('admin:dbmail_mailtemplate_changelist')
Exemplo n.º 35
0
    def handle(self, **options):
        base_template, _ = MailBaseTemplate.objects.update_or_create(
            name="Main",
            defaults={
                'message': """
                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                <body>
                {{ content }}
                
                    
                <p>The {{ site_name }} team</p>
                </body>
                </html>
                """
            }
        )

        # Destination: account managers
        MailTemplate.objects.update_or_create(
            slug='resident_profile_filled',
            defaults={
                'name': 'Resident profile filled',
                'subject': 'New resident {{ resident.full_name }} filled profile',
                'message': """
                <p>
                    Hello!
                </p>
                <p></p>
                <p>
                    {{ resident.full_name }} is waiting for approving. Please review his profile
                and approve or reject him.
                </p>
                <p></p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/account-manager/detail/{{ resident.pk }}/">
                        Review resident on the site
                    </a>
                </p>
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='resident_approved',
            defaults={
                'name': 'Resident approved',
                'subject': 'You are approved',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    You are successfully approved and now you can apply for a shifts.
                </p>
                <p></p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/schedule/">
                        Go to the schedule
                    </a>
                </p>
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='resident_rejected',
            defaults={
                'name': 'Resident rejected',
                'subject': 'You are rejected',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    You are rejected to be an approved resident. You can update your profile and our staff will consider your profile again. 
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/profile/">
                        Update profile
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='shift_created',
            defaults={
                'name': 'Shift created',
                'subject': 'A new suitable shift for you',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    There is a new suitable shift for you was created right now.
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/">
                        Open the shift
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='shift_updated',
            defaults={
                'name': 'Shift updated',
                'subject': 'A shift was updated',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    {% if is_applicant %}
                    The shift you applied for was changed.
                    {% else %}
                    Suitable shift for you was changed.
                    {% endif %}
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/">
                        Open the shift
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='shift_deleted',
            defaults={
                'name': 'Shift deleted',
                'subject': 'A shift was deleted',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                The shift for {{ shift.facility_name }} at {{ shift.department_name }} which will start at {{ shift.date_start }} was deleted.    
                """,
                'base': base_template,
            }
        )

        # Destination: resident or scheduler
        MailTemplate.objects.update_or_create(
            slug='message_created',
            defaults={
                'name': 'Message created',
                'subject': 'You received new message from {{ source.full_name }}',
                'message': """
                <p>
                    Hello {{ destination.full_name }}!
                </p>
                <p></p>
                <p>
                    You received new message from {{ source.full_name }}:<br />
                    {{ comment }}
                </p>
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/{{ destination.role }}/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: scheduler
        MailTemplate.objects.update_or_create(
            slug='application_created',
            defaults={
                'name': 'Application created',
                'subject': 'New application from {{ resident.full_name }}',
                'message': """
                <p>
                    Hello {{ scheduler.full_name }}!
                </p>
                <p></p>
                <p>
                    {{ resident.full_name }} applied for the shift:
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/scheduler/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Review application
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='invitation_created',
            defaults={
                'name': 'Invitation created',
                'subject': 'You are invited to the shift',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    You are invite to the shift:
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/scheduler/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Review application
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='application_approved',
            defaults={
                'name': 'Application approved',
                'subject': 'Your application was approved',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    Your application was approved! Please confirm your participation. <br />
                    {{ comment }} 
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='application_rejected',
            defaults={
                'name': 'Application rejected',
                'subject': 'Your application was rejected',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    Your application was rejected. <br />
                    {{ comment }} 
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='application_postponed',
            defaults={
                'name': 'Application postponed',
                'subject': 'Your application was postponed',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    Your application was postponed because an another application was approved.
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='application_renewed',
            defaults={
                'name': 'Application renewed',
                'subject': 'Your application was renewed',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    Your application was renewed because an another application was cancelled.
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident
        MailTemplate.objects.update_or_create(
            slug='application_completed',
            defaults={
                'name': 'Application completed',
                'subject': 'Your application was completed',
                'message': """
                <p>
                    Hello {{ resident.full_name }}!
                </p>
                <p></p>
                <p>
                    Your application was completed.<br />
                    {{ comment }}
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: scheduler
        MailTemplate.objects.update_or_create(
            slug='application_confirmed',
            defaults={
                'name': 'Application confirmed',
                'subject': 'The resident {{ resident.full_name }} confirmed the application',
                'message': """
                <p>
                    Hello {{ scheduler.full_name }}!
                </p>
                <p></p>
                <p>
                    {{ resident.full_name }} confirmed the application.<br />
                    {{ comment }}
                </p>
                
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/resident/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        # Destination: resident or scheduler
        MailTemplate.objects.update_or_create(
            slug='application_cancelled',
            defaults={
                'name': 'Application cancelled',
                'subject': 'Application cancelled',
                'message': """
                <p>
                    Hello {{ destination.full_name }}!
                </p>
                <p></p>
                <p>
                    The application was cancelled.<br />
                    {{ comment }}
                </p>
                <p>
                    <b>Shift details:</b>
                </p>
                <p>
                    <b>Location:</b> {{ shift.facility_name }} at {{ shift.department_name }}<br />
                    <b>Starts:</b> {{ shift.date_start }} <br />
                    <b>Ends:</b> {{ shift.date_end }} <br />
                    <b>Payment amount:</b> {{ shift.payment_amount }} {% if shift.payment_per_hour %}per hour{% endif %}<br />
                    {{ shift.description }}
                </p>
                <p>
                    <a href="{{ protocol }}://{{ domain }}/#/{{ destination.role }}/messages/{{ shift.pk }}/discuss/{{ application.pk }}/">
                        Open dialog
                    </a>
                </p>               
                """,
                'base': base_template,
            }
        )

        MailTemplate.clean_cache()
Exemplo n.º 36
0
 def handle(self, *args, **options):
     MailTemplate.clean_cache()
     ApiKey.clean_cache()
def clean_cache(apps, schema_editor):
    from dbmail.models import MailTemplate, ApiKey

    MailTemplate.clean_cache()
    ApiKey.clean_cache()
Exemplo n.º 38
0
    def test_retrieve_file_cached_invalidation_cache(self):
        self.test_retrieve_file_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.files_list), 1)
Exemplo n.º 39
0
 def _get_template(self):
     return MailTemplate.get_template(slug=self._slug)
Exemplo n.º 40
0
 def __retrieve_named_template_and_check_num_queries(self, num):
     with self.assertNumQueries(num):
         template = MailTemplate.get_template("welcome")
         self.assertEqual(template.pk, 1)
         return template
    def test_retrieve_file_cached_invalidation_cache(self):
        self.test_retrieve_file_cached_invalidation()

        with self.assertNumQueries(0):
            template = MailTemplate.get_template("welcome")
            self.assertEquals(len(template.files_list), 1)
Exemplo n.º 42
0
 def _get_template(self):
     return MailTemplate.get_template(slug=self._slug)
Exemplo n.º 43
0
 def _get_template(self, lang=None):
     return MailTemplate.get_template(slug=self._slug, lang=lang)
Exemplo n.º 44
0
 def handle(self, *args, **options):
     for obj in MailTemplate.objects.all():
         MailTemplate.clean_cache()
         MailTemplate.get_template(obj.slug)