python-twitter-django-tags icon indicating copy to clipboard operation
python-twitter-django-tags copied to clipboard

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

Open coredumperror opened this issue 7 years ago • 1 comments

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

coredumperror avatar Jan 26 '18 22:01 coredumperror

This works like a charm!

dre2004 avatar Oct 26 '18 12:10 dre2004