當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。