Python django.template.defaultfilters.truncatechars() Examples

The following are 20 code examples of django.template.defaultfilters.truncatechars(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.template.defaultfilters , or try the search function .
Example #1
Source File: proxy.py    From zing with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: ticket.py    From online-judge with GNU Affero General Public License v3.0 6 votes vote down vote up
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)),
            },
        }) 
Example #3
Source File: ticket.py    From online-judge with GNU Affero General Public License v3.0 6 votes vote down vote up
def get(self, request, *args, **kwargs):
        try:
            message_id = int(request.GET['message'])
        except (KeyError, ValueError):
            return HttpResponseBadRequest()
        ticket = self.get_object()
        try:
            message = ticket.messages.get(id=message_id)
        except TicketMessage.DoesNotExist:
            return HttpResponseBadRequest()
        return JsonResponse({
            'message': get_template('ticket/message.html').render({'message': message}, request),
            'notification': {
                'title': _('New Ticket Message For: %s') % ticket.title,
                'body': truncatechars(message.body, 200),
            },
        }) 
Example #4
Source File: models.py    From django-yandex-kassa with MIT License 5 votes vote down vote up
def __unicode__(self):
        return truncatechars(self.name, 16) 
Example #5
Source File: note.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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) 
Example #6
Source File: models.py    From srvup-membership with MIT License 5 votes vote down vote up
def get_preview(self):
		#return truncatechars(self.text, 120)
		return Truncator(self.text).chars(120) 
Example #7
Source File: conversation_tags.py    From django-conversation with MIT License 5 votes vote down vote up
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) 
Example #8
Source File: admin.py    From elasticsearch-django with MIT License 5 votes vote down vote up
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) 
Example #9
Source File: models.py    From django-andablog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __unicode__(self):
        return u"{entry} - {image}".format(
            entry=truncatechars(self.entry, 10),
            image=truncatechars(self.image.name, 10),
        ) 
Example #10
Source File: admin.py    From arxiv-vanity with Apache License 2.0 5 votes vote down vote up
def short_paper_title(self, obj):
        return truncatechars(obj.paper.title, 70) 
Example #11
Source File: models.py    From srvup-rest-framework with Apache License 2.0 5 votes vote down vote up
def get_preview(self):
		#return truncatechars(self.text, 120)
		return Truncator(self.text).chars(120) 
Example #12
Source File: email.py    From openduty with MIT License 5 votes vote down vote up
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" 
Example #13
Source File: admin.py    From django-package-monitor with MIT License 5 votes vote down vote up
def _licence(self, obj):
        """Return truncated version of licence."""
        return truncatechars(obj.licence, 20) 
Example #14
Source File: models.py    From Qujini with GNU General Public License v3.0 5 votes vote down vote up
def question_trim(self):
        return truncatechars(self.question, 100) 
Example #15
Source File: models.py    From django-q with MIT License 5 votes vote down vote up
def short_result(self):
        return truncatechars(self.result, 100) 
Example #16
Source File: models.py    From django-google-adwords with MIT License 5 votes vote down vote up
def __unicode__(self):
        return '%s' % truncatechars(self.ad, 24) 
Example #17
Source File: wagtail_hooks.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #18
Source File: wagtail_hooks.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #19
Source File: wagtail_hooks.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #20
Source File: wagtail_hooks.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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