Skip to content

Commit

Permalink
Merge pull request #579 from CTPUG/feature/add_show_speakers_flag_iss…
Browse files Browse the repository at this point in the history
…ue_377

Feature/add show speakers flag issue 377
  • Loading branch information
drnlm committed Nov 19, 2020
2 parents 5e1ea34 + 693236c commit 1c2a765
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
24 changes: 24 additions & 0 deletions wafer/talks/migrations/0021_talk_type_show_speakers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.0.3 on 2020-10-11 12:16

from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import markitup.fields
import wafer.talks.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('talks', '0020_talk_url_public'),
]

operations = [
migrations.AddField(
model_name='talktype',
name='show_speakers',
field=models.BooleanField(default=True, help_text='Whether to show the authors for this talk type in the speakers list', verbose_name='Show authors in speakers list'),
),
]
6 changes: 6 additions & 0 deletions wafer/talks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class TalkType(models.Model):
help_text=_("Whether submissions after the deadline should be accepted")
)

show_speakers = models.BooleanField(
_('Show authors in speakers list'),
default=True,
help_text=_("Whether to show the authors for this talk type in the speakers list")
)

objects = TalkTypeManager()

def __str__(self):
Expand Down
48 changes: 48 additions & 0 deletions wafer/talks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def test_view_seven_speakers(self):

@mock.patch('wafer.users.models.UserProfile.avatar_url', mock_avatar_url)
def test_multiple_types(self):
"""Test the view for multiple talk types"""
talk_d = create_talk('Talk D', ACCEPTED, 'author_d', self.talk_type1)
talk_e = create_talk('Talk E', ACCEPTED, 'author_e', self.talk_type1)
keynote_f = create_talk('Talk F', ACCEPTED, 'author_f', self.talk_type2)
Expand Down Expand Up @@ -530,6 +531,53 @@ def test_multiple_types(self):
'</div>',
]), html=True)

def test_exluding_types(self):
"""Test that the show_speakers flag excludes the speakers from the list."""
hidden = create_talk_type('Hidden')
talk_d = create_talk('Talk D', ACCEPTED, 'author_d', hidden)

response = self.client.get(
reverse('wafer_talks_speakers'))
self.assertEqual(response.status_code, 200)
self.assertIn('Hidden', response.context["speaker_rows"])

# Hide the talk type
hidden.show_speakers = False
hidden.save()

response = self.client.get(
reverse('wafer_talks_speakers'))
self.assertEqual(response.status_code, 200)
self.assertNotIn('Hidden', response.context["speaker_rows"])

def test_ordering_types(self):
"""Test that we order the speakers according to the talk type correctly"""
test1 = create_talk_type('Test 1')
test2 = create_talk_type('Test 2')

# 'Test 1' is at the start of the list
test1.order = 1
test1.save()
test2.order = 2
test2.save()

talk_d = create_talk('Talk D', ACCEPTED, 'author_d', test1)
talk_e = create_talk('Talk D', ACCEPTED, 'author_e', test2)
response = self.client.get(
reverse('wafer_talks_speakers'))
types = list(response.context['speaker_rows'])
# 'None' talk type may be first or last, depending on the database
# so we check the relative order of the talk types
self.assertLess(types.index('Test 1'), types.index('Test 2'))

# Move 'Test 1' to the end of the list
test1.order = 5
test1.save()
response = self.client.get(
reverse('wafer_talks_speakers'))
types = list(response.context['speaker_rows'])
self.assertGreater(types.index('Test 1'), types.index('Test 2'))


class TalkSlugUrlTests(TestCase):
"""Check that we can lookup a talk via correct and incorrect slugs"""
Expand Down
9 changes: 7 additions & 2 deletions wafer/talks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,16 @@ def get_context_data(self, **kwargs):
'user__first_name',
'user__last_name',
'user__username').annotate(
talk_type=F('user__talks__talk_type__name'))
talk_type=F('user__talks__talk_type__name'),
show_speakers=F('user__talks__talk_type__show_speakers'))
bytype = groupby(speakers, lambda x: x.talk_type)
context['speaker_rows'] = {}
for talk_type, type_speakers in bytype:
context["speaker_rows"][talk_type] = self._by_row(list(type_speakers), 4)
type_speakers = list(type_speakers)
# We explicitly check for False, as no talk type will give us None for
# show_speakers and we want to default to including that
if type_speakers and type_speakers[0].show_speakers is not False:
context["speaker_rows"][talk_type] = self._by_row(type_speakers, 4)
return context


Expand Down

0 comments on commit 1c2a765

Please sign in to comment.