From 43ccb8d49d8fb5bd74e4ea9e21655f5e9b1a5ac8 Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Wed, 15 Mar 2023 21:48:19 +0800 Subject: [PATCH 01/17] chore(events): remove schedule views --- src/events/urls.py | 4 -- src/events/views.py | 162 +------------------------------------------- 2 files changed, 2 insertions(+), 164 deletions(-) diff --git a/src/events/urls.py b/src/events/urls.py index a32dbdee2..4c112d9d3 100644 --- a/src/events/urls.py +++ b/src/events/urls.py @@ -4,10 +4,6 @@ from events import views urlpatterns = [ - url(r'^schedule/$', views.ScheduleView.as_view(), name='events_schedule'), - url(r'^schedule/new/$', views.ScheduleCreateView.as_view()), - - url(r'^talks/$', views.TalkListView.as_view(), name='events_talk_list'), url(r'^tutorials/$', views.TutorialListView.as_view(), diff --git a/src/events/views.py b/src/events/views.py index dc4f5ed7a..9604dfbf7 100644 --- a/src/events/views.py +++ b/src/events/views.py @@ -1,33 +1,12 @@ -import collections -import itertools import logging -from django.conf import settings -from django.contrib.auth.mixins import PermissionRequiredMixin from django.db.models import Count, Prefetch -from django.http import HttpResponseNotFound, HttpResponseRedirect -from django.urls import reverse -from django.utils import translation -from django.utils.translation import gettext_lazy as _ -from django.views.generic import CreateView, DetailView, ListView, TemplateView +from django.views.generic import DetailView, ListView -from core.mixins import FormValidMessageMixin from core.utils import OrderedDefaultDict, TemplateExistanceStatusResponse from proposals.models import AdditionalSpeaker, TalkProposal, TutorialProposal -from .forms import ScheduleCreationForm -from .models import ( - EVENT_ROOMS, - CustomEvent, - KeynoteEvent, - Location, - ProposedTalkEvent, - ProposedTutorialEvent, - Schedule, - SponsoredEvent, - Time, -) -from .renderers import render_all +from .models import ProposedTalkEvent, ProposedTutorialEvent, SponsoredEvent logger = logging.getLogger(__name__) @@ -96,143 +75,6 @@ def get_queryset(self): return qs -class ScheduleView(TemplateView): - template_name = 'events/schedule.html' - response_class = TemplateExistanceStatusResponse - - def get(self, request, *args, **kwargs): - try: - self.schedule = Schedule.objects.latest() - except Schedule.DoesNotExist: - redirect_url = settings.SCHEDULE_REDIRECT_URL - if not redirect_url: - return HttpResponseNotFound() - return HttpResponseRedirect(redirect_url) - return super().get(request, *args, **kwargs) - - def get_context_data(self, **kwargs): - return super().get_context_data( - schedule_html=self.schedule.html, - schedule_days=collections.OrderedDict([ - (key, {'name': value}) - for key, value in settings.EVENTS_DAY_NAMES.items() - ]), - **kwargs - ) - - -class ScheduleCreateMixin: - form_class = ScheduleCreationForm - form_valid_message = _('New talk schedule generated successfully.') - permission_required = ['events.add_schedule'] - template_name = 'events/schedule_create.html' - response_class = TemplateExistanceStatusResponse - - def get_success_url(self): - return reverse('events_schedule') - - -class ScheduleCreate2016View( - ScheduleCreateMixin, FormValidMessageMixin, PermissionRequiredMixin, CreateView -): - def get_context_data(self, **kwargs): - return super().get_context_data(content=render_all(), **kwargs) - - -def _room_sort_key(room): - return room.split('-', 1)[-1] - - -class ScheduleCreateView( - ScheduleCreateMixin, FormValidMessageMixin, PermissionRequiredMixin, CreateView -): - event_querysets = [ - CustomEvent.objects.all().exclude(location=Location.OTHER), - KeynoteEvent.objects.all().exclude(location=Location.OTHER), - ( - ProposedTalkEvent.objects - .select_related('proposal__submitter') - .annotate(_additional_speaker_count=Count( - 'proposal__additionalspeaker_set', - )).exclude(location=Location.OTHER) - ), - SponsoredEvent.objects.select_related('host').exclude(location=Location.OTHER), - ( - ProposedTutorialEvent.objects - .select_related('proposal__submitter') - .annotate(_additional_speaker_count=Count( - 'proposal__additionalspeaker_set', - )).exclude(location=Location.OTHER) - ), - ] - - def get_day_grouped_events(self): - begin_time_event_dict = collections.defaultdict(set) - for qs in self.event_querysets: - for event in qs.select_related('begin_time', 'end_time'): - begin_time_event_dict[event.begin_time].add(event) - - day_info_dict = collections.OrderedDict( - (date, { - 'name': name, - 'rooms': set(), - 'slots': {}, - 'slots_mobile': {}, - 'timeline': {}, - }) for date, name in settings.EVENTS_DAY_NAMES.items() - ) - - times = list(Time.objects.order_by('value')) - end_time_iter = iter(times) - next(end_time_iter, None) - - for begin, __ in zip(times, end_time_iter): - try: - day_info = day_info_dict[begin.value.date()] - except KeyError: - logger.warn(f'Invalid time sot dropped: {begin}') - continue - for event in begin_time_event_dict[begin]: - location = event.location - day_info['slots'].setdefault(location, []) - day_info['slots_mobile'].setdefault(event.begin_time, []) - day_info['timeline'].setdefault('begin', event.begin_time) - day_info['timeline'].setdefault('end', event.end_time) - - day_info['slots'][location].append(event) - day_info['slots_mobile'][event.begin_time].append(event) - day_info['timeline']['begin'] = min( - day_info['timeline']['begin'], - event.begin_time - ) - day_info['timeline']['end'] = max( - day_info['timeline']['end'], - event.end_time - ) - if location in EVENT_ROOMS: - day_info['rooms'].add(location) - - for info in day_info_dict.values(): - # Sort rooms. - info['rooms'] = sorted(info['rooms'], key=_room_sort_key) - - return day_info_dict - - def get_context_data(self, **kwargs): - with translation.override('en-us'): - schedule_days = self.get_day_grouped_events() - - all_rooms = sorted(set(itertools.chain.from_iterable( - info['rooms'] for info in schedule_days.values() - )), key=_room_sort_key) - - return super().get_context_data( - schedule_days=schedule_days, - all_rooms=all_rooms, - **kwargs - ) - - class EventInfoMixin: def is_event_sponsored(self): From 1975a3be780c617f366f7089cf86a03fa7afaa99 Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Wed, 15 Mar 2023 21:49:09 +0800 Subject: [PATCH 02/17] test(events): remove tests of schedule views --- src/core/tests/test_views.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/core/tests/test_views.py b/src/core/tests/test_views.py index 16f148970..6c6caf00e 100644 --- a/src/core/tests/test_views.py +++ b/src/core/tests/test_views.py @@ -2,11 +2,7 @@ import os import pytest -from django.conf import settings from django.utils.translation import activate -from pytest_django.asserts import assertRedirects - -from events.models import Schedule @pytest.mark.django_db @@ -97,14 +93,7 @@ def test_content_pages(client, parser, content_page_full_path): assert response.status_code == 200, content_page_full_path -@pytest.fixture -def schedule(db): - """Generate a schedule to prevent the schedule page from returning 404. - """ - return Schedule.objects.create(html='
') - - -def test_content_pages_links(client, parser, schedule, content_page_full_path): +def test_content_pages_links(client, parser, content_page_full_path): """Test to make sure all in-site links in a content page work. """ if '/surveys/conference/' in content_page_full_path: @@ -116,14 +105,6 @@ def test_content_pages_links(client, parser, schedule, content_page_full_path): link_status_codes = [] for tag in link_tags: link = tag.get('href') - if "/events/schedule/" in link \ - and settings.SCHEDULE_REDIRECT_URL: - assertRedirects( - client.get(link), - settings.SCHEDULE_REDIRECT_URL, - fetch_redirect_response=False - ) - continue try: status = client.get(link, follow=True).status_code except Exception: # Catch internal server error for better reporting. From ae66bcd7254884720560e17e721825cea2e907ed Mon Sep 17 00:00:00 2001 From: Matt Wang Date: Wed, 15 Mar 2023 21:51:43 +0800 Subject: [PATCH 03/17] chore(events): remove schedule view templates --- .../pycontw-2021/_includes/menu.html | 2 - .../pycontw-2021/_includes/portal.html | 4 - .../_includes/schedule_custom_event.html | 24 ---- .../_includes/schedule_keynote_event.html | 25 ---- .../events/_includes/schedule_talk_event.html | 36 ------ .../pycontw-2021/events/schedule.html | 48 -------- .../pycontw-2021/events/schedule_create.html | 113 ------------------ .../pycontw-2022/_includes/menu.html | 2 - .../pycontw-2022/_includes/portal.html | 4 - .../_includes/schedule_custom_event.html | 24 ---- .../_includes/schedule_keynote_event.html | 25 ---- .../events/_includes/schedule_talk_event.html | 36 ------ .../pycontw-2022/events/schedule.html | 48 -------- .../pycontw-2022/events/schedule_create.html | 113 ------------------ .../pycontw-2023/_includes/menu.html | 2 - .../pycontw-2023/_includes/portal.html | 4 - .../_includes/schedule_custom_event.html | 24 ---- .../_includes/schedule_keynote_event.html | 25 ---- .../events/_includes/schedule_talk_event.html | 36 ------ .../pycontw-2023/events/schedule.html | 48 -------- .../pycontw-2023/events/schedule_create.html | 113 ------------------ .../pycontw-2024/_includes/menu.html | 2 - .../pycontw-2024/_includes/portal.html | 4 - .../_includes/schedule_custom_event.html | 24 ---- .../_includes/schedule_keynote_event.html | 25 ---- .../events/_includes/schedule_talk_event.html | 36 ------ .../pycontw-2024/events/schedule.html | 48 -------- .../pycontw-2024/events/schedule_create.html | 113 ------------------ 28 files changed, 1008 deletions(-) delete mode 100644 src/templates/pycontw-2021/events/_includes/schedule_custom_event.html delete mode 100644 src/templates/pycontw-2021/events/_includes/schedule_keynote_event.html delete mode 100644 src/templates/pycontw-2021/events/_includes/schedule_talk_event.html delete mode 100644 src/templates/pycontw-2021/events/schedule.html delete mode 100644 src/templates/pycontw-2021/events/schedule_create.html delete mode 100644 src/templates/pycontw-2022/events/_includes/schedule_custom_event.html delete mode 100644 src/templates/pycontw-2022/events/_includes/schedule_keynote_event.html delete mode 100644 src/templates/pycontw-2022/events/_includes/schedule_talk_event.html delete mode 100644 src/templates/pycontw-2022/events/schedule.html delete mode 100644 src/templates/pycontw-2022/events/schedule_create.html delete mode 100644 src/templates/pycontw-2023/events/_includes/schedule_custom_event.html delete mode 100644 src/templates/pycontw-2023/events/_includes/schedule_keynote_event.html delete mode 100644 src/templates/pycontw-2023/events/_includes/schedule_talk_event.html delete mode 100644 src/templates/pycontw-2023/events/schedule.html delete mode 100644 src/templates/pycontw-2023/events/schedule_create.html delete mode 100644 src/templates/pycontw-2024/events/_includes/schedule_custom_event.html delete mode 100644 src/templates/pycontw-2024/events/_includes/schedule_keynote_event.html delete mode 100644 src/templates/pycontw-2024/events/_includes/schedule_talk_event.html delete mode 100644 src/templates/pycontw-2024/events/schedule.html delete mode 100644 src/templates/pycontw-2024/events/schedule_create.html diff --git a/src/templates/pycontw-2021/_includes/menu.html b/src/templates/pycontw-2021/_includes/menu.html index a55756f5c..ab336e69a 100644 --- a/src/templates/pycontw-2021/_includes/menu.html +++ b/src/templates/pycontw-2021/_includes/menu.html @@ -13,7 +13,6 @@ {% url 'page' path='speaking/tutorial' as speaking_tutorial_url %} {% url 'page' path='speaking/recording' as speaking_recording_url %} -{% url 'events_schedule' as events_schedule_url %} {% url 'page' path='conference/keynotes' as events_keynote_url %} {% url 'events_talk_list' as events_talk_list_url %} {% url 'events_tutorial_list' as events_tutorial_list_url %} @@ -78,7 +77,6 @@