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


Python text.Truncator方法代碼示例

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


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

示例1: label_and_url_for_value

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def label_and_url_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.model._default_manager.using(self.db).get(**{key: value})
        except (ValueError, self.rel.model.DoesNotExist):
            return '', ''

        try:
            url = reverse(
                '%s:%s_%s_change' % (
                    self.admin_site.name,
                    obj._meta.app_label,
                    obj._meta.object_name.lower(),
                ),
                args=(obj.pk,)
            )
        except NoReverseMatch:
            url = ''  # Admin not registered for target model.

        return Truncator(obj).words(14, truncate='...'), url 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:22,代碼來源:widgets.py

示例2: render

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def render(text, truncate_words=None):
    html = markdown.markdown(
        text,
        extensions=[
            EmojiExtension(emoji_index=twemoji),
            SuperFencesCodeExtension(),
            MagiclinkExtension(),
            DeleteSubExtension(subscript=False),
            Nl2BrExtension(),
        ]
    )
    markdown_attrs['img'].append('class')
    markdown_tags.append('pre')
    clean_html = bleach.clean(html, markdown_tags, markdown_attrs)

    if truncate_words:
        clean_html = Truncator(clean_html).words(num=truncate_words, html=True)

    return clean_html 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:21,代碼來源:markdown.py

示例3: notify_message_push_subscribers_with_language

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def notify_message_push_subscribers_with_language(message, subscriptions, language):
    conversation = message.conversation

    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        message_title = get_message_title(message, language)

    if message.is_thread_reply():
        click_action = frontend_urls.thread_url(message.thread)
    else:
        click_action = frontend_urls.conversation_url(conversation, message.author)

    notify_subscribers_by_device(
        subscriptions,
        click_action=click_action,
        fcm_options={
            'message_title': message_title,
            'message_body': Truncator(message.content).chars(num=1000),
            # this causes each notification for a given conversation to replace previous notifications
            # fancier would be to make the new notifications show a summary not just the latest message
            'tag': 'conversation:{}'.format(conversation.id),
        }
    ) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:27,代碼來源:tasks.py

示例4: label_and_url_for_value

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def label_and_url_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.model._default_manager.using(self.db).get(**{key: value})
        except (ValueError, self.rel.model.DoesNotExist, ValidationError):
            return '', ''

        try:
            url = reverse(
                '%s:%s_%s_change' % (
                    self.admin_site.name,
                    obj._meta.app_label,
                    obj._meta.object_name.lower(),
                ),
                args=(obj.pk,)
            )
        except NoReverseMatch:
            url = ''  # Admin not registered for target model.

        return Truncator(obj).words(14, truncate='...'), url 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:22,代碼來源:widgets.py

示例5: label_for_value

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def label_for_value(self, other_model, rel_name, value):
        try:
            obj = other_model._default_manager.get(**{rel_name: value})
            return '%s' % escape(Truncator(obj).words(14, truncate='...'))
        except (ValueError, other_model.DoesNotExist):
            return "" 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:8,代碼來源:filters.py

示例6: label_for_value

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def label_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.to._default_manager.using(
                self.db).get(**{key: value})
            return '%s' % escape(Truncator(obj).words(14, truncate='...'))
        except (ValueError, self.rel.to.DoesNotExist):
            return "" 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:10,代碼來源:relfield.py

示例7: label_for_value

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def label_for_value(self, value):
        key = self.rel.get_related_field().name
        try:
            obj = self.rel.to._default_manager.using(self.db).get(**{key: value})
            return '&nbsp;<strong>%s</strong>' % escape(Truncator(obj).words(14, truncate='...'))
        except (ValueError, self.rel.to.DoesNotExist):
            return '' 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:widgets.py

示例8: formataddr

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def formataddr(pair, *args, **kwargs):
    # Be nice and limit the length of 'from_email'
    name, email = pair
    name = Truncator(name).chars(num=75)

    return real_formataddr((name, email), *args, **kwargs) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:8,代碼來源:email_utils.py

示例9: prepare_thread_message_notification

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def prepare_thread_message_notification(user, messages):
    first_message = messages[0]
    conversation = first_message.conversation
    group = conversation.find_group()
    thread = first_message.thread

    thread_text_beginning = Truncator(thread.content).chars(num=60)

    from_text = author_names(messages)
    reply_to_name = thread.author.display_name
    conversation_name = thread_text_beginning

    local_part = make_local_part(conversation, user, thread)
    reply_to = formataddr((reply_to_name, '{}@{}'.format(local_part, settings.SPARKPOST_RELAY_DOMAIN)))
    from_email = formataddr((from_text, settings.DEFAULT_FROM_EMAIL))

    unsubscribe_url = thread_unsubscribe_url(user, group, thread)

    return prepare_email(
        template='thread_message_notification',
        from_email=from_email,
        user=user,
        tz=group.timezone,
        reply_to=[reply_to],
        unsubscribe_url=unsubscribe_url,
        context={
            'messages': messages,
            'conversation_name': conversation_name,
            'thread_author': thread.author,
            'thread_message_content': thread.content_rendered(truncate_words=40),
            'thread_url': thread_url(thread),
            'mute_url': unsubscribe_url,
        },
        stats_category='thread_message',
    ) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:37,代碼來源:emails.py

示例10: get_meta_description

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def get_meta_description(self):
        about = Truncator(self.about).words(35)
        return f"{self.full_name} - {self.role}. {about}" 
開發者ID:adinhodovic,項目名稱:wagtail-resume,代碼行數:5,代碼來源:models.py

示例11: get_preview

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def get_preview(self):
		#return truncatechars(self.text, 120)
		return Truncator(self.text).chars(120) 
開發者ID:codingforentrepreneurs,項目名稱:srvup-rest-framework,代碼行數:5,代碼來源:models.py

示例12: __str__

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def __str__(self):
        return Truncator(self.content).words(6, truncate="...") 
開發者ID:openfun,項目名稱:richie,代碼行數:4,代碼來源:models.py

示例13: __str__

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def __str__(self):
        return Truncator(strip_tags(self.body)).words(6, truncate="...") 
開發者ID:openfun,項目名稱:richie,代碼行數:4,代碼來源:models.py

示例14: __str__

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def __str__(self):
        return Truncator(self.title).words(6, truncate="...") 
開發者ID:openfun,項目名稱:richie,代碼行數:4,代碼來源:models.py

示例15: truncatechars

# 需要導入模塊: from django.utils import text [as 別名]
# 或者: from django.utils.text import Truncator [as 別名]
def truncatechars(value, arg):
    """
    Truncates a string after a certain number of characters.

    Argument: Number of characters to truncate after.
    """
    try:
        length = int(arg)
    except ValueError: # Invalid literal for int().
        return value # Fail silently.
    return Truncator(value).chars(length) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:13,代碼來源:defaultfilters.py


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