當前位置: 首頁>>代碼示例>>Python>>正文


Python premailer.transform方法代碼示例

本文整理匯總了Python中premailer.transform方法的典型用法代碼示例。如果您正苦於以下問題:Python premailer.transform方法的具體用法?Python premailer.transform怎麽用?Python premailer.transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在premailer的用法示例。


在下文中一共展示了premailer.transform方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: send_verification_email

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def send_verification_email(user):
    """Send verification email to user
    """
    # create email verification request
    r = EmailVerificationRequest(key=os.urandom(32).hex(), user=user)
    db.session.add(r)
    db.session.flush()

    # send email
    subject = 'Flaskapp Account: Please Confirm Email'
    msg = Message(subject, recipients=[user.email])
    verify_url = url_for('.verify_email', key=r.key, email=user.email, \
                             _external=True)

    f = '/auth/verify-email-email'
    msg.body = render_template(f + '.txt', verify_url=verify_url)

    html = render_template(f + '.html', verify_url=verify_url)
    base_url = url_for('content.home', _external=True)
    msg.html = transform(html, base_url=base_url)
    mail.send(msg) 
開發者ID:muicss,項目名稱:flaskapp,代碼行數:23,代碼來源:auth.py

示例2: message

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def message(self, sender, to, subject, message, html_message):
        """Prepare an message
        """
        if not isinstance(to, (list, tuple)):
            to = [to]
        if html_message:
            if not message and bs:
                body = bs(html_message, 'html.parser').find('body')
                if body:
                    message = body.get_text().strip()
            html_message = transform(html_message)

        msg = EmailMultiAlternatives(subject, message, sender, to,
                                     encoding=self.app.config['ENCODING'])
        if html_message:
            msg.attach_alternative(html_message, 'text/html')
        return msg 
開發者ID:quantmind,項目名稱:lux,代碼行數:19,代碼來源:backend.py

示例3: md2html

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def md2html(text, styles=None, poster='', banner='', convert_list=True, ul_style='\u25CB'):
    md = Markdown()

    # 將markdown列表轉化為帶序號的普通段落(純為適應微信中列表序號樣式自動丟失的古怪現象)
    if convert_list:
        blocks = text.split('\n```')
        for i in range(0, len(blocks)):
            if i % 2 == 0:
                blocks[i] = re.sub(r'(\n\d+)(\.\s.*?)', r'\n\1\\\2', blocks[i])
                blocks[i] = re.sub(r'\n[\-\+\*](\s.*?)',
                                   u'\n\n{} \1'.format(ul_style), blocks[i])
            else:
                continue  # 跳過代碼塊內部內容
        text = '\n```'.join(blocks)

    inner_html = md(text)
    result = premailer.transform(pack_html(inner_html, styles, poster, banner))
    return result 
開發者ID:insula1701,項目名稱:maxpress,代碼行數:20,代碼來源:maxpress.py

示例4: sendUpsellEmail

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def sendUpsellEmail(data):
        name = Utils.getUserName(data['user'])
        with webapp.app_context():
            consumer_mail = render_template('mailers/extend_order.html',
                            name = name,
                            book_name = data['book_name'],
                            order_id = data['order_id'],
                            items = data['items'], 
                            curated_items = data['curated_items'],
                            quote = data['quote'], 
                            quote_author = data['quote_author'])
            pre = Premailer(consumer_mail, remove_classes=False, strip_important=False)
            consumer_mail =  pre.transform()
            email = Message('Enjoying the book?',
                            recipients=[data['user'].email])
            email.html = consumer_mail
            mail.send(email)
        return True 
開發者ID:anantzoid,項目名稱:Ostrich,代碼行數:20,代碼來源:mailer.py

示例5: forgot

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def forgot():
    """GET|POST /forgot: forgot password form handler
    """
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        # get user
        u = User.query.filter_by(email=form.email.data).one()

        # create reset password
        # Todo: delete all previous entries
        r = PasswordResetRequest(key=os.urandom(32).hex(), user=u)

        # save to db
        db.session.add(r)
        db.session.flush()

        # generate email
        msg = Message('Password Reset Request',
                      recipients=[u.email])
        reset_url = url_for('auth.reset_password', key=r.key, email=u.email, \
                                _external=True)

        # txt
        msg.body = render_template('/auth/reset-password-email.txt',
                                   reset_url=reset_url)

        # html
        html = render_template('/auth/reset-password-email.html',
                               reset_url=reset_url)
        msg.html = transform(html,
                             base_url=url_for('content.home', _external=True))

        # send email
        mail.send(msg)

        return render_template('/auth/forgot-followup.html',
                               email=u.email)

    return render_template('/auth/forgot.html', form=form) 
開發者ID:muicss,項目名稱:flaskapp,代碼行數:41,代碼來源:auth.py

示例6: get_body_html

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def get_body_html(self):
        html = ""
        if self.body_html:
            html = transform(self.render_text_template(self.body_html))
        elif self.body_html_template:
            html = transform(self.render_template(self.body_html_template))
        return html 
開發者ID:scrapinghub,項目名稱:spidermon,代碼行數:9,代碼來源:__init__.py

示例7: send_email

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def send_email(
    to_email, context, subject, plain_template, html_template, from_email=None
):
    """
    Render a plain and html message based on a context and send it using django.core.mail.
    """

    plain_body = render_to_string(plain_template, context)

    html_body = None
    if html_template:
        html_body = render_to_string(html_template, context)

    recipient_list = to_email if isinstance(to_email, list) else [to_email]

    log.info(
        "send_mail",
        subject=subject,
        from_email=from_email,
        recipient_list=recipient_list,
    )

    django_send_mail(
        subject=subject,
        message=plain_body,
        from_email=from_email,
        recipient_list=recipient_list,
        html_message=transform(html_body),
        fail_silently=False,
    ) 
開發者ID:webkom,項目名稱:lego,代碼行數:32,代碼來源:email.py

示例8: premailer_transform

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def premailer_transform(text):
    try:
        from premailer import transform

        return transform(text)
    except ImportError:
        logger.error("You don't have module 'premailer' installed")
        return text
    except Exception as err:
        logger.error(err)
        return text 
開發者ID:LPgenerator,項目名稱:django-db-mailer,代碼行數:13,代碼來源:utils.py

示例9: transform

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def transform(html_message, base_url=None):
        return html_message 
開發者ID:quantmind,項目名稱:lux,代碼行數:4,代碼來源:backend.py

示例10: send_notification

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def send_notification(user, commtype_code, context, site, recipient=None):
    """Send different notification mail to the user based on the triggering event.

    Args:
    user(obj): 'User' object to whom email is to send
    commtype_code(str): Communication type code
    context(dict): context to be used in the mail
    recipient(str): Email which overrides user.email when set

    """

    tracking_id, client_id, ip = parse_tracking_context(user, usage='notification')

    tracking_pixel = 'https://www.google-analytics.com/collect?v=1&t=event&ec=email&ea=open&tid={tracking_id}' \
                     '&cid={client_id}&uip={ip}'.format(tracking_id=tracking_id, client_id=client_id, ip=ip)
    full_name = user.get_full_name()
    context.update({
        'full_name': full_name,
        'site_domain': site.domain,
        'platform_name': site.name,
        'tracking_pixel': tracking_pixel,
    })

    try:
        event_type = CommunicationEventType.objects.get(code=commtype_code)
    except CommunicationEventType.DoesNotExist:
        try:
            messages = CommunicationEventType.objects.get_and_render(commtype_code, context)
        except Exception:  # pylint: disable=broad-except
            log.error('Unable to locate a DB entry or templates for communication type [%s]. '
                      'No notification has been sent.', commtype_code)
            return
    else:
        messages = event_type.get_messages(context)

    if messages and (messages['body'] or messages['html']):
        messages['html'] = transform(messages['html'])
        Dispatcher().dispatch_user_messages(user, messages, site, recipient) 
開發者ID:edx,項目名稱:ecommerce,代碼行數:40,代碼來源:notifications.py

示例11: generate_content

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def generate_content(
    md_content: str, theme: Optional[str] = None, context: Optional[dict] = None
):
    """
    Generates the content of an email to be sent. This method actually renders two templates:
    1. The extremely simple local template, which writes the stylesheet, header and user-provided md_content to the
    message
    2.  The result of 1. is also treated as a jinja template, and rendered using the arguments provided in the context
    parameter

    Apart from rendering the template, this method also does two other things:
    1. Applies an additional highlight renderer with better support for code blocks
    2. Uses premailer.transform to bake the css into the HTML
    """
    if not theme:
        theme = os.path.join(os.path.dirname(os.path.abspath(__file__)), "style.css")

    if not context:
        context = {}

    with open(theme) as f:
        theme = f.read()

    markdown = mistune.Markdown(renderer=HighlightRenderer())

    with open(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), "template.jinja2")
    ) as t:
        template = jinja2.Template(t.read())
    content = premailer.transform(
        template.render(content=markdown(md_content), stylesheet=theme)
    )

    new_template = jinja2.Template(content)
    return new_template.render(context)


#
# with open('test.md') as r:
#     with open('test.html', 'w') as f:
#         f.write(generate_content(r.read(), theme='my-style.css', context=dict(things=['Thing 1', 'Thing 2']))) 
開發者ID:chris104957,項目名稱:maildown,代碼行數:43,代碼來源:renderer.py

示例12: welcomeMailer

# 需要導入模塊: import premailer [as 別名]
# 或者: from premailer import transform [as 別名]
def welcomeMailer(user):
        name = Utils.getUserName(user)
        with webapp.app_context():
            email = Message('Welcome to Ostrich!',
                        recipients=[user.email])
            email.html = transform(render_template('mailers/welcome.html', name=name))
            mail.send(email)
        return True 
開發者ID:anantzoid,項目名稱:Ostrich,代碼行數:10,代碼來源:mailer.py


注:本文中的premailer.transform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。