Browse Source

Move url-transformation application to TopicSchema

This was only being done when a new topic was created before, which
meant that if a topic's link was edited, the new link wouldn't go
through the transformation process (and we do want it to).
merge-requests/64/head
Deimos 6 years ago
parent
commit
2fe4743b62
  1. 3
      tildes/tildes/models/topic/topic.py
  2. 4
      tildes/tildes/schemas/topic.py

3
tildes/tildes/models/topic/topic.py

@ -32,7 +32,6 @@ 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, is_tweet
from tildes.lib.url_transform import apply_url_transformations
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
@ -208,7 +207,7 @@ class Topic(DatabaseModel):
"""Create a new link topic.""" """Create a new link topic."""
new_topic = cls._create_base_topic(group, author, title) new_topic = cls._create_base_topic(group, author, title)
new_topic.topic_type = TopicType.LINK new_topic.topic_type = TopicType.LINK
new_topic.link = apply_url_transformations(link)
new_topic.link = link
new_topic.original_url = link new_topic.original_url = link
incr_counter("topics", type="link") incr_counter("topics", type="link")

4
tildes/tildes/schemas/topic.py

@ -11,6 +11,7 @@ from marshmallow import pre_load, Schema, validates, validates_schema, Validatio
from marshmallow.fields import DateTime, List, Nested, String, URL from marshmallow.fields import DateTime, List, Nested, String, URL
import sqlalchemy_utils import sqlalchemy_utils
from tildes.lib.url_transform import apply_url_transformations
from tildes.schemas.fields import Enum, ID36, Ltree, Markdown, SimpleString from tildes.schemas.fields import Enum, ID36, Ltree, Markdown, SimpleString
from tildes.schemas.group import GroupSchema from tildes.schemas.group import GroupSchema
from tildes.schemas.user import UserSchema from tildes.schemas.user import UserSchema
@ -118,6 +119,9 @@ class TopicSchema(Schema):
if not parsed.scheme: if not parsed.scheme:
data["link"] = "http://" + data["link"] data["link"] = "http://" + data["link"]
# run the link through the url-transformation process
data["link"] = apply_url_transformations(data["link"])
return data return data
@validates_schema @validates_schema

Loading…
Cancel
Save