Skip to content

expand_tweet_urls is broken because SetText() doesn't exist any more. #2

Open
@coredumperror

Description

@coredumperror

Thanks for this great template filters! These saved me a ton of time having to manually rewrite my old CMS's way of doing this.

There's one game-breaking bug, though: the Status class from python-twitter no longer has a SetText() method. Instead, you apparently just have to assign to tweet.text directly.

I replaced the filter with this, and it works great:

@register.filter()
def expand_tweet_urls(tweet):
    """
    Replace shortened URLs with long URLs in the twitter status. Should be used before urlize_tweet.
    """
    for url in tweet.urls:
        tweet.text = tweet.text.replace(
            url.url, '<a href="{}" target="_blank">{}</a>'.format(url.expanded_url, url.url)
        )
    return tweet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions