Skip to content

Issue #1701: Calendar events now shows the year for events which are not in the current year #1713

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

Closed
wants to merge 7 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ static/stylesheets/no-mq.css
static/stylesheets/style.css
__pycache__
*.db


# Ignore Microsoft Visual Studio Code's and Jetbrain's Pycharm Files
.vscode/
.idea/
sass/
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ factory-boy==2.9.2
Faker==0.8.1
tblib==1.3.2
responses==0.10.5
selenium==3.141.0

# Extra stuff required for local dev

Expand Down
18 changes: 18 additions & 0 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ def next_time(self):
except IndexError:
return None

def is_scheduled_to_start_this_year(self) -> bool:
current_year: int = datetime.datetime.now().year
try:
if self.next_time.dt_start.year == current_year:
return True
except Exception:
pass
return False

def is_scheduled_to_end_this_year(self) -> bool:
current_year: int = datetime.datetime.now().year
try:
if self.next_time.dt_end.year == current_year:
return True
except Exception:
pass
return False

@property
def previous_time(self):
now = timezone.now()
Expand Down
62 changes: 62 additions & 0 deletions events/tests/test_events_functional_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import datetime

from django.contrib.auth import get_user_model
from django.test import LiveServerTestCase
from django.utils import timezone
from selenium.common.exceptions import WebDriverException
from selenium.webdriver import Chrome

from ..models import Event, OccurringRule, Calendar


class EventsPageFunctionalTests(LiveServerTestCase):
@classmethod
def setUpClass(cls):
cls.now = timezone.now()
cls.user = get_user_model().objects.create_user(username='username', password='password')
cls.calendar = Calendar.objects.create(creator=cls.user, slug="test-calendar-2")
cls.event_future_start_following_year = Event.objects.create(title='Event Starts Following Year',
creator=cls.user, calendar=cls.calendar)
cls.event_future_end_following_year = Event.objects.create(title='Event Ends Following Year',
creator=cls.user, calendar=cls.calendar)
recurring_time_dtstart = cls.now + datetime.timedelta(days=3)
recurring_time_dtend = recurring_time_dtstart + datetime.timedelta(days=5)

cls.rule_future_start_year = OccurringRule.objects.create(
event=cls.event_future_start_following_year,
dt_start=recurring_time_dtstart + datetime.timedelta(weeks=52),
dt_end=recurring_time_dtstart + datetime.timedelta(weeks=53),
)
cls.rule_future_end_year = OccurringRule.objects.create(
event=cls.event_future_end_following_year,
dt_start=recurring_time_dtstart,
dt_end=recurring_time_dtend + datetime.timedelta(weeks=52)
)
super(EventsPageFunctionalTests, cls).setUpClass()

def setUp(self) -> None:
try:
self.browser = Chrome()
self.browser.implicitly_wait(5)
except WebDriverException: # GitHub Actions Django CI
from selenium import webdriver
self.browser = webdriver.FirefoxOptions()
self.browser.headless = True
webdriver.Firefox(options=self.browser)

def tearDown(self) -> None:
super().tearDown()
try:
self.browser.quit()
except Exception:
pass

def test_event_starting_and_ending_future_year_displays_year(self):
event = self.event_future_start_following_year
self.browser.get(self.live_server_url + '/events/')
future_event_span_value = self.browser.find_element_by_id(str(event.id))
self.assertIn(str(event.next_time.dt_start.year), future_event_span_value.text)

event_2 = Event.objects.get(title="Event Ends Following Year")
future_event_span_value = self.browser.find_element_by_id(str(event_2.id))
self.assertIn(str(event_2.next_time.dt_end.year), future_event_span_value.text)
23 changes: 22 additions & 1 deletion events/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_recurring_event(self):
self.assertEqual(self.event.next_time.dt_start, recurring_time_dtstart)
self.assertTrue(rt.valid_dt_end())


rt.begin = now - datetime.timedelta(days=5)
rt.finish = now - datetime.timedelta(days=3)
rt.save()
Expand Down Expand Up @@ -186,3 +185,25 @@ def test_event_previous_event(self):
# 'Event.previous_event' can return None if there is no
# OccurringRule or RecurringRule found.
self.assertIsNone(self.event.previous_event)

def test_scheduled_to_start_this_year_method(self):
now = seconds_resolution(timezone.now())

occurring_time_dtstart = now + datetime.timedelta(days=3)
OccurringRule.objects.create(
event=self.event,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart
)
self.assertTrue(self.event.is_scheduled_to_start_this_year())

def test_scheduled_to_end_this_year_method(self):
now = seconds_resolution(timezone.now())

occurring_time_dtstart = now + datetime.timedelta(days=3)
OccurringRule.objects.create(
event=self.event,
dt_start=occurring_time_dtstart,
dt_end=occurring_time_dtstart
)
self.assertTrue(self.event.is_scheduled_to_end_this_year())
19 changes: 13 additions & 6 deletions events/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.test import TestCase
from django.utils import timezone

from ..models import Calendar, Event, EventCategory, EventLocation, RecurringRule
from ..models import Calendar, Event, EventCategory, EventLocation, RecurringRule, OccurringRule
from ..templatetags.events import get_events_upcoming
from users.factories import UserFactory

Expand All @@ -18,6 +18,7 @@ def setUpTestData(cls):
cls.calendar = Calendar.objects.create(creator=cls.user, slug="test-calendar")
cls.event = Event.objects.create(creator=cls.user, calendar=cls.calendar)
cls.event_past = Event.objects.create(title='Past Event', creator=cls.user, calendar=cls.calendar)
cls.event_single_day = Event.objects.create(title="Single Day Event", creator=cls.user, calendar=cls.calendar)

cls.now = timezone.now()

Expand All @@ -34,12 +35,18 @@ def setUpTestData(cls):
begin=cls.now - datetime.timedelta(days=2),
finish=cls.now - datetime.timedelta(days=1),
)
cls.rule_single_day = OccurringRule.objects.create(
event=cls.event_single_day,
dt_start=recurring_time_dtstart,
dt_end=recurring_time_dtstart
)

def test_events_homepage(self):
url = reverse('events:events')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 1)
self.assertEqual(len(response.context['object_list']), 2)
self.assertIn(Event.objects.last().title, response.content.decode())

def test_calendar_list(self):
calendars_count = Calendar.objects.count()
Expand All @@ -54,7 +61,7 @@ def test_event_list(self):
response = self.client.get(url)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 1)
self.assertEqual(len(response.context['object_list']), 2)

url = reverse('events:event_list_past', kwargs={"calendar_slug": 'unexisting'})
response = self.client.get(url)
Expand Down Expand Up @@ -114,7 +121,7 @@ def test_event_list_date(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object'], dt.date())
self.assertEqual(len(response.context['object_list']), 2)
self.assertEqual(len(response.context['object_list']), 3)

def test_eventlocation_list(self):
venue = EventLocation.objects.create(
Expand Down Expand Up @@ -150,12 +157,12 @@ def test_event_detail(self):
self.assertEqual(self.event, response.context['object'])

def test_upcoming_tag(self):
self.assertEqual(len(get_events_upcoming()), 1)
self.assertEqual(len(get_events_upcoming()), 2)
self.assertEqual(len(get_events_upcoming(only_featured=True)), 0)
self.rule.begin = self.now - datetime.timedelta(days=3)
self.rule.finish = self.now - datetime.timedelta(days=2)
self.rule.save()
self.assertEqual(len(get_events_upcoming()), 0)
self.assertEqual(len(get_events_upcoming()), 1)


class EventSubmitTests(TestCase):
Expand Down
8 changes: 8 additions & 0 deletions templates/events/event_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ <h2 class="widget-title"><span aria-hidden="true" class="icon-calendar"></span>U
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<p>
{% with object.next_time as next_time %}
{% with object.is_scheduled_to_start_this_year as scheduled_start_this_year %}
{% with object.is_scheduled_to_end_this_year as scheduled_end_this_year %}
{% include "events/includes/time_tag.html" %}
{% endwith %}
{% endwith %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %}, {{ object.venue.address }}{% endif %}</span>
Expand All @@ -65,8 +69,12 @@ <h3 class="widget-title just-missed">You just missed...</h3>
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3>
<p>
{% with object.previous_time as next_time %}
{% with object.is_scheduled_to_start_this_year as scheduled_start_this_year %}
{% with object.is_scheduled_to_end_this_year as scheduled_end_this_year %}
{% include "events/includes/time_tag.html" %}
{% endwith %}
{% endwith %}
{% endwith %}

{% if object.venue %}
<span class="event-location">{% if object.venue.url %}<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %}, {{ object.venue.address }}{% endif %}</span>
Expand Down
31 changes: 29 additions & 2 deletions templates/events/includes/time_tag.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
{% if next_time.single_day %}
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}<span class="say-no-more"> {{ 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 }} {{ next_time.dt_end|date:"e" }}{% endif %}{% endif %}</time>
<time id="{{ object.id }}" datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}
<span {% if scheduled_start_this_year %}class="say-no-more"{% endif %}>
{{ next_time.dt_start|date:"Y" }}
</span>

<span {% 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 }}
{{ next_time.dt_end|date:"e" }}
{% endif %}
{% endif %}
</time>
{% else %}
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}{% if next_time.valid_dt_end %} &ndash; {{ next_time.dt_end|date:"d N" }}{% endif %} <span class="say-no-more"> {{ next_time.dt_end|date:"Y" }}</span></time>
<time id="{{ object.id }}" datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}
<span {% if scheduled_start_this_year %}class="say-no-more"{% endif %}>
{{ next_time.dt_start|date:"Y" }}
</span>

{% if next_time.valid_dt_end %} &ndash;
{{ next_time.dt_end|date:"d N" }}
{% endif %}

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