本文整理汇总了Python中django.utils.html.strip_tags方法的典型用法代码示例。如果您正苦于以下问题:Python html.strip_tags方法的具体用法?Python html.strip_tags怎么用?Python html.strip_tags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.html
的用法示例。
在下文中一共展示了html.strip_tags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify_mobile_survey_start
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def notify_mobile_survey_start(self, request, mobile_survey):
admin_email = settings.ADMINS[0][1] if settings.ADMINS else ""
email_context = {
"button_text": _("Logon to {app_name}".format(app_name=settings.APP_NAME)),
"link": request.build_absolute_uri(reverse("home")),
"greeting": _(
"Welcome to Arches! You've just been added to a Mobile Survey. \
Please take a moment to review the mobile_survey description and mobile_survey start and end dates."
),
"closing": _(f"If you have any qustions contact the site administrator at {admin_email}."),
}
html_content = render_to_string("email/general_notification.htm", email_context)
text_content = strip_tags(html_content) # this strips the html, so people will have the text as well.
# create the email, and attach the HTML version as well.
for user in self.get_mobile_survey_users(mobile_survey):
msg = EmailMultiAlternatives(
_("You've been invited to an {app_name} Survey!".format(app_name=settings.APP_NAME)),
text_content,
admin_email,
[user.email],
)
msg.attach_alternative(html_content, "text/html")
msg.send()
示例2: league_document
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def league_document(request):
try:
league_tag = request.GET.get('league', None)
type_ = request.GET.get('type', None)
strip_html = request.GET.get('strip_html', None) == 'true'
except ValueError:
return HttpResponse('Bad request', status=400)
if not league_tag or not type_:
return HttpResponse('Bad request', status=400)
league_doc = LeagueDocument.objects.filter(league__tag=league_tag, type=type_).first()
if league_doc is None:
return JsonResponse({'name': None, 'content': None, 'error': 'not_found'})
document = league_doc.document
content = document.content
if strip_html:
content = strip_tags(content)
return JsonResponse({
'name': document.name,
'content': content
})
示例3: blog_tags
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def blog_tags():
all_blog_entry = Entry.objects.published()[:5]
all_blog_entry = [ [p.title, p.slug, p.tags, p.body, p.created ] for p in all_blog_entry ]
out = []
for item in all_blog_entry:
title = str(item[0])
slug = str(item[1])
tags = item[2].all()
tmp_tags_slug = ''
for tag in tags:
tmp_tags_slug += str(tag.slug)
def smart_truncate_chars(value, max_length):
if len(value) > max_length:
truncd_val = value[:max_length]
if value[max_length] != ' ':
truncd_val = truncd_val[:truncd_val.rfind(' ')]
return truncd_val + '...'
return value
body = smart_truncate_chars(str(item[3].encode('utf-8')), 20) #str(item[3])
created = str(item[4])
out.append('%s %s %s %s %s' % (title, slug, tmp_tags_slug, strip_tags(body), created))
return ''.join(out)
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:26,代码来源:Template Tag for Truncating Characters.py
示例4: _build_message
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def _build_message(self, to, text, subject=None, mtype=None, unsubscribe_url=None):
"""Constructs a MIME message from message and dispatch models."""
# TODO Maybe file attachments handling through `files` message_model context var.
if subject is None:
subject = '%s' % _('No Subject')
if mtype == 'html':
msg = self.mime_multipart()
text_part = self.mime_multipart('alternative')
text_part.attach(self.mime_text(strip_tags(text), _charset='utf-8'))
text_part.attach(self.mime_text(text, 'html', _charset='utf-8'))
msg.attach(text_part)
else:
msg = self.mime_text(text, _charset='utf-8')
msg['From'] = self.from_email
msg['To'] = to
msg['Subject'] = subject
if unsubscribe_url:
msg['List-Unsubscribe'] = '<%s>' % unsubscribe_url
return msg
示例5: send_email
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def send_email(to, kind, cc=[], **kwargs):
current_site = Site.objects.get_current()
ctx = {"current_site": current_site, "STATIC_URL": settings.STATIC_URL}
ctx.update(kwargs.get("context", {}))
subject = "[%s] %s" % (
current_site.name,
render_to_string(
"symposion/emails/%s/subject.txt" % kind, ctx
).strip(),
)
message_html = render_to_string(
"symposion/emails/%s/message.html" % kind, ctx
)
message_plaintext = strip_tags(message_html)
from_email = settings.DEFAULT_FROM_EMAIL
email = EmailMultiAlternatives(
subject, message_plaintext, from_email, to, cc=cc
)
email.attach_alternative(message_html, "text/html")
email.send()
示例6: mutate
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def mutate(self, info, email):
user = User.objects.get(email=email)
if user is not None:
newPassword = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(10))
user.set_password(newPassword)
user.save()
context = {
"password": newPassword,
"username": user.username
}
message = render_to_string('email/password_reset_email.html', context)
send_mail('Reset Password | amFOSS CMS', strip_tags(message), from_email, [email], fail_silently=False,
html_message=message)
return userStatusObj(status=True)
else:
raise APIException('Email is not registered',
code='WRONG_EMAIL')
示例7: send
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def send(self):
"""Sends the payment email along with the invoice."""
body = self.get_body()
# Set non-empty body according to
# http://stackoverflow.com/questions/14580176/confusion-with-sending-email-in-django
mail = EmailMultiAlternatives(
subject=self.get_subject(),
body=strip_tags(body),
to=self.get_recipient_list(),
cc=self.get_cc_list(),
bcc=self.get_bcc_list(),
)
mail.attach_alternative(body, "text/html")
for attachment in self.attachments:
mail.attach_file(attachment[0], attachment[1])
return mail.send()
示例8: test_post_render_static_polls
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def test_post_render_static_polls(self):
"""
Should render the static polls
"""
comment_html = post_render_static_polls(self.comment)
self.assertTrue('my poll' in comment_html)
comment_parts = [
l.strip()
for l in strip_tags(comment_html).splitlines()
if l.strip()
]
self.assertEqual(comment_parts, [
'my poll',
'#1 choice 1',
'#2 choice 2',
'Name: foo, choice selection: from 1 up to 1, mode: default'
])
示例9: get_snippet
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def get_snippet(self, solr_rec):
""" get a text highlighting snippet """
if isinstance(self.highlighting, dict):
if self.uuid is False:
if 'uuid' in solr_rec:
self.uuid = solr_rec['uuid']
if self.uuid in self.highlighting:
if 'text' in self.highlighting[self.uuid]:
text_list = self.highlighting[self.uuid]['text']
self.snippet = ' '.join(text_list)
# some processing to remove fagments of HTML markup.
self.snippet = self.snippet.replace('<em>', '[[[[mark]]]]')
self.snippet = self.snippet.replace('</em>', '[[[[/mark]]]]')
try:
self.snippet = '<div>' + self.snippet + '</div>'
self.snippet = lxml.html.fromstring(self.snippet).text_content()
self.snippet = strip_tags(self.snippet)
except:
self.snippet = strip_tags(self.snippet)
self.snippet = self.snippet.replace('[[[[mark]]]]', '<em>')
self.snippet = self.snippet.replace('[[[[/mark]]]]', '</em>')
示例10: build_approval_email
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def build_approval_email(
application: Application, confirmation_deadline: timezone.datetime
) -> Tuple[str, str, str, None, List[str]]:
"""
Creates a datatuple of (subject, message, html_message, from_email, [to_email]) indicating that a `User`'s
application has been approved.
"""
subject = f"Your {settings.EVENT_NAME} application has been approved!"
context = {
"first_name": application.first_name,
"event_name": settings.EVENT_NAME,
"confirmation_deadline": confirmation_deadline,
}
html_message = render_to_string("application/emails/approved.html", context)
message = strip_tags(html_message)
return subject, message, html_message, None, [application.user.email]
示例11: save
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def save(self, *args, **kwargs):
self.modified_time = timezone.now()
# 首先实例化一个 Markdown 类,用于渲染 body 的文本。
# 由于摘要并不需要生成文章目录,所以去掉了目录拓展。
md = markdown.Markdown(
extensions=["markdown.extensions.extra", "markdown.extensions.codehilite",]
)
# 先将 Markdown 文本渲染成 HTML 文本
# strip_tags 去掉 HTML 文本的全部 HTML 标签
# 从文本摘取前 54 个字符赋给 excerpt
self.excerpt = strip_tags(md.convert(self.body))[:54]
super().save(*args, **kwargs)
# 自定义 get_absolute_url 方法
# 记得从 django.urls 中导入 reverse 函数
示例12: clean_description
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def clean_description(self):
return strip_tags(self.description)
示例13: notify_mobile_survey_end
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def notify_mobile_survey_end(self, request, mobile_survey):
admin_email = settings.ADMINS[0][1] if settings.ADMINS else ""
email_context = {
"button_text": _("Logon to {app_name}".format(app_name=settings.APP_NAME)),
"link": request.build_absolute_uri(reverse("home")),
"greeting": _(
"Hi! The Mobile Survey you were part of has ended or is temporarily suspended. \
Please permform a final sync of your local dataset as soon as possible."
),
"closing": _(f"If you have any qustions contact the site administrator at {admin_email}."),
}
html_content = render_to_string("email/general_notification.htm", email_context)
text_content = strip_tags(html_content) # this strips the html, so people will have the text as well.
# create the email, and attach the HTML version as well.
for user in self.get_mobile_survey_users(mobile_survey):
msg = EmailMultiAlternatives(
_("There's been a change to an {app_name} Survey that you're part of!".format(app_name=settings.APP_NAME)),
text_content,
admin_email,
[user.email],
)
msg.attach_alternative(html_content, "text/html")
msg.send()
# @method_decorator(can_read_resource_instance(), name='dispatch')
示例14: markdown
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def markdown(value):
"""
Render text as Markdown.
"""
# Strip HTML tags and render Markdown
html = md(strip_tags(value), extensions=["fenced_code", "tables"])
return mark_safe(html)
示例15: send_fulltext
# 需要导入模块: from django.utils import html [as 别名]
# 或者: from django.utils.html import strip_tags [as 别名]
def send_fulltext(domain, from_email):
notify_messages = []
for i_message, message in enumerate(
Message.objects.exclude(
send_notify_messages__isnull=True
).prefetch_related('recipients')
):
notify_messages.append([])
for user in message.recipients.all():
if not user.email:
continue
user_profile = user.profile
user_profile.send_notify_messages.remove(message)
lang = user_profile.language
translation.activate(lang)
subject = message.title
message_text = render_mail(message, user)
plain_text = strip_tags(message_text).replace(' ', ' ')
context = {
"domain": domain,
"title": subject,
"message_text": message_text,
}
html = render_to_string('email_fulltext_mail.html', context)
notify_messages[i_message].append((subject, plain_text, html, from_email, [user.email]))
translation.deactivate()
return notify_messages