From ddd83473f3668ddf96dfe247fd29e0e3d1f4b9b5 Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 29 May 2024 10:24:01 +0200 Subject: [PATCH 1/5] New chyron color fields in projector --- global/meta | 2 +- openslides_backend/action/actions/projector/create.py | 2 ++ openslides_backend/action/actions/projector/update.py | 2 ++ openslides_backend/models/models.py | 2 ++ tests/system/action/projector/test_create.py | 2 ++ tests/system/action/projector/test_update.py | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/global/meta b/global/meta index d79688cdc..f84717978 160000 --- a/global/meta +++ b/global/meta @@ -1 +1 @@ -Subproject commit d79688cdcdf93c601ea9d7d2186403f739c3a5fe +Subproject commit f847179784964e578e8982fe01e8bfb2ee8d153f diff --git a/openslides_backend/action/actions/projector/create.py b/openslides_backend/action/actions/projector/create.py index ac33d1429..3cb65e228 100644 --- a/openslides_backend/action/actions/projector/create.py +++ b/openslides_backend/action/actions/projector/create.py @@ -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", diff --git a/openslides_backend/action/actions/projector/update.py b/openslides_backend/action/actions/projector/update.py index ab9d15f86..0d1365ff8 100644 --- a/openslides_backend/action/actions/projector/update.py +++ b/openslides_backend/action/actions/projector/update.py @@ -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", diff --git a/openslides_backend/models/models.py b/openslides_backend/models/models.py index d3bc54c63..75cb8a57e 100644 --- a/openslides_backend/models/models.py +++ b/openslides_backend/models/models.py @@ -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) diff --git a/tests/system/action/projector/test_create.py b/tests/system/action/projector/test_create.py index c0cbbab1e..c4aed82b3 100644 --- a/tests/system/action/projector/test_create.py +++ b/tests/system/action/projector/test_create.py @@ -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, diff --git a/tests/system/action/projector/test_update.py b/tests/system/action/projector/test_update.py index 837019fd5..be954e976 100644 --- a/tests/system/action/projector/test_update.py +++ b/tests/system/action/projector/test_update.py @@ -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, From 4f291095a46cf17a4877f3c8140f24d89a5d1761 Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 29 May 2024 13:26:15 +0200 Subject: [PATCH 2/5] Fix example data, add migration --- global/data/example-data.json | 4 + .../migrations/0053_fill_new_color_fields.py | 63 ++++++ .../test_0053_fill_new_color_fields.py | 199 ++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 openslides_backend/migrations/migrations/0053_fill_new_color_fields.py create mode 100644 tests/system/migrations/test_0053_fill_new_color_fields.py diff --git a/global/data/example-data.json b/global/data/example-data.json index 2d609049a..713582211 100644 --- a/global/data/example-data.json +++ b/global/data/example-data.json @@ -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, @@ -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, diff --git a/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py new file mode 100644 index 000000000..c2ddab9b1 --- /dev/null +++ b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py @@ -0,0 +1,63 @@ +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 removes all remnants of the old structure level field in meeting users. + """ + + 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 = 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) diff --git a/tests/system/migrations/test_0053_fill_new_color_fields.py b/tests/system/migrations/test_0053_fill_new_color_fields.py new file mode 100644 index 000000000..5c7942795 --- /dev/null +++ b/tests/system/migrations/test_0053_fill_new_color_fields.py @@ -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", + }, + ) From 4f151d8104e9b988fc19a13f8070c14002e005a7 Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 29 May 2024 13:29:56 +0200 Subject: [PATCH 3/5] Migration indices on example and initial data --- global/data/example-data.json | 2 +- global/data/initial-data.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/global/data/example-data.json b/global/data/example-data.json index 713582211..13ef253f0 100644 --- a/global/data/example-data.json +++ b/global/data/example-data.json @@ -1,5 +1,5 @@ { - "_migration_index": 53, + "_migration_index": 54, "organization": { "1": { "id": 1, diff --git a/global/data/initial-data.json b/global/data/initial-data.json index 1d3f16c92..4983d8cbf 100644 --- a/global/data/initial-data.json +++ b/global/data/initial-data.json @@ -1,5 +1,5 @@ { - "_migration_index": 53, + "_migration_index": 54, "organization": { "1": { "id": 1, From bbc44e46185fe249e99d805d7b1e6adf4c543dab Mon Sep 17 00:00:00 2001 From: Luisa Date: Wed, 29 May 2024 14:44:14 +0200 Subject: [PATCH 4/5] Adress tests --- .../migrations/migrations/0053_fill_new_color_fields.py | 2 +- tests/system/presenter/test_check_database_all.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py index c2ddab9b1..dc96afe11 100644 --- a/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py +++ b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py @@ -21,7 +21,7 @@ def migrate_models(self) -> list[BaseRequestEvent] | None: ["headbar", "primary_500"], ).values() ) - theme = themes[0] + 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") diff --git a/tests/system/presenter/test_check_database_all.py b/tests/system/presenter/test_check_database_all.py index e62223f64..f4c520c81 100644 --- a/tests/system/presenter/test_check_database_all.py +++ b/tests/system/presenter/test_check_database_all.py @@ -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, @@ -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, @@ -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, @@ -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, From 2ca6a453849c1ec57b5ddd558490bf6365de24fd Mon Sep 17 00:00:00 2001 From: Luisa Date: Thu, 30 May 2024 13:47:27 +0200 Subject: [PATCH 5/5] Edit comment --- .../migrations/migrations/0053_fill_new_color_fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py index dc96afe11..e61a06bf8 100644 --- a/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py +++ b/openslides_backend/migrations/migrations/0053_fill_new_color_fields.py @@ -7,7 +7,8 @@ class Migration(BaseModelMigration): """ - This migration removes all remnants of the old structure level field in meeting users. + 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