Python django.template.defaultfilters 模块,truncatechars() 实例源码

我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用django.template.defaultfilters.truncatechars()

项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def _format(self):
        image = self._dict.get('image')
        if image:
            self._dict['image'] = self._format_image(image)

            if isinstance(image, ImageFieldFile):
                image_size = image._get_image_dimensions()
                is_large = image_size[0] >= 500 and image_size[1] >= 250
                self._dict['card'] = 'summary_large_image' if is_large else 'summary'

        super()._format()

        # title
        title = self._dict.get('title')
        if title:
            self._dict['title'] = truncatechars(title, 70)

        # description
        descr = self._dict.get('description')
        if descr:
            self._dict['description'] = truncatechars(descr, 200)
项目:jakniedojade    作者:hackerspace-silesia    | 项目源码 | 文件源码
def short_description(self, obj):
        return truncatechars(obj.description, 50)
项目:blogghar    作者:v1k45    | 项目源码 | 文件源码
def short_comment(self, obj):
        return truncatechars(obj.comment, 100)
项目:zing    作者:evernote    | 项目源码 | 文件源码
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
项目:arxiv-vanity    作者:arxiv-vanity    | 项目源码 | 文件源码
def short_paper_title(self, obj):
        return truncatechars(obj.paper.title, 70)
项目:djangocms-comments    作者:Nekmo    | 项目源码 | 文件源码
def __str__(self):
        return u'[{}] {}'.format(self.page, truncatechars(self.body, 40))
项目:djangocms-comments    作者:Nekmo    | 项目源码 | 文件源码
def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
        extra_context = extra_context or {}
        comment = self.get_object(request, unquote(object_id))
        if comment is not None:
            extra_context['user_agent'] = get_user_agent(comment.user_agent) or truncatechars(comment.user_agent, 60)
            comment.requires_attention = ''
            comment.save()
        changeform = super(CommentAdmin, self).changeform_view(request, object_id=object_id, form_url=form_url,
                                                               extra_context=extra_context)
        return changeform
项目:djangocms-comments    作者:Nekmo    | 项目源码 | 文件源码
def body_print(self, obj):
        return self._strong_unread(obj, truncatechars(obj.body, 80))
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def short_message(self, obj):
        return truncatechars(obj.message, 48)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def short_message(self, obj):
        return truncatechars(obj.message, 48)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def short_message(self, obj):
        return truncatechars(obj.message, 48)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def short_note(self, obj):
        return truncatechars(obj.note, 36)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def short_message(self, obj):
        return truncatechars(obj.message, 48)
项目:osedev    作者:damoti    | 项目源码 | 文件源码
def excerpt(self, obj):
        return truncatechars(obj.text, 100)
项目:pypers    作者:rossant    | 项目源码 | 文件源码
def title_short(self, obj):
        s = truncatechars(obj.title, 64)
        if not obj.pdf_path:
            return s
        path = reverse('get_paper')
        return format_html('<a href="%s?paper_id=%d" target="_blank">%s</a>' %
                           (path, obj.id, s))
项目:waves-demo    作者:lirmm    | 项目源码 | 文件源码
def short(self, obj):
        """ Truncate short description in list display """
        return truncatechars(obj.short_description, 100)
项目:issue-reporting    作者:6aika    | 项目源码 | 文件源码
def __str__(self):
        return "%s: %s" % (self.identifier, truncatechars(self.description, 50))
项目:bloshi    作者:gskoljarev    | 项目源码 | 文件源码
def truncated_url(self):
        return truncatechars(self.url, 10)
项目:newco-legacy    作者:blaze33    | 项目源码 | 文件源码
def save(self):
        maxl = self._meta.get_field_by_name("slug")[0].max_length
        self.slug = truncatechars(slugify(self.name), maxl)
        super(Item, self).save()
项目:newco-legacy    作者:blaze33    | 项目源码 | 文件源码
def __unicode__(self):
        return truncatechars(self.content, 50)
项目:newco-legacy    作者:blaze33    | 项目源码 | 文件源码
def __unicode__(self):
        return truncatechars(strip_tags(self.content), 50)
项目:uwcs-zarya    作者:davidjrichardson    | 项目源码 | 文件源码
def migrate_events():
    event_index = Page.objects.get(id=6).specific
    user = get_user_model().objects.get(id=1)
    old_events = OldEvent.objects.using('old_data').all()

    # Migrate events
    for old_event in old_events:
        old_event_type = old_event.type

        try:
            # We don't actually care about this - its a test to migrate the event across
            event_type = EventType.objects.get(name=old_event_type.name, target=old_event_type.target)
        except EventType.DoesNotExist:
            event_type = EventType(name=old_event_type.name, target=old_event_type.target)
            event_type.save()

        title = '{type} on {date}'.format(type=old_event_type.name, date=date(old_event.start, 'D jS F Y'))
        slug = slugify('{title} - {rand}'.format(title=title, rand=int(round(time.time() * 1000))))

        if old_event.shortDescription:
            description = old_event.shortDescription
        else:
            if old_event_type.info:
                description = old_event_type.info
            else:
                description = old_event_type.name

        new_event = EventPage(
            title=title.strip(),
            slug=slug,
            description=description.strip(),
            start=old_event.start,
            finish=old_event.finish,
            cancelled=old_event.cancelled,
            category=event_type,
            location=old_event.location.name
        )

        new_event.body.stream_data = [
            ('paragraph', RichText('<p>{body}</p>'.format(body=linebreaks(old_event.longDescription))))
        ]

        print('Restoring event {type} from {date}'.format(type=old_event.type.name, date=old_event.start))

        event_index.add_child(instance=new_event)
        revision = new_event.save_revision(
            user=user,
            submitted_for_moderation=False
        )
        revision.publish()
        new_event.save()

        # Deal with signups
        old_signups = Signup.objects.using('old_data').filter(event_id=old_event.id)

        for old_signup in old_signups:
            print('Restoring signup for {type} from {date}'.format(type=old_event.type.name, date=old_event.start))
            new_signup = EventSignup(comment=truncatechars(old_signup.comment, 1024),
                                     member=get_user_model().objects.get(id=old_signup.user_id),
                                     event_id=new_event.id, signup_created=old_signup.time)
            new_signup.save()
项目:newco-legacy    作者:blaze33    | 项目源码 | 文件源码
def _decathlon_init(aff_item, decathlon_item):
    MATCHING_TABLE = {
        "Url": "url",
        "EAN": "ean",
        "Id produit": "object_id",
        "Url image petite": "img_small",
        "Url image moyenne": "img_medium",
        "Url image grande": "img_large"
    }

    CURRENCY_TABLE = {u"€": CURRENCIES.euro, u"$": CURRENCIES.dollar,
                      u"£": CURRENCIES.pound}

    DECATHLON_AVAILABILITY_PATTERN = "(?P<days>\d*)\s?jours"
    EXACT_PATTERN = AVAILABILITY_PATTERNS["exact"]

    ROUND = decimal.Decimal(".01")

    for key, value in decathlon_item.items():
        val = unicode(value, "utf-8")
        if key in ["Prix", "Prix barré", "Frais de port"]:
            parsed_price = parse_decimal(val, locale="fr")
            decimal_price = decimal.Decimal(parsed_price).quantize(ROUND)
            if key == "Prix":
                price = decimal_price
            elif key == "Prix barré":
                price_2 = decimal_price
            elif key == "Frais de port":
                aff_item._shipping_price = decimal_price
        elif key == "Monnaie":
            aff_item.currency = CURRENCY_TABLE.get(val, CURRENCIES.euro)
        elif key == "Nom":
            aff_item.name = truncatechars(val, NAME_MAX_LENGTH)
        elif key == "Disponibilité":
            match = re.match(DECATHLON_AVAILABILITY_PATTERN, val)
            if match is not None:
                days = match.groups("days")[0]
                if days:
                    availability = EXACT_PATTERN.format(
                        value=days, unit="D")
                else:
                    availability = "in stock"
                aff_item._availability = availability
        elif key in MATCHING_TABLE:
            setattr(aff_item, MATCHING_TABLE[key], val)

    aff_item.price = price if price and price < price_2 else price_2

    return aff_item