Skip to content

Commit

Permalink
Add support for RTL text direction for template content (#2321)
Browse files Browse the repository at this point in the history
* feat(rtl): add new text direction column to db, model

* feat(rtl): add `text_direction_rtl` property to `TemplateSchema`

* feat(rtl): add `text_direction_rtl` property to the list of properties checked to see if a template changed

* chore: formatting

* tests(rtl): add tests to ensure template updates when text direction changes

* chore: update utils dep

* chore: update poetry lock file

* test(rtl): add tests for creating templates

* chore: bump utils

* chore: update poetry.lock
  • Loading branch information
andrewleith authored Oct 17, 2024
1 parent 00c6286 commit ae05c9f
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 195 deletions.
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ def __init__(self, **kwargs):
hidden = db.Column(db.Boolean, nullable=False, default=False)
subject = db.Column(db.Text)
postage = db.Column(db.String, nullable=True)
text_direction_rtl = db.Column(db.Boolean, nullable=False, default=False)
CheckConstraint(
"""
CASE WHEN template_type = 'letter' THEN
Expand Down
2 changes: 2 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class TemplateSchema(BaseTemplateSchema):
redact_personalisation = fields.Method("redact")
created_at = FlexibleDateTime()
updated_at = FlexibleDateTime()
text_direction_rtl = field_for(models.Template, "text_direction_rtl")

def get_is_precompiled_letter(self, template):
return template.is_precompiled_letter
Expand Down Expand Up @@ -578,6 +579,7 @@ class Meta(BaseSchema.Meta):
"subject",
"redact_personalisation",
"is_precompiled_letter",
"text_direction_rtl",
],
dump_only=True,
)
Expand Down
11 changes: 10 additions & 1 deletion app/template/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ def _template_has_not_changed(current_data, updated_template):
return False
return all(
current_data[key] == updated_template[key]
for key in ("name", "content", "subject", "archived", "process_type", "postage", "template_category_id")
for key in (
"name",
"content",
"subject",
"archived",
"process_type",
"postage",
"template_category_id",
"text_direction_rtl",
)
)


Expand Down
26 changes: 26 additions & 0 deletions migrations/versions/0461_add_rtl_column_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Revision ID: 0461_add_rtl_column_templates
Revises: 0460_new_service_columns
Create Date: 2024-06-27 13:32:00
"""
import sqlalchemy as sa
from alembic import op

revision = "0461_add_rtl_column_templates"
down_revision = "0460_new_service_columns"


def upgrade():
# Add the new column to the templates table
op.add_column("templates", sa.Column("text_direction_rtl", sa.Boolean(), nullable=False, server_default=sa.false()))

# Add the new column to the templates_history table
op.add_column("templates_history", sa.Column("text_direction_rtl", sa.Boolean(), nullable=False, server_default=sa.false()))


def downgrade():
# Remove the column from the templates table
op.drop_column("templates", "text_direction_rtl")

# Remove the column from the templates_history table
op.drop_column("templates_history", "text_direction_rtl")
Loading

0 comments on commit ae05c9f

Please sign in to comment.