Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New chyron color fields in projector #2451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion global/data/example-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 53,
"_migration_index": 54,
"organization": {
"1": {
"id": 1,
Expand Down Expand Up @@ -2360,6 +2360,8 @@
"header_h1_color": "#317796",
"chyron_background_color": "#317796",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#134768",
"chyron_font_color_2": "#ffffff",
"show_header_footer": true,
"show_title": true,
"show_logo": true,
Expand Down Expand Up @@ -2404,6 +2406,8 @@
"header_h1_color": "#317796",
"chyron_background_color": "#317796",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#134768",
"chyron_font_color_2": "#ffffff",
"show_header_footer": true,
"show_title": true,
"show_logo": true,
Expand Down
2 changes: 1 addition & 1 deletion global/data/initial-data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_migration_index": 53,
"_migration_index": 54,
"organization": {
"1": {
"id": 1,
Expand Down
2 changes: 1 addition & 1 deletion global/meta
Submodule meta updated 1 files
+8 −0 models.yml
2 changes: 2 additions & 0 deletions openslides_backend/action/actions/projector/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ProjectorCreateAction(SequentialNumbersMixin, CreateAction):
"header_h1_color",
"chyron_background_color",
"chyron_font_color",
"chyron_background_color_2",
"chyron_font_color_2",
"show_header_footer",
"show_title",
"show_logo",
Expand Down
2 changes: 2 additions & 0 deletions openslides_backend/action/actions/projector/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ProjectorUpdate(UpdateAction):
"header_h1_color",
"chyron_background_color",
"chyron_font_color",
"chyron_background_color_2",
"chyron_font_color_2",
"show_header_footer",
"show_title",
"show_logo",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from datastore.migrations import BaseModelMigration
from datastore.shared.util import fqid_from_collection_and_id
from datastore.writer.core import BaseRequestEvent, RequestUpdateEvent

from ...shared.filters import FilterOperator


class Migration(BaseModelMigration):
"""
This migration enriches the database with calculated values
for the new projector color fields "chyron_background_color_2" and "chyron_font_color_2".
"""

target_migration_index = 54

def migrate_models(self) -> list[BaseRequestEvent] | None:
events: list[BaseRequestEvent] = []
themes = list(
self.reader.filter(
"theme",
FilterOperator("theme_for_organization_id", "=", 1),
["headbar", "primary_500"],
).values()
)
theme = {} if len(themes) == 0 else themes[0]
default_color = theme.get("headbar") or (
self.darken_color(str(theme["primary_500"]))
if theme.get("primary_500")
else "#134768"
)
db_models = self.reader.get_all(
"projector", ["chyron_background_color", "chyron_font_color"]
)
for id_, model in db_models.items():
events.append(
RequestUpdateEvent(
fqid_from_collection_and_id("projector", id_),
{
"chyron_background_color_2": (
default_color
if model.get("chyron_background_color") is None
or model.get("chyron_background_color")
== theme.get("primary_500")
else self.darken_color(
str(model["chyron_background_color"])
)
),
"chyron_font_color_2": model.get("chyron_font_color"),
},
)
)
return events

def darken_color(self, color: str) -> str:
"this mirrors the headbar color generation in the client"
stripped = color.lstrip("#")
rgb = tuple(int(stripped[i : i + 2], 16) for i in range(0, 6, 2))
darker = tuple((val**2) // 255 for val in rgb)

p = 25 / 100
rgb1 = darker
rgb2 = rgb
rgb = tuple([int((rgb2[i] - rgb1[i]) * p + rgb1[i]) for i in range(3)])
return "#" + "".join(f"{i:02x}" for i in rgb)
2 changes: 2 additions & 0 deletions openslides_backend/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,9 @@ class Projector(Model):
header_font_color = fields.ColorField(default="#f5f5f5")
header_h1_color = fields.ColorField(default="#317796")
chyron_background_color = fields.ColorField(default="#317796")
chyron_background_color_2 = fields.ColorField(default="#134768")
chyron_font_color = fields.ColorField(default="#ffffff")
chyron_font_color_2 = fields.ColorField(default="#ffffff")
show_header_footer = fields.BooleanField(default=True)
show_title = fields.BooleanField(default=True)
show_logo = fields.BooleanField(default=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/system/action/projector/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def test_create_all_fields(self) -> None:
"header_h1_color": "#cdef01",
"chyron_background_color": "#234567",
"chyron_font_color": "#890abc",
"chyron_background_color_2": "#123456",
"chyron_font_color_2": "#ffaaff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down
2 changes: 2 additions & 0 deletions tests/system/action/projector/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def test_update_correct(self) -> None:
"header_h1_color": "#ffffff",
"chyron_background_color": "#ffffff",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#ffffff",
"chyron_font_color_2": "#ffffff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down
199 changes: 199 additions & 0 deletions tests/system/migrations/test_0053_fill_new_color_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
projector_events = [
{
"type": "create",
"fqid": "projector/3",
"fields": {
"id": 3,
"chyron_background_color": "#c8dcf0", # (200, 220, 240) -> (156, 189, 225) -> (167, 196, 228) -> #a7c4e4
"chyron_font_color": "#ffffff",
},
},
{
"type": "create",
"fqid": "projector/4",
"fields": {"id": 4, "chyron_font_color": "#000000"},
},
{
"type": "create",
"fqid": "projector/5",
"fields": {
"id": 5,
},
},
]


def test_migration_with_empty_theme(write, finalize, assert_model):
write(
{
"type": "create",
"fqid": "organization/1",
"fields": {"id": 1, "theme_id": 2, "theme_ids": [2]},
},
{
"type": "create",
"fqid": "theme/2",
"fields": {
"id": 2,
"organization_id": 1,
"theme_for_organization_id": 1,
},
},
*projector_events
)

finalize("0053_fill_new_color_fields")

assert_model(
"projector/3",
{
"id": 3,
"chyron_background_color": "#c8dcf0",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#a7c4e4",
"chyron_font_color_2": "#ffffff",
},
)
assert_model(
"projector/4",
{
"id": 4,
"chyron_font_color": "#000000",
"chyron_background_color_2": "#134768",
"chyron_font_color_2": "#000000",
},
)
assert_model(
"projector/5",
{"id": 5, "chyron_background_color_2": "#134768"},
)


def test_migration_with_primary_set_in_theme(write, finalize, assert_model):
write(
{
"type": "create",
"fqid": "organization/1",
"fields": {"id": 1, "theme_id": 2, "theme_ids": [2]},
},
{
"type": "create",
"fqid": "theme/2",
"fields": {
"id": 2,
"organization_id": 1,
"theme_for_organization_id": 1,
"primary_500": "#141e28", # (20, 30, 40) -> (1, 3, 6) -> (5, 9, 14) -> #05090e
},
},
*projector_events,
{
"type": "create",
"fqid": "projector/6",
"fields": {
"id": 6,
"chyron_background_color": "#141e28",
},
}
)

finalize("0053_fill_new_color_fields")

assert_model(
"projector/3",
{
"id": 3,
"chyron_background_color": "#c8dcf0",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#a7c4e4",
"chyron_font_color_2": "#ffffff",
},
)
assert_model(
"projector/4",
{
"id": 4,
"chyron_font_color": "#000000",
"chyron_background_color_2": "#05090e",
"chyron_font_color_2": "#000000",
},
)
assert_model(
"projector/5",
{"id": 5, "chyron_background_color_2": "#05090e"},
)
assert_model(
"projector/6",
{
"id": 6,
"chyron_background_color": "#141e28",
"chyron_background_color_2": "#05090e",
},
)


def test_migration_with_headbar_set_in_theme(write, finalize, assert_model):
write(
{
"type": "create",
"fqid": "organization/1",
"fields": {"id": 1, "theme_id": 2, "theme_ids": [2]},
},
{
"type": "create",
"fqid": "theme/2",
"fields": {
"id": 2,
"organization_id": 1,
"theme_for_organization_id": 1,
"primary_500": "#141e28", # (20, 30, 40) -> (1, 3, 6) -> #010306
"headbar": "#ff0000",
},
},
*projector_events,
{
"type": "create",
"fqid": "projector/6",
"fields": {
"id": 6,
"chyron_background_color": "#141e28",
},
}
)

finalize("0053_fill_new_color_fields")

assert_model(
"projector/3",
{
"id": 3,
"chyron_background_color": "#c8dcf0",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#a7c4e4",
"chyron_font_color_2": "#ffffff",
},
)
assert_model(
"projector/4",
{
"id": 4,
"chyron_font_color": "#000000",
"chyron_background_color_2": "#ff0000",
"chyron_font_color_2": "#000000",
},
)
assert_model(
"projector/5",
{
"id": 5,
"chyron_background_color_2": "#ff0000",
},
)
assert_model(
"projector/6",
{
"id": 6,
"chyron_background_color": "#141e28",
"chyron_background_color_2": "#ff0000",
},
)
8 changes: 8 additions & 0 deletions tests/system/presenter/test_check_database_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def test_correct(self) -> None:
"header_h1_color": "#ffffff",
"chyron_background_color": "#ffffff",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#ffffff",
"chyron_font_color_2": "#ffffff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down Expand Up @@ -503,6 +505,8 @@ def test_correct_relations(self) -> None:
"header_h1_color": "#ffffff",
"chyron_background_color": "#ffffff",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#ffffff",
"chyron_font_color_2": "#ffffff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down Expand Up @@ -711,6 +715,8 @@ def test_relation_2(self) -> None:
"header_h1_color": "#ffffff",
"chyron_background_color": "#ffffff",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#ffffff",
"chyron_font_color_2": "#ffffff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down Expand Up @@ -799,6 +805,8 @@ def test_relation_2(self) -> None:
"header_h1_color": "#ffffff",
"chyron_background_color": "#ffffff",
"chyron_font_color": "#ffffff",
"chyron_background_color_2": "#ffffff",
"chyron_font_color_2": "#ffffff",
"show_header_footer": True,
"show_title": True,
"show_logo": True,
Expand Down