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


Python defaultfilters.truncatechars方法代码示例

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


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

示例1: get

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def get(self, request, *args, **kwargs):
        try:
            self.kwargs['pk'] = int(request.GET['id'])
        except (KeyError, ValueError):
            return HttpResponseBadRequest()
        ticket = self.get_object()
        message = ticket.messages.first()
        return JsonResponse({
            'row': get_template('ticket/row.html').render({'ticket': ticket}, request),
            'notification': {
                'title': _('New Ticket: %s') % ticket.title,
                'body': '%s\n%s' % (_('#%(id)d, assigned to: %(users)s') % {
                    'id': ticket.id,
                    'users': (_(', ').join(ticket.assignees.values_list('user__username', flat=True)) or _('no one')),
                }, truncatechars(message.body, 200)),
            },
        }) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:19,代码来源:ticket.py

示例2: unit_info

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def unit_info(self):
        info = {}
        if self.unit is None:
            return info
        info.update(
            dict(
                source=truncatechars(self.unit_source, 50),
                unit_url=self.unit_translate_url,
            )
        )
        if self.qc_name is None:
            return info
        info.update(
            dict(
                check_name=self.qc_name,
                check_displayname=check_names.get(self.qc_name, self.qc_name),
            )
        )
        return info 
开发者ID:evernote,项目名称:zing,代码行数:21,代码来源:proxy.py

示例3: note_saved

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def note_saved(sender, instance, created, **kwargs):
    if created and instance.order:
        order = instance.order
        user = instance.created_by

        if user is not order.user:
            msg = truncatechars(instance.body, 75)
            order.notify("note_added", msg, user) 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:note.py

示例4: name_display

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def name_display(obj):
        if obj.description:
            description = truncatechars(obj.description, 64)
            return mark_safe("{}<br/><small>{}</small>".format(obj.name, description))
        return obj.name 
开发者ID:jberghoef,项目名称:wagtail-tag-manager,代码行数:7,代码来源:wagtail_hooks.py

示例5: __unicode__

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def __unicode__(self):
        return '%s' % truncatechars(self.ad, 24) 
开发者ID:alexhayes,项目名称:django-google-adwords,代码行数:4,代码来源:models.py

示例6: short_result

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def short_result(self):
        return truncatechars(self.result, 100) 
开发者ID:Koed00,项目名称:django-q,代码行数:4,代码来源:models.py

示例7: question_trim

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def question_trim(self):
        return truncatechars(self.question, 100) 
开发者ID:amfoss,项目名称:Qujini,代码行数:4,代码来源:models.py

示例8: _licence

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def _licence(self, obj):
        """Return truncated version of licence."""
        return truncatechars(obj.licence, 20) 
开发者ID:yunojuno-archive,项目名称:django-package-monitor,代码行数:5,代码来源:admin.py

示例9: notify

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def notify(self, notification):

        gmail_user = self.__config['user']
        gmail_pwd = self.__config['password']
        truncate_length = int(self.__config.get('max_subject_length', 100))
        FROM = self.__config['user']
        TO = [notification.user_to_notify.email]
        try:
            SUBJECT = "Openduty Incident Report - {0}".format(notification.incident.description)
        except:
            SUBJECT = notification.message
        if truncate_length:
            SUBJECT = truncatechars(SUBJECT, truncate_length)
        TEXT =  notification.message
        message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
            """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
        try:
            server = smtplib.SMTP("smtp.gmail.com", 587)
            server.starttls()
            server.ehlo()
            server.login(gmail_user, gmail_pwd)
            server.sendmail(FROM, TO, message)
            server.close()
            print 'successfully sent the mail'
        except:
            print "failed to send mail" 
开发者ID:ustream,项目名称:openduty,代码行数:28,代码来源:email.py

示例10: get_preview

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def get_preview(self):
		#return truncatechars(self.text, 120)
		return Truncator(self.text).chars(120) 
开发者ID:codingforentrepreneurs,项目名称:srvup-rest-framework,代码行数:5,代码来源:models.py

示例11: short_paper_title

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def short_paper_title(self, obj):
        return truncatechars(obj.paper.title, 70) 
开发者ID:arxiv-vanity,项目名称:arxiv-vanity,代码行数:4,代码来源:admin.py

示例12: __unicode__

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def __unicode__(self):
        return u"{entry} - {image}".format(
            entry=truncatechars(self.entry, 10),
            image=truncatechars(self.image.name, 10),
        ) 
开发者ID:WimpyAnalytics,项目名称:django-andablog,代码行数:7,代码来源:models.py

示例13: search_terms_

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [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

示例14: chain_user_names

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def chain_user_names(users, exclude_user, truncate=35):
    """Tag to return a truncated chain of user names."""
    if not users or not isinstance(exclude_user, get_user_model()):
        return ''
    return truncatechars(
        ', '.join(u'{}'.format(u) for u in users.exclude(pk=exclude_user.pk)),
        truncate) 
开发者ID:bitlabstudio,项目名称:django-conversation,代码行数:9,代码来源:conversation_tags.py

示例15: __unicode__

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def __unicode__(self):
        return truncatechars(self.name, 16) 
开发者ID:DrMartiner,项目名称:django-yandex-kassa,代码行数:4,代码来源:models.py


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