Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2626: Fix Multi Year String Render For Single Day Events #2627

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions events/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,200 @@ def test_events_scheduled_current_year_does_not_display_current_year(self):
response.content.decode()
)

def test_single_day_event_only_renders_event_date_year_string_if_relevant(self):
url = reverse('events:events')
single_day_event_starting_and_ending_in_current_year = Event.objects.create(
title='Single Day Event Starting & Ending In Current Year', creator=self.user, calendar=self.calendar)
single_day_all_day_event_starting_and_ending_in_current_year = Event.objects.create(
title='Single Day All Day Event Starting & Ending In Current Year',
creator=self.user,
calendar=self.calendar)
single_day_event_starting_and_ending_in_future_year = Event.objects.create(
title='Single Day Event Staring And Ending In Future Year', creator=self.user,
calendar=self.calendar)
single_day_all_day_event_starting_and_ending_in_future_year = Event.objects.create(
title='Single Day All Day Event Starting And Ending In Future Year',
creator=self.user,
calendar=self.calendar)

occurring_time_dtstart = self.now + datetime.timedelta(minutes=2)

OccurringRule.objects.create(
event=single_day_event_starting_and_ending_in_current_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(minutes=5)
)
OccurringRule.objects.create(
all_day=True,
event=single_day_all_day_event_starting_and_ending_in_current_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(minutes=5)
)
OccurringRule.objects.create(
event=single_day_event_starting_and_ending_in_future_year,
dt_start=occurring_time_dtstart + datetime.timedelta(days=366),
dt_end=occurring_time_dtstart + datetime.timedelta(minutes=10)
)
OccurringRule.objects.create(
all_day=True,
event=single_day_all_day_event_starting_and_ending_in_future_year,
dt_start=occurring_time_dtstart + datetime.timedelta(days=366),
dt_end=occurring_time_dtstart + datetime.timedelta(minutes=10)
)

response = self.client.get(url)

# Single Day Event Starting & Ending In Current Year
self.assertIn(
f'<span id="start-{single_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_event_starting_and_ending_in_current_year.id}">',
response.content.decode())

# Single Day All Day Event Starting & Ending In Current Year
self.assertIn(
f'<span id="start-{single_day_all_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_all_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_all_day_event_starting_and_ending_in_current_year.id}">',
response.content.decode())

# Single Day Event Staring And Ending In Future Year
self.assertIn(
f'<span id="start-{single_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())

# Single Day All Day Event Starting And Ending In Future Year
self.assertIn(
f'<span id="start-{single_day_all_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{single_day_all_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())

def test_multi_day_event_only_render_end_year_information_when_dt_end_is_valid(self):
url = reverse('events:events')
multi_day_event_starting_and_ending_in_current_year = Event.objects.create(
title='Multi-Day Event Starting & Ending In Current Year', creator=self.user, calendar=self.calendar)
multi_day_all_day_event_starting_and_ending_in_current_year = Event.objects.create(
title='Multi-Day All Day Event Starting & Ending In Current Year',
creator=self.user,
calendar=self.calendar)
multi_day_event_starting_in_current_year_and_ending_in_future_year = Event.objects.create(
title='Multi-Day Event Staring In Current Year And Ending In Future Year', creator=self.user,
calendar=self.calendar)
multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year = Event.objects.create(
title='Multi-Day All Day Event Starting In Current Year And Ending In Future Year',
creator=self.user,
calendar=self.calendar)
multi_day_event_starting_and_ending_in_future_year = Event.objects.create(
title='Multi-Day Event Staring And Ending In Future Year', creator=self.user,
calendar=self.calendar)
multi_day_all_day_event_starting_and_ending_in_future_year = Event.objects.create(
title='Multi-Day All Day Event Starting And Ending In Future Year',
creator=self.user,
calendar=self.calendar)

occurring_time_dtstart = self.now + datetime.timedelta(minutes=2)

OccurringRule.objects.create(
event=multi_day_event_starting_and_ending_in_current_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(days=1)
)
OccurringRule.objects.create(
all_day=True,
event=multi_day_all_day_event_starting_and_ending_in_current_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(days=1)
)
OccurringRule.objects.create(
event=multi_day_event_starting_in_current_year_and_ending_in_future_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(days=366)
)
OccurringRule.objects.create(
all_day=True,
event=multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart + datetime.timedelta(days=366)
)
OccurringRule.objects.create(
event=multi_day_event_starting_and_ending_in_future_year,
dt_start=occurring_time_dtstart + datetime.timedelta(days=366),
dt_end=occurring_time_dtstart + datetime.timedelta(days=367)
)
OccurringRule.objects.create(
all_day=True,
event=multi_day_all_day_event_starting_and_ending_in_future_year,
dt_start=occurring_time_dtstart + datetime.timedelta(days=366),
dt_end=occurring_time_dtstart + datetime.timedelta(days=367)
)
response = self.client.get(url)

# Multi-Day All Day Event Starting & Ending In Current Year
self.assertIn(
f'<span id="start-{multi_day_all_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertIn(
f'<span id="end-{multi_day_all_day_event_starting_and_ending_in_current_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="start-{multi_day_all_day_event_starting_and_ending_in_current_year.id}">',
response.content.decode())
self.assertNotIn(
f'<span id="end-{multi_day_all_day_event_starting_and_ending_in_current_year.id}">',
response.content.decode())

# Multi-Day Event Staring In Current Year And Ending In Future Year
self.assertIn(
f'<span id="end-{multi_day_event_starting_in_current_year_and_ending_in_future_year.id}">',
response.content.decode())
self.assertIn(
f'<span id="start-{multi_day_event_starting_in_current_year_and_ending_in_future_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="start-{multi_day_event_starting_in_current_year_and_ending_in_future_year.id}">',
response.content.decode())

# Multi-Day All Day Event Starting In Current Year And Ending In Future Year
self.assertIn(
f'<span id="end-{multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year.id}">',
response.content.decode())
self.assertIn(
f'<span id="start-{multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year.id}" class="say-no-more">',
response.content.decode())
self.assertNotIn(
f'<span id="start-{multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year.id}">',
response.content.decode())

# Multi-Day Event Staring And Ending In Future Year
self.assertIn(
f'<span id="start-{multi_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())
self.assertIn(
f'<span id="end-{multi_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())

# Multi-Day All Day Event Starting And Ending In Future Year
self.assertIn(
f'<span id="start-{multi_day_all_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())
self.assertIn(
f'<span id="end-{multi_day_all_day_event_starting_and_ending_in_future_year.id}">',
response.content.decode())


class EventSubmitTests(TestCase):
event_submit_url = reverse_lazy('events:event_submit')

Expand Down
10 changes: 3 additions & 7 deletions templates/events/includes/time_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
{{ next_time.dt_start|date:"Y" }}
</span>

<span id="start-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}>
{{ next_time.dt_start|date:"Y" }}
</span>

{% if not next_time.all_day %}
{{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}
{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }}
Expand All @@ -23,10 +19,10 @@

{% if next_time.valid_dt_end %} &ndash;
{{ next_time.dt_end|date:"d N" }}
<span id="end-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}>
{{ next_time.dt_end|date:"Y" }}
</span>
{% endif %}

<span id="end-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}>
{{ next_time.dt_end|date:"Y" }}
</span>
</time>
{% endif %}