本文整理汇总了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)),
},
})
示例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
示例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)
示例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
示例5: __unicode__
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def __unicode__(self):
return '%s' % truncatechars(self.ad, 24)
示例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)
示例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)
示例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)
示例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"
示例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)
示例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)
示例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),
)
示例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)
示例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)
示例15: __unicode__
# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import truncatechars [as 别名]
def __unicode__(self):
return truncatechars(self.name, 16)