From 92e7f519f27b23e559135396ad1fc2673f41e435 Mon Sep 17 00:00:00 2001 From: Ritabear Date: Sun, 16 Jun 2024 22:19:35 +0800 Subject: [PATCH 1/5] feat: control displayed sponsors --- src/sponsors/admin.py | 2 +- src/sponsors/api/views.py | 3 +++ .../migrations/0033_sponsor_is_shown.py | 18 ++++++++++++++++++ src/sponsors/models.py | 6 ++++++ src/sponsors/tests/test_api.py | 15 ++++++++------- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/sponsors/migrations/0033_sponsor_is_shown.py diff --git a/src/sponsors/admin.py b/src/sponsors/admin.py index 90468743a..7bc1744a9 100644 --- a/src/sponsors/admin.py +++ b/src/sponsors/admin.py @@ -7,7 +7,7 @@ @admin.register(Sponsor) class SponsorAdmin(TranslationAdmin): fields = [ - 'name', 'level', 'website_url', 'intro', 'subtitle', + 'name', 'level', 'is_shown', 'website_url', 'intro', 'subtitle', 'logo_svg', 'logo_image', 'order' ] list_display = ['name', 'level', 'order'] diff --git a/src/sponsors/api/views.py b/src/sponsors/api/views.py index 022ddd959..34142d59b 100644 --- a/src/sponsors/api/views.py +++ b/src/sponsors/api/views.py @@ -20,6 +20,9 @@ def get(self, request): if sponsor.level_en_name not in level_dict: level_dict[sponsor.level_en_name] = [] + if sponsor.is_shown is False: + continue + level_dict[sponsor.level_en_name].append({ "name_en_us": sponsor.name_en_us, "name_zh_hant": sponsor.name_zh_hant, diff --git a/src/sponsors/migrations/0033_sponsor_is_shown.py b/src/sponsors/migrations/0033_sponsor_is_shown.py new file mode 100644 index 000000000..39d4d12b9 --- /dev/null +++ b/src/sponsors/migrations/0033_sponsor_is_shown.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.25 on 2024-06-02 09:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sponsors', '0032_fix_verbose_typo'), + ] + + operations = [ + migrations.AddField( + model_name='sponsor', + name='is_shown', + field=models.BooleanField(default=False, verbose_name='is shown'), + ), + ] diff --git a/src/sponsors/models.py b/src/sponsors/models.py index 9691af375..d10401a16 100644 --- a/src/sponsors/models.py +++ b/src/sponsors/models.py @@ -23,6 +23,12 @@ class Sponsor(ConferenceRelated): verbose_name=_('name'), max_length=100, ) + + is_shown = models.BooleanField( + verbose_name=_('is shown'), + default=False, + ) + website_url = models.URLField( verbose_name=_('website URL'), max_length=255, blank=True, diff --git a/src/sponsors/tests/test_api.py b/src/sponsors/tests/test_api.py index 169188988..cfcd5d989 100644 --- a/src/sponsors/tests/test_api.py +++ b/src/sponsors/tests/test_api.py @@ -6,12 +6,13 @@ @pytest.fixture(autouse=True, scope='function') def test_data(): # sponsors - # platinum - sponsor_1 = Sponsor.objects.create(name='1', level=1) - # gold - sponsor_2 = Sponsor.objects.create(name='2', level=2, order=2) - sponsor_3 = Sponsor.objects.create(name='3', level=2, order=None) # noqa - sponsor_4 = Sponsor.objects.create(name='4', level=2, order=1) # noqa + # # platinum + sponsor_1 = Sponsor.objects.create(name='1', level=1, is_shown=True) + # # gold + sponsor_2 = Sponsor.objects.create(name='2', level=2, order=2, is_shown=True) + sponsor_3 = Sponsor.objects.create(name='3', level=2, order=None, is_shown=True) # noqa + sponsor_4 = Sponsor.objects.create(name='4', level=2, order=1, is_shown=True) # noqa + sponsor_5 = Sponsor.objects.create(name='5', level=2, order=3, is_shown=False) # Not shown sponsor # roles OpenRole.objects.create(sponsor=sponsor_1, name='11', description='...') @@ -69,4 +70,4 @@ def test_should_get_role_data(self, api_client): assert len(jobs_2) == 2 job_names = [j['job_name_en_us'] for j in jobs_2] - assert set(job_names) == {'21', '22'} + assert set(job_names) == {'21', '22'} \ No newline at end of file From e0697b828128249b5da6ecbdf9584fe3b1ae2ce8 Mon Sep 17 00:00:00 2001 From: Ritabear Date: Sun, 16 Jun 2024 22:54:07 +0800 Subject: [PATCH 2/5] fix:ruff formatting --- src/sponsors/tests/test_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sponsors/tests/test_api.py b/src/sponsors/tests/test_api.py index cfcd5d989..34d6048d3 100644 --- a/src/sponsors/tests/test_api.py +++ b/src/sponsors/tests/test_api.py @@ -12,7 +12,7 @@ def test_data(): sponsor_2 = Sponsor.objects.create(name='2', level=2, order=2, is_shown=True) sponsor_3 = Sponsor.objects.create(name='3', level=2, order=None, is_shown=True) # noqa sponsor_4 = Sponsor.objects.create(name='4', level=2, order=1, is_shown=True) # noqa - sponsor_5 = Sponsor.objects.create(name='5', level=2, order=3, is_shown=False) # Not shown sponsor + sponsor_5 = Sponsor.objects.create(name='5', level=2, order=3, is_shown=False) # noqa # roles OpenRole.objects.create(sponsor=sponsor_1, name='11', description='...') @@ -44,6 +44,7 @@ def test_should_get_sponsor_data(self, api_client): # small-order > large-order > null-order gold_sponsor_names = [s['name_en_us'] for s in gold_sponsors] assert gold_sponsor_names == ['4', '2', '3'] + assert '5' not in gold_sponsor_names def test_should_get_role_data(self, api_client): # arrange: test_data fixture @@ -70,4 +71,4 @@ def test_should_get_role_data(self, api_client): assert len(jobs_2) == 2 job_names = [j['job_name_en_us'] for j in jobs_2] - assert set(job_names) == {'21', '22'} \ No newline at end of file + assert set(job_names) == {'21', '22'} From 2d7c5f4966f54efbf185b9bb7c32c049ef48a81c Mon Sep 17 00:00:00 2001 From: Ritabear Date: Fri, 21 Jun 2024 08:03:45 +0800 Subject: [PATCH 3/5] fix:translation and redundant cod --- src/locale/en_US/LC_MESSAGES/django.po | 56 +++++++++++++----------- src/locale/zh_Hant/LC_MESSAGES/django.po | 56 +++++++++++++----------- src/sponsors/tests/test_api.py | 1 - 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/locale/en_US/LC_MESSAGES/django.po b/src/locale/en_US/LC_MESSAGES/django.po index cd1932195..2ae1f85e2 100644 --- a/src/locale/en_US/LC_MESSAGES/django.po +++ b/src/locale/en_US/LC_MESSAGES/django.po @@ -13,7 +13,7 @@ msgid "" msgstr "" "Project-Id-Version: PyCon TW\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-15 17:45+0800\n" +"POT-Creation-Date: 2024-06-21 07:48+0800\n" "PO-Revision-Date: 2022-07-11 02:23+0800\n" "Last-Translator: Tom Chen \n" "Language-Team: English (United States) (http://www.transifex.com/pycon-" @@ -506,7 +506,7 @@ msgstr "keynote events" msgid "Keynote: {speaker}" msgstr "Keynote: {speaker}" -#: events/models.py:318 sponsors/models.py:97 sponsors/models.py:113 +#: events/models.py:318 sponsors/models.py:103 sponsors/models.py:119 msgid "sponsor" msgstr "sponsor" @@ -1418,23 +1418,27 @@ msgstr "Stage {stage} dump for {proposal}" msgid "name" msgstr "name" -#: sponsors/models.py:27 +#: sponsors/models.py:28 +msgid "is shown" +msgstr "display on prod" + +#: sponsors/models.py:33 msgid "website URL" msgstr "website URL" -#: sponsors/models.py:31 +#: sponsors/models.py:37 msgid "introduction" msgstr "introduction" -#: sponsors/models.py:34 +#: sponsors/models.py:40 msgid "subtitle" msgstr "subtitle" -#: sponsors/models.py:39 +#: sponsors/models.py:45 msgid "logo (SVG)" msgstr "logo (SVG)" -#: sponsors/models.py:42 +#: sponsors/models.py:48 msgid "" "Vector format of the logo, in SVG. This takes precedence to the raster " "format, if available." @@ -1442,11 +1446,11 @@ msgstr "" "Vector format of the logo, in SVG. This takes precedence to the raster " "format, if available." -#: sponsors/models.py:47 +#: sponsors/models.py:53 msgid "logo (image)" msgstr "logo (image)" -#: sponsors/models.py:51 +#: sponsors/models.py:57 msgid "" "Raster format of the logo, e.g. PNG, JPEG. This is used as fallback when the " "SVG file is not available." @@ -1454,71 +1458,71 @@ msgstr "" "Raster format of the logo, e.g. PNG, JPEG. This is used as fallback when the " "SVG file is not available." -#: sponsors/models.py:56 +#: sponsors/models.py:62 msgid "order" msgstr "order" -#: sponsors/models.py:76 +#: sponsors/models.py:82 msgid "platinum" msgstr "platinum" -#: sponsors/models.py:77 +#: sponsors/models.py:83 msgid "gold" msgstr "gold" -#: sponsors/models.py:78 +#: sponsors/models.py:84 msgid "silver" msgstr "silver" -#: sponsors/models.py:79 +#: sponsors/models.py:85 msgid "bronze" msgstr "bronze" -#: sponsors/models.py:80 +#: sponsors/models.py:86 msgid "special" msgstr "special" -#: sponsors/models.py:81 +#: sponsors/models.py:87 msgid "special-thanks" msgstr "special-thanks" -#: sponsors/models.py:82 +#: sponsors/models.py:88 msgid "organizer" msgstr "organizer" -#: sponsors/models.py:83 +#: sponsors/models.py:89 msgid "co-organizer" msgstr "co-organizer" -#: sponsors/models.py:92 +#: sponsors/models.py:98 msgid "level" msgstr "level" -#: sponsors/models.py:98 +#: sponsors/models.py:104 msgid "sponsors" msgstr "sponsors" -#: sponsors/models.py:118 +#: sponsors/models.py:124 msgid "open role name" msgstr "open role name" -#: sponsors/models.py:123 +#: sponsors/models.py:129 msgid "open role description" msgstr "open role description" -#: sponsors/models.py:127 +#: sponsors/models.py:133 msgid "open role requirements" msgstr "open role requirements" -#: sponsors/models.py:132 +#: sponsors/models.py:138 msgid "open role URL" msgstr "open role URL" -#: sponsors/models.py:137 +#: sponsors/models.py:143 msgid "open role" msgstr "open role" -#: sponsors/models.py:138 +#: sponsors/models.py:144 msgid "open roles" msgstr "open roles" diff --git a/src/locale/zh_Hant/LC_MESSAGES/django.po b/src/locale/zh_Hant/LC_MESSAGES/django.po index 645976e65..d9beef693 100644 --- a/src/locale/zh_Hant/LC_MESSAGES/django.po +++ b/src/locale/zh_Hant/LC_MESSAGES/django.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: PyCon TW\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-15 17:45+0800\n" +"POT-Creation-Date: 2024-06-21 07:48+0800\n" "PO-Revision-Date: 2022-07-11 02:25+0800\n" "Last-Translator: Tom Chen \n" "Language-Team: Chinese Traditional (http://www.transifex.com/pycon-taiwan/" @@ -513,7 +513,7 @@ msgstr "基調演講" msgid "Keynote: {speaker}" msgstr "基調演講:{speaker}" -#: events/models.py:318 sponsors/models.py:97 sponsors/models.py:113 +#: events/models.py:318 sponsors/models.py:103 sponsors/models.py:119 msgid "sponsor" msgstr "贊助" @@ -1375,104 +1375,108 @@ msgstr "第 {stage} 階段封存《{proposal}》" msgid "name" msgstr "名稱" -#: sponsors/models.py:27 +#: sponsors/models.py:28 +msgid "is shown" +msgstr "同步顯示於 prod" + +#: sponsors/models.py:33 msgid "website URL" msgstr "網站 URL" -#: sponsors/models.py:31 +#: sponsors/models.py:37 msgid "introduction" msgstr "簡介" -#: sponsors/models.py:34 +#: sponsors/models.py:40 msgid "subtitle" msgstr "副標題" -#: sponsors/models.py:39 +#: sponsors/models.py:45 msgid "logo (SVG)" msgstr "logo (SVG)" -#: sponsors/models.py:42 +#: sponsors/models.py:48 msgid "" "Vector format of the logo, in SVG. This takes precedence to the raster " "format, if available." msgstr "即使有點陣式圖形格式的圖標,還是會優先採用向量式SVG格式的圖標。" -#: sponsors/models.py:47 +#: sponsors/models.py:53 msgid "logo (image)" msgstr "logo (圖片)" -#: sponsors/models.py:51 +#: sponsors/models.py:57 msgid "" "Raster format of the logo, e.g. PNG, JPEG. This is used as fallback when the " "SVG file is not available." msgstr "" "當SVG格式的檔案不存在時,會回過頭來使用點陣式格式的圖標,例如PNG、JPEG。" -#: sponsors/models.py:56 +#: sponsors/models.py:62 msgid "order" msgstr "排序" -#: sponsors/models.py:76 +#: sponsors/models.py:82 msgid "platinum" msgstr "白金級" -#: sponsors/models.py:77 +#: sponsors/models.py:83 msgid "gold" msgstr "金級" -#: sponsors/models.py:78 +#: sponsors/models.py:84 msgid "silver" msgstr "銀級" -#: sponsors/models.py:79 +#: sponsors/models.py:85 msgid "bronze" msgstr "銅級" -#: sponsors/models.py:80 +#: sponsors/models.py:86 msgid "special" msgstr "特別贊助" -#: sponsors/models.py:81 +#: sponsors/models.py:87 msgid "special-thanks" msgstr "特別感謝" -#: sponsors/models.py:82 +#: sponsors/models.py:88 msgid "organizer" msgstr "主辦單位" -#: sponsors/models.py:83 +#: sponsors/models.py:89 msgid "co-organizer" msgstr "協辦單位" -#: sponsors/models.py:92 +#: sponsors/models.py:98 msgid "level" msgstr "等級" -#: sponsors/models.py:98 +#: sponsors/models.py:104 msgid "sponsors" msgstr "贊助" -#: sponsors/models.py:118 +#: sponsors/models.py:124 msgid "open role name" msgstr "職缺名稱" -#: sponsors/models.py:123 +#: sponsors/models.py:129 msgid "open role description" msgstr "職缺說明" -#: sponsors/models.py:127 +#: sponsors/models.py:133 msgid "open role requirements" msgstr "職缺需求" -#: sponsors/models.py:132 +#: sponsors/models.py:138 msgid "open role URL" msgstr "職缺 URL" -#: sponsors/models.py:137 +#: sponsors/models.py:143 msgid "open role" msgstr "職缺" -#: sponsors/models.py:138 +#: sponsors/models.py:144 msgid "open roles" msgstr "職缺" diff --git a/src/sponsors/tests/test_api.py b/src/sponsors/tests/test_api.py index 34d6048d3..374354ccb 100644 --- a/src/sponsors/tests/test_api.py +++ b/src/sponsors/tests/test_api.py @@ -44,7 +44,6 @@ def test_should_get_sponsor_data(self, api_client): # small-order > large-order > null-order gold_sponsor_names = [s['name_en_us'] for s in gold_sponsors] assert gold_sponsor_names == ['4', '2', '3'] - assert '5' not in gold_sponsor_names def test_should_get_role_data(self, api_client): # arrange: test_data fixture From 68710ed9bfde4bd9ee362b9b2a5adf9038d94151 Mon Sep 17 00:00:00 2001 From: Ritabear Date: Mon, 24 Jun 2024 22:36:05 +0800 Subject: [PATCH 4/5] fix:naming for is_shown --- src/locale/en_US/LC_MESSAGES/django.po | 2 +- src/locale/zh_Hant/LC_MESSAGES/django.po | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/locale/en_US/LC_MESSAGES/django.po b/src/locale/en_US/LC_MESSAGES/django.po index 2ae1f85e2..3239da342 100644 --- a/src/locale/en_US/LC_MESSAGES/django.po +++ b/src/locale/en_US/LC_MESSAGES/django.po @@ -1420,7 +1420,7 @@ msgstr "name" #: sponsors/models.py:28 msgid "is shown" -msgstr "display on prod" +msgstr "is_shown" #: sponsors/models.py:33 msgid "website URL" diff --git a/src/locale/zh_Hant/LC_MESSAGES/django.po b/src/locale/zh_Hant/LC_MESSAGES/django.po index d9beef693..a1e05ee09 100644 --- a/src/locale/zh_Hant/LC_MESSAGES/django.po +++ b/src/locale/zh_Hant/LC_MESSAGES/django.po @@ -1377,7 +1377,7 @@ msgstr "名稱" #: sponsors/models.py:28 msgid "is shown" -msgstr "同步顯示於 prod" +msgstr "顯示於官網" #: sponsors/models.py:33 msgid "website URL" From 2a232a0350cee754085027665bf027f73f80c169 Mon Sep 17 00:00:00 2001 From: "Wei-Hsiang (Matt) Wang" Date: Wed, 26 Jun 2024 00:10:44 +0800 Subject: [PATCH 5/5] Apply suggestions from code review --- src/locale/en_US/LC_MESSAGES/django.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/en_US/LC_MESSAGES/django.po b/src/locale/en_US/LC_MESSAGES/django.po index 3239da342..a402e1d86 100644 --- a/src/locale/en_US/LC_MESSAGES/django.po +++ b/src/locale/en_US/LC_MESSAGES/django.po @@ -1420,7 +1420,7 @@ msgstr "name" #: sponsors/models.py:28 msgid "is shown" -msgstr "is_shown" +msgstr "whether to show on the website" #: sponsors/models.py:33 msgid "website URL"