当前位置: 首页>>代码示例>>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;未经允许,请勿转载。