当前位置: 首页>>代码示例>>Python>>正文


Python defaultfilters.truncatewords方法代码示例

本文整理汇总了Python中django.template.defaultfilters.truncatewords方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.truncatewords方法的具体用法?Python defaultfilters.truncatewords怎么用?Python defaultfilters.truncatewords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.defaultfilters的用法示例。


在下文中一共展示了defaultfilters.truncatewords方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_opengraph

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def generate_opengraph(cache_key, data, style):
    metadata = cache.get(cache_key)
    if metadata is None:
        description = None
        tree = reference(markdown(data, style)).tree
        for p in tree.iterfind('.//p'):
            text = p.text_content().strip()
            if text:
                description = text
                break
        if description:
            for remove in (r'\[', r'\]', r'\(', r'\)'):
                description = description.replace(remove, '')
        img = tree.xpath('.//img')
        metadata = truncatewords(description, 60), img[0].get('src') if img else None
        cache.set(cache_key, metadata, 86400)
    return metadata 
开发者ID:DMOJ,项目名称:online-judge,代码行数:19,代码来源:opengraph.py

示例2: item_description

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def item_description(self, item):
        return truncatewords(item.body, 30) 
开发者ID:PacktPublishing,项目名称:Django-3-by-Example,代码行数:4,代码来源:feeds.py

示例3: truncated_title

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def truncated_title(self):
        """
        This PR's title truncated to 4 words
        """
        return truncatewords(self.title, 4) 
开发者ID:open-craft,项目名称:opencraft,代码行数:7,代码来源:github.py

示例4: get_change_message

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def get_change_message(self, obj):
        return truncatewords(obj.get_change_message(), 23) 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:4,代码来源:admin.py

示例5: get_truncated_description

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def get_truncated_description(self, obj):
        return defaultfilters.truncatewords(obj.description, 25) 
开发者ID:opencivicdata,项目名称:python-opencivicdata,代码行数:4,代码来源:event.py

示例6: get_truncated_event_name

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def get_truncated_event_name(self, obj):
        return defaultfilters.truncatewords(obj.event.name, 8) 
开发者ID:opencivicdata,项目名称:python-opencivicdata,代码行数:4,代码来源:event.py

示例7: get_truncated_sponsors

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def get_truncated_sponsors(self, obj):
        spons = ", ".join(s.name for s in obj.sponsorships.all()[:5])
        return defaultfilters.truncatewords(spons, 10) 
开发者ID:opencivicdata,项目名称:python-opencivicdata,代码行数:5,代码来源:bill.py

示例8: get_truncated_title

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def get_truncated_title(self, obj):
        return defaultfilters.truncatewords(obj.title, 25) 
开发者ID:opencivicdata,项目名称:python-opencivicdata,代码行数:4,代码来源:bill.py

示例9: search_terms_

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def search_terms_(self, instance: SearchQuery) -> str:
        """Return truncated version of search_terms."""
        raw = instance.search_terms
        # take first five words, and further truncate to 50 chars if necessary
        return truncatechars(truncatewords(raw, 5), 50) 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:7,代码来源:admin.py

示例10: item_description

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def item_description(self, item):
        return truncatewords(item.content, 30) 
开发者ID:r26zhao,项目名称:django_blog,代码行数:4,代码来源:feeds.py

示例11: short_detail

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def short_detail(self):
        return truncatewords(self.detail, 15) 
开发者ID:openstax,项目名称:openstax-cms,代码行数:4,代码来源:models.py

示例12: test_truncate

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def test_truncate(self):
        self.assertEqual(truncatewords('A sentence with a few words in it', 1), 'A ...') 
开发者ID:nesdis,项目名称:djongo,代码行数:4,代码来源:test_truncatewords.py

示例13: test_truncate2

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def test_truncate2(self):
        self.assertEqual(
            truncatewords('A sentence with a few words in it', 5),
            'A sentence with a few ...',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_truncatewords.py

示例14: test_overtruncate

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def test_overtruncate(self):
        self.assertEqual(
            truncatewords('A sentence with a few words in it', 100),
            'A sentence with a few words in it',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_truncatewords.py

示例15: test_invalid_number

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatewords [as 别名]
def test_invalid_number(self):
        self.assertEqual(
            truncatewords('A sentence with a few words in it', 'not a number'),
            'A sentence with a few words in it',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_truncatewords.py


注:本文中的django.template.defaultfilters.truncatewords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。