LPgenerator / django-db-mailer

Django module to easily send emails/sms/tts/push using django templates stored on database and managed through the Django Admin
https://github.com/LPgenerator/django-db-mailer
GNU General Public License v2.0
256 stars 80 forks source link

Image tag in CK-editor convert template tags from {{ image_url }} to %7B%7B%20image_url%20%7D%7D #34

Closed waqasraz closed 8 years ago

waqasraz commented 8 years ago

When using Ck-editor if you define a template tage for image_url as <img src={{ imageurl }} Ck editor encode them to %7B%7B%20image_url%20%7D%7D and is not recognized by db-mailer while sending email. Any solution for this?

waqasraz commented 8 years ago

Also if i try to add image ta li

send_db_mail( 'customer', '', { 'image': u"< src=link />" }, use_celery=False, )

i get escape sting &lt img src=link &gt

gotlium commented 8 years ago
  1. I think we can replace this characters on save method.
  2. We are using RichTextField from ckeditor.fields, you can redefine default field.
  3. Possible Ck-editor have a settings to do this?
  4. When you are trying to send, backend do not escape any characters. Check dbmail/backends/mail.py. For html messages we are using clean_html for text part https://github.com/LPgenerator/django-db-mailer/blob/development/dbmail/backends/mail.py#L163
gotlium commented 8 years ago

On my tests all is working properly on master branch.

waqasraz commented 8 years ago

After few days of lookup i realize the problem was with premailer. If i don't have premailer install everything work fine.

gotlium commented 8 years ago

:)

night-crawler commented 8 years ago

Anyway sometimes I have a need to put some urls in my template, i.e. <a href="{{sites.main.url}}">{{sites.main.name}}</a> and premailer breaks a template var repr to %7b%7bsites.main.url%7d%7d

The stupid fast hack looks like:

# -*- coding: utf-8 -*-
from django.db.models.signals import pre_save
from django.dispatch import receiver
from dbmail.models import MailTemplate

@receiver(pre_save, sender=MailTemplate, dispatch_uid='mailtemplate_pre_save')
def mailtemplate_pre_save(sender, instance: MailTemplate, **kwargs):
    instance.message = instance.message.replace('%7B%7B', '{{')
    instance.message = instance.message.replace('%7b%7b', '{{')
    instance.message = instance.message.replace('%7D%7D', '}}')
    instance.message = instance.message.replace('%7d%7d', '}}')

But imho the the right way looks like addition message {pre,post}processor pipeline support.

gotlium commented 8 years ago

that a premailer problems. not a dbmail.