Compare commits

...

4 Commits

Author SHA1 Message Date
Mira Weller
feb2ec0d48 Adapt remaining tests 2024-08-27 22:01:05 +02:00
Mira Weller
f3eb6b33e6 Adapt test cases 2024-08-27 22:01:05 +02:00
Mira Weller
3a774db641 Refactor 2024-08-27 22:01:05 +02:00
Mira Weller
6245d1f286 Show weekday in subevent dates 2024-08-27 22:01:04 +02:00
5 changed files with 29 additions and 34 deletions

View File

@@ -60,7 +60,6 @@ from django.urls import reverse
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.formats import date_format from django.utils.formats import date_format
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.html import format_html
from django.utils.timezone import make_aware, now from django.utils.timezone import make_aware, now
from django.utils.translation import gettext, gettext_lazy as _ from django.utils.translation import gettext, gettext_lazy as _
from django_scopes import ScopedManager, scopes_disabled from django_scopes import ScopedManager, scopes_disabled
@@ -180,14 +179,10 @@ class EventMixin:
""" """
tz = tz or self.timezone tz = tz or self.timezone
if (not self.settings.show_date_to and not force_show_end) or not self.date_to: if (not self.settings.show_date_to and not force_show_end) or not self.date_to:
if as_html: df, dt = self.date_from, self.date_from
return format_html( else:
"<time datetime=\"{}\">{}</time>", df, dt = self.date_from, self.date_to
_date(self.date_from.astimezone(tz), "Y-m-d"), return daterange(df.astimezone(tz), dt.astimezone(tz), as_html)
_date(self.date_from.astimezone(tz), "DATE_FORMAT"),
)
return _date(self.date_from.astimezone(tz), "DATE_FORMAT")
return daterange(self.date_from.astimezone(tz), self.date_to.astimezone(tz), as_html)
def get_date_range_display_as_html(self, tz=None, force_show_end=False) -> str: def get_date_range_display_as_html(self, tz=None, force_show_end=False) -> str:
return self.get_date_range_display(tz, force_show_end, as_html=True) return self.get_date_range_display(tz, force_show_end, as_html=True)

View File

@@ -53,14 +53,14 @@ def daterange(df, dt, as_html=False):
if lng.startswith("de"): if lng.startswith("de"):
if df.year == dt.year and df.month == dt.month and df.day == dt.day: if df.year == dt.year and df.month == dt.month and df.day == dt.day:
return format_html(base_format, _date(df, "j. F Y")) return format_html(base_format, _date(df, "D, j. F Y"))
elif df.year == dt.year and df.month == dt.month: elif df.year == dt.year and df.month == dt.month:
return format_html(base_format, _date(df, "j."), "", _date(dt, "j. F Y")) return format_html(base_format, _date(df, "j."), "", _date(dt, "j. F Y"))
elif df.year == dt.year: elif df.year == dt.year:
return format_html(base_format, _date(df, "j. F"), " ", _date(dt, "j. F Y")) return format_html(base_format, _date(df, "j. F"), " ", _date(dt, "j. F Y"))
elif lng.startswith("en"): elif lng.startswith("en"):
if df.year == dt.year and df.month == dt.month and df.day == dt.day: if df.year == dt.year and df.month == dt.month and df.day == dt.day:
return format_html(base_format, _date(df, "N jS, Y")) return format_html(base_format, _date(df, "D, N jS, Y"))
elif df.year == dt.year and df.month == dt.month: elif df.year == dt.year and df.month == dt.month:
return format_html(base_format, _date(df, "N jS"), " ", _date(dt, "jS, Y")) return format_html(base_format, _date(df, "N jS"), " ", _date(dt, "jS, Y"))
elif df.year == dt.year: elif df.year == dt.year:

View File

@@ -43,15 +43,15 @@ from pretix.helpers.daterange import daterange, datetimerange
def test_same_day_german(): def test_same_day_german():
with translation.override('de'): with translation.override('de'):
df = date(2003, 2, 1) df = date(2003, 2, 1)
assert daterange(df, df) == "1. Februar 2003" assert daterange(df, df) == "Sa, 1. Februar 2003"
assert daterange(df, df, as_html=True) == '<time datetime="2003-02-01">1. Februar 2003</time>' assert daterange(df, df, as_html=True) == '<time datetime="2003-02-01">Sa, 1. Februar 2003</time>'
def test_same_day_english(): def test_same_day_english():
with translation.override('en'): with translation.override('en'):
df = date(2003, 2, 1) df = date(2003, 2, 1)
assert daterange(df, df) == "Feb. 1st, 2003" assert daterange(df, df) == "Sat, Feb. 1st, 2003"
assert daterange(df, df, as_html=True) == '<time datetime="2003-02-01">Feb. 1st, 2003</time>' assert daterange(df, df, as_html=True) == '<time datetime="2003-02-01">Sat, Feb. 1st, 2003</time>'
def test_same_day_spanish(): def test_same_day_spanish():

View File

@@ -1599,7 +1599,7 @@ class EventLocaleTest(EventTestMixin, SoupTest):
'/%s/%s/' % (self.orga.slug, self.event.slug) '/%s/%s/' % (self.orga.slug, self.event.slug)
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIn('Dec. 26,', response.rendered_content) self.assertIn('Fri, Dec. 26th,', response.rendered_content)
self.assertIn('14:00', response.rendered_content) self.assertIn('14:00', response.rendered_content)
def test_english_region_US(self): def test_english_region_US(self):
@@ -1609,7 +1609,7 @@ class EventLocaleTest(EventTestMixin, SoupTest):
'/%s/%s/' % (self.orga.slug, self.event.slug) '/%s/%s/' % (self.orga.slug, self.event.slug)
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIn('Dec. 26,', response.rendered_content) self.assertIn('Fri, Dec. 26th,', response.rendered_content)
self.assertIn('2 p.m.', response.rendered_content) self.assertIn('2 p.m.', response.rendered_content)
def test_german_region_US(self): def test_german_region_US(self):
@@ -1619,5 +1619,5 @@ class EventLocaleTest(EventTestMixin, SoupTest):
'/%s/%s/' % (self.orga.slug, self.event.slug) '/%s/%s/' % (self.orga.slug, self.event.slug)
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIn('26. Dezember', response.rendered_content) self.assertIn('Fr, 26. Dezember', response.rendered_content)
self.assertIn('14:00', response.rendered_content) self.assertIn('14:00', response.rendered_content)

View File

@@ -169,7 +169,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"target_url": "http://example.com/ccc/30c3/", "target_url": "http://example.com/ccc/30c3/",
"subevent": None, "subevent": None,
"name": "30C3", "name": "30C3",
"date_range": f"Dec. 26, {self.event.date_from.year} 00:00", "date_range": f"{self.event.date_from.strftime('%a')}, Dec. 26th, {self.event.date_from.year} 00:00",
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
@@ -375,7 +375,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"target_url": "http://example.com/ccc/30c3/", "target_url": "http://example.com/ccc/30c3/",
"subevent": None, "subevent": None,
"name": "30C3", "name": "30C3",
"date_range": f"Dec. 26, {self.event.date_from.year} 00:00", "date_range": f"{self.event.date_from.strftime('%a')}, Dec. 26th, {self.event.date_from.year} 00:00",
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
@@ -435,7 +435,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"target_url": "http://example.com/ccc/30c3/", "target_url": "http://example.com/ccc/30c3/",
"subevent": None, "subevent": None,
"name": "30C3", "name": "30C3",
"date_range": f"Dec. 26, {self.event.date_from.year} 00:00", "date_range": f"{self.event.date_from.strftime('%a')}, Dec. 26th, {self.event.date_from.year} 00:00",
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
@@ -520,7 +520,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"target_url": "http://example.com/ccc/30c3/", "target_url": "http://example.com/ccc/30c3/",
"subevent": None, "subevent": None,
"name": "30C3", "name": "30C3",
"date_range": f"Dec. 26, {self.event.date_from.year} 00:00", "date_range": f"{self.event.date_from.strftime('%a')}, Dec. 26th, {self.event.date_from.year} 00:00",
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
@@ -627,9 +627,9 @@ class WidgetCartTest(CartTestMixin, TestCase):
'poweredby': '<a href="https://pretix.eu" target="_blank" rel="noopener">ticketing powered by pretix</a>', 'poweredby': '<a href="https://pretix.eu" target="_blank" rel="noopener">ticketing powered by pretix</a>',
'has_more_events': False, 'has_more_events': False,
'events': [ 'events': [
{'name': 'Present', 'date_range': 'Jan. 1, 2019 11:00', 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'name': 'Present', 'date_range': 'Tue, Jan. 1st, 2019 11:00', 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk, 'location': ''}, 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk, 'location': ''},
{'name': 'Future', 'date_range': 'Jan. 4, 2019 11:00', 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'name': 'Future', 'date_range': 'Fri, Jan. 4th, 2019 11:00', 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk, 'location': ''} 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk, 'location': ''}
] ]
} }
@@ -659,14 +659,14 @@ class WidgetCartTest(CartTestMixin, TestCase):
[ [
None, None,
{'day': 1, 'date': '2019-01-01', 'events': [ {'day': 1, 'date': '2019-01-01', 'events': [
{'name': 'Present', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 1, 2019 11:00', {'name': 'Present', 'time': '11:00', 'continued': False, 'date_range': 'Tue, Jan. 1st, 2019 11:00',
'location': '', 'location': '',
'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk}]}, 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk}]},
{'day': 2, 'date': '2019-01-02', 'events': []}, {'day': 2, 'date': '2019-01-02', 'events': []},
{'day': 3, 'date': '2019-01-03', 'events': []}, {'day': 3, 'date': '2019-01-03', 'events': []},
{'day': 4, 'date': '2019-01-04', 'events': [ {'day': 4, 'date': '2019-01-04', 'events': [
{'name': 'Future', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 4, 2019 11:00', {'name': 'Future', 'time': '11:00', 'continued': False, 'date_range': 'Fri, Jan. 4th, 2019 11:00',
'location': '', 'location': '',
'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk}]}, 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk}]},
@@ -734,14 +734,14 @@ class WidgetCartTest(CartTestMixin, TestCase):
'days': [ 'days': [
{'day_formatted': 'Mon, Dec 31st', 'date': '2018-12-31', 'events': [], 'today': False}, {'day_formatted': 'Mon, Dec 31st', 'date': '2018-12-31', 'events': [], 'today': False},
{'day_formatted': 'Tue, Jan 1st', 'date': '2019-01-01', 'events': [ {'day_formatted': 'Tue, Jan 1st', 'date': '2019-01-01', 'events': [
{'name': 'Present', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 1, 2019 11:00', {'name': 'Present', 'time': '11:00', 'continued': False, 'date_range': 'Tue, Jan. 1st, 2019 11:00',
'location': '', 'location': '',
'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk}], 'today': True}, 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk}], 'today': True},
{'day_formatted': 'Wed, Jan 2nd', 'date': '2019-01-02', 'events': [], 'today': False}, {'day_formatted': 'Wed, Jan 2nd', 'date': '2019-01-02', 'events': [], 'today': False},
{'day_formatted': 'Thu, Jan 3rd', 'date': '2019-01-03', 'events': [], 'today': False}, {'day_formatted': 'Thu, Jan 3rd', 'date': '2019-01-03', 'events': [], 'today': False},
{'day_formatted': 'Fri, Jan 4th', 'date': '2019-01-04', 'events': [ {'day_formatted': 'Fri, Jan 4th', 'date': '2019-01-04', 'events': [
{'name': 'Future', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 4, 2019 11:00', {'name': 'Future', 'time': '11:00', 'continued': False, 'date_range': 'Fri, Jan. 4th, 2019 11:00',
'location': '', 'location': '',
'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk}], 'today': False}, 'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk}], 'today': False},
@@ -778,12 +778,12 @@ class WidgetCartTest(CartTestMixin, TestCase):
'location': '', 'location': '',
'name': '30C3'}, 'name': '30C3'},
{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'date_range': 'Jan. 1, 2019 10:00', 'date_range': 'Tue, Jan. 1st, 2019 10:00',
'location': '', 'location': '',
'event_url': 'http://example.com/ccc/present/', 'event_url': 'http://example.com/ccc/present/',
'name': 'Present'}, 'name': 'Present'},
{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'date_range': 'Jan. 4, 2019 10:00', 'date_range': 'Fri, Jan. 4th, 2019 10:00',
'location': '', 'location': '',
'event_url': 'http://example.com/ccc/future/', 'event_url': 'http://example.com/ccc/future/',
'name': 'Future'} 'name': 'Future'}
@@ -884,7 +884,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
'day': 1, 'day': 1,
'events': [{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'events': [{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'continued': False, 'continued': False,
'date_range': 'Jan. 1, 2019 10:00', 'date_range': 'Tue, Jan. 1st, 2019 10:00',
'event_url': 'http://example.com/ccc/present/', 'event_url': 'http://example.com/ccc/present/',
'name': 'Present', 'name': 'Present',
'location': '', 'location': '',
@@ -892,7 +892,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
'time': '10:00'}, 'time': '10:00'},
{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'continued': False, 'continued': False,
'date_range': 'Jan. 1, 2019 11:00', 'date_range': 'Tue, Jan. 1st, 2019 11:00',
'event_url': 'http://example.com/ccc/30c3/', 'event_url': 'http://example.com/ccc/30c3/',
'name': 'Present', 'name': 'Present',
'location': '', 'location': '',
@@ -904,7 +904,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
'day': 4, 'day': 4,
'events': [{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, 'events': [{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'continued': False, 'continued': False,
'date_range': 'Jan. 4, 2019 10:00', 'date_range': 'Fri, Jan. 4th, 2019 10:00',
'event_url': 'http://example.com/ccc/future/', 'event_url': 'http://example.com/ccc/future/',
'name': 'Future', 'name': 'Future',
'location': '', 'location': '',
@@ -912,7 +912,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
'time': '10:00'}, 'time': '10:00'},
{'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'}, {'availability': {'color': 'none', 'text': 'More info', 'reason': 'unknown'},
'continued': False, 'continued': False,
'date_range': 'Jan. 4, 2019 11:00', 'date_range': 'Fri, Jan. 4th, 2019 11:00',
'event_url': 'http://example.com/ccc/30c3/', 'event_url': 'http://example.com/ccc/30c3/',
'name': 'Future', 'name': 'Future',
'location': '', 'location': '',