Skip to content

Commit

Permalink
feat: control displayed sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritabear committed Jun 16, 2024
1 parent 03d3e8a commit 92e7f51
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sponsors/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 3 additions & 0 deletions src/sponsors/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/sponsors/migrations/0033_sponsor_is_shown.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
6 changes: 6 additions & 0 deletions src/sponsors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions src/sponsors/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='...')
Expand Down Expand Up @@ -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'}

0 comments on commit 92e7f51

Please sign in to comment.