Skip to content

Commit

Permalink
Merge pull request #712 from drnlm/feature/add_tracks_to_talks_list
Browse files Browse the repository at this point in the history
Feature/add tracks to talks list
  • Loading branch information
drnlm authored Jun 3, 2024
2 parents eb5f7d3 + c3a8092 commit d4207b9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 3 deletions.
7 changes: 6 additions & 1 deletion wafer/talks/templates/wafer.talks/talks.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h1>{% trans "Accepted Talks" %}</h1>
{% trans "Talk" %}
{% endif %}
</th>
{% if tracks %}<th>{% trans "Track" %}</th>{% endif %}
{% if languages %}<th>{% trans "Language" %}</th>{% endif %}
<th>{% trans "Speakers" %}</th>
</tr>
Expand Down Expand Up @@ -52,6 +53,9 @@ <h1>{% trans "Accepted Talks" %}</h1>
<a href="{{ talk.get_absolute_url }}">{{ talk.title }}</a>
{% endif %}
</td>
{% if tracks %}
<td>{{ talk.track.name }}</td>
{% endif %}
{% if languages %}
<td>{{ talk.get_language_display }}</td>
{% endif %}
Expand All @@ -68,12 +72,13 @@ <h1>{% trans "Accepted Talks" %}</h1>
<th>
{% trans "Talk" %}
</th>
{% if tracks %}<th>{% trans "Track" %}</th>{% endif %}
{% if languages %}<th>{% trans "Language" %}</th>{% endif %}
<th>{% trans "Speakers" %}</th>
</tr>
</thead>
<tr>
<td colspan="{% if languages %}3{% else %}2{% endif %}">
<td colspan="{% if tracks and languages %}4{% elif tracks or languages %}3{% else %}2{% endif %}">
{% trans 'No talks accepted yet.' %}
</td>
</tr>
Expand Down
112 changes: 110 additions & 2 deletions wafer/talks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import mock

from django.test import Client, TestCase
from django.test import Client, TestCase, override_settings
from django.urls import reverse

from wafer.tests.api_utils import SortedResultsClient
from wafer.tests.utils import create_user, mock_avatar_url
from wafer.talks.models import (
Talk, TalkUrl, ACCEPTED, REJECTED, SUBMITTED, UNDER_CONSIDERATION,
Talk, TalkUrl, Track, ACCEPTED, REJECTED, SUBMITTED, UNDER_CONSIDERATION,
CANCELLED, PROVISIONAL, WITHDRAWN)
from wafer.talks.tests.fixtures import create_talk, create_talk_type

Expand Down Expand Up @@ -52,6 +52,114 @@ def test_user_with_view_all(self):
self.talk_s, self.talk_u, self.talk_c]))


class TalksListLayoutTests(TestCase):
"""Test the table layout with different options
We test this with both no talks and talks so we can check both headers and the
span for the 'No Accepted Talks' line.
Some tests moneky-patch Talk.LANGUAGES - this is to avoid needing to re-import
Talk with modified settings to achieve the same result"""

def setUp(self):
self.client = Client()

def tearDown(self):
"""Ensure Talk monkey-patching doesn't leak"""
Talk.LANGUAGES = ()

def test_no_options(self):
"""Test that we have the right layout if no tracks or languages"""
response = self.client.get('/talks/')
self.assertFalse(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 0)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertNotContains(response, 'Track', html=True)
self.assertNotContains(response, 'Language', html=True)
self.assertContains(response, '<td colspan="2">\nNo talks accepted yet.\n</td>', html=True)

talk1 = create_talk('Talk 1', ACCEPTED, 'author_a')
response = self.client.get('/talks/')
self.assertFalse(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 0)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertNotContains(response, 'Track', html=True)
self.assertNotContains(response, 'Language', html=True)
self.assertNotContains(response, '<td colspan="2">\nNo talks accepted yet.\n</td>', html=True)

def test_langauge(self):
"""Test that we have the right layout if langauges, but no tracks"""
Talk.LANGUAGES = (('en', 'English'),)

response = self.client.get('/talks/')
self.assertFalse(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 1)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertNotContains(response, 'Track', html=True)
self.assertContains(response, 'Language', html=True)
self.assertContains(response, '<td colspan="3">\nNo talks accepted yet.\n</td>', html=True)

talk1 = create_talk('Talk 1', ACCEPTED, 'author_a')
response = self.client.get('/talks/')
self.assertFalse(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 1)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertNotContains(response, 'Track', html=True)
self.assertContains(response, 'Language', html=True)
self.assertNotContains(response, '<td colspan="3">\nNo talks accepted yet.\n</td>', html=True)

def test_track(self):
"""Test that we have the right layout if tracks, but no languages"""
track1 = Track.objects.create(name="Test Trakc 1")
response = self.client.get('/talks/')
self.assertTrue(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 0)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertContains(response, 'Track', html=True)
self.assertNotContains(response, 'Language', html=True)
self.assertContains(response, '<td colspan="3">\nNo talks accepted yet.\n</td>', html=True)

talk1 = create_talk('Talk 1', ACCEPTED, 'author_a')
response = self.client.get('/talks/')
self.assertTrue(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 0)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertContains(response, 'Track', html=True)
self.assertNotContains(response, 'Language', html=True)
self.assertNotContains(response, '<td colspan="3">\nNo talks accepted yet.\n</td>', html=True)


def test_track_and_language(self):
"""Test that we have the right layout if we have tracks and languages"""
track1 = Track.objects.create(name="Test Trakc 1")
Talk.LANGUAGES = (('en', 'English'),)

response = self.client.get('/talks/')
self.assertTrue(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 1)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertContains(response, 'Track', html=True)
self.assertContains(response, 'Language', html=True)
self.assertContains(response, '<td colspan="4">\nNo talks accepted yet.\n</td>', html=True)

talk1 = create_talk('Talk 1', ACCEPTED, 'author_a')
response = self.client.get('/talks/')
self.assertTrue(response.context['tracks'])
self.assertEqual(len(response.context['languages']), 1)
self.assertContains(response, 'Talk', html=True)
self.assertContains(response, 'Speakers', html=True)
self.assertContains(response, 'Track', html=True)
self.assertContains(response, 'Language', html=True)
self.assertNotContains(response, '<td colspan="4">\nNo talks accepted yet.\n</td>', html=True)


class TalkViewTests(TestCase):
def setUp(self):
public_type = create_talk_type(name="BoF", show_pending_submissions=True)
Expand Down
1 change: 1 addition & 0 deletions wafer/talks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["languages"] = Talk.LANGUAGES
context["tracks"] = Track.objects.count() > 0
context["see_all"] = Talk.can_view_all(self.request.user)
return context

Expand Down

0 comments on commit d4207b9

Please sign in to comment.