Browse Source

Convert all-caps titles to title case

merge-requests/32/head
Celeo 6 years ago
committed by Deimos
parent
commit
be6fc19c16
  1. 1
      tildes/requirements-to-freeze.txt
  2. 1
      tildes/requirements.txt
  3. 16
      tildes/tests/test_topic.py
  4. 6
      tildes/tildes/models/topic/topic.py

1
tildes/requirements-to-freeze.txt

@ -37,6 +37,7 @@ SQLAlchemy
SQLAlchemy-Utils
stripe
testing.redis
titlecase
webargs
webtest
zope.sqlalchemy

1
tildes/requirements.txt

@ -83,6 +83,7 @@ SQLAlchemy-Utils==0.33.3
stripe==2.4.0
testing.common.database==2.0.3
testing.redis==1.1.1
titlecase==0.12.0
toml==0.9.4
traitlets==4.3.2
transaction==2.2.1

16
tildes/tests/test_topic.py

@ -130,3 +130,19 @@ def test_multiple_edits_update_time(text_topic):
def test_topic_initial_last_activity_time(text_topic):
"""Ensure last_activity_time is initially the same as created_time."""
assert text_topic.last_activity_time == text_topic.created_time
def test_convert_all_caps(session_user, session_group):
"""Ensure that all-caps titles are converted to title case."""
topic = Topic.create_link_topic(
session_group, session_user, "THE TITLE", "http://example.com"
)
assert topic.title == "The Title"
def test_no_convert_partial_caps_title(session_user, session_group):
"""Ensure that partially-caps titles are not converted to title case."""
topic = Topic.create_link_topic(
session_group, session_user, "This is a TITLE", "http://example.com"
)
assert topic.title == "This is a TITLE"

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

@ -20,6 +20,7 @@ from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import deferred, relationship
from sqlalchemy.sql.expression import text
from sqlalchemy_utils import Ltree
from titlecase import titlecase
from tildes.enums import TopicType
from tildes.lib.database import ArrayOfLtree
@ -172,6 +173,11 @@ class Topic(DatabaseModel):
new_topic = cls()
new_topic.group_id = group.group_id
new_topic.user_id = author.user_id
# if the title is all caps, convert to title case
if title.isupper():
title = titlecase(title)
new_topic.title = title
return new_topic

Loading…
Cancel
Save