Browse Source

Replace is_tweet() with a check on content type

merge-requests/85/head
Deimos 5 years ago
parent
commit
1fc20d5608
  1. 6
      tildes/tildes/lib/url.py
  2. 6
      tildes/tildes/models/topic/topic.py

6
tildes/tildes/lib/url.py

@ -17,9 +17,3 @@ def get_domain_from_url(url: str, strip_www: bool = True) -> str:
domain = domain[4:] domain = domain[4:]
return domain return domain
def is_tweet(url: str) -> bool:
"""Return whether a url is a link to a tweet."""
domain = get_domain_from_url(url)
return domain == "twitter.com" and "/status/" in url

6
tildes/tildes/models/topic/topic.py

@ -32,7 +32,7 @@ from tildes.lib.datetime import utc_from_timestamp, utc_now
from tildes.lib.id import id_to_id36 from tildes.lib.id import id_to_id36
from tildes.lib.markdown import convert_markdown_to_safe_html from tildes.lib.markdown import convert_markdown_to_safe_html
from tildes.lib.string import convert_to_url_slug from tildes.lib.string import convert_to_url_slug
from tildes.lib.url import get_domain_from_url, is_tweet
from tildes.lib.url import get_domain_from_url
from tildes.metrics import incr_counter from tildes.metrics import incr_counter
from tildes.models import DatabaseModel from tildes.models import DatabaseModel
from tildes.models.group import Group from tildes.models.group import Group
@ -492,7 +492,7 @@ class Topic(DatabaseModel):
if self.is_text_type: if self.is_text_type:
return self.get_content_metadata("excerpt") return self.get_content_metadata("excerpt")
if self.link and is_tweet(self.link):
if self.content_type is TopicContentType.TWEET:
authors = self.get_content_metadata("authors") authors = self.get_content_metadata("authors")
tweet = self.get_content_metadata("description") tweet = self.get_content_metadata("description")
@ -515,7 +515,7 @@ class Topic(DatabaseModel):
if not self.is_link_type: if not self.is_link_type:
return None return None
if self.link and is_tweet(self.link):
if self.content_type is TopicContentType.TWEET:
authors = self.get_content_metadata("authors") authors = self.get_content_metadata("authors")
tweet = self.get_content_metadata("description") tweet = self.get_content_metadata("description")

Loading…
Cancel
Save