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


Python html.strip_tags方法代碼示例

本文整理匯總了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() 
開發者ID:archesproject,項目名稱:arches,代碼行數:27,代碼來源:mobile_survey.py

示例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
    }) 
開發者ID:cyanfish,項目名稱:heltour,代碼行數:26,代碼來源:api.py

示例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 
開發者ID:idlesign,項目名稱:django-sitemessage,代碼行數:27,代碼來源:smtp.py

示例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() 
開發者ID:pydata,項目名稱:conf_site,代碼行數:27,代碼來源:mail.py

示例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') 
開發者ID:amfoss,項目名稱:cms,代碼行數:19,代碼來源:schema.py

示例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() 
開發者ID:evernote,項目名稱:zing,代碼行數:21,代碼來源:payment_email.py

示例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'
        ]) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:20,代碼來源:tests.py

示例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>') 
開發者ID:ekansa,項目名稱:open-context-py,代碼行數:23,代碼來源:recordprops.py

示例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] 
開發者ID:tamuhack-org,項目名稱:Ouroboros,代碼行數:19,代碼來源:admin.py

示例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 函數 
開發者ID:HelloGitHub-Team,項目名稱:HelloDjango-blog-tutorial,代碼行數:20,代碼來源:models.py

示例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) 
開發者ID:kimeraapp,項目名稱:pythonjobs.ie,代碼行數:4,代碼來源:models.py

示例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') 
開發者ID:archesproject,項目名稱:arches,代碼行數:30,代碼來源:mobile_survey.py

示例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) 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:9,代碼來源:helpers.py

示例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('&nbsp;', ' ')

            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 
開發者ID:znick,項目名稱:anytask,代碼行數:38,代碼來源:send_mail_notifications.py


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