Skip to content

Commit

Permalink
Merge branch 'main' into INTR-310
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelkornblum authored Oct 9, 2024
2 parents 7527688 + b618152 commit ce95228
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 121 deletions.
3 changes: 1 addition & 2 deletions assets/js/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Sentry from "@sentry/browser";
import { BrowserTracing } from "@sentry/tracing";

/**
* Return config from meta html elements.
Expand All @@ -24,7 +23,7 @@ function sentryInit() {
dsn,
release: config("release"),
environment: config("environment"),
integrations: [new BrowserTracing()],
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: Number(config("sentry:browser-traces-sample-rate")),
});
}
Expand Down
280 changes: 218 additions & 62 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"private": true,
"dependencies": {
"@ministryofjustice/frontend": "^1.8.0",
"@sentry/browser": "^6.19.7",
"@sentry/tracing": "^6.19.7",
"@sentry/browser": "^7.119.1",
"cropperjs": "^1.5.13",
"css-loader": "^5.2.7",
"govuk-frontend": "^4.5.0",
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/dw_design_system/dwds/components/engagement.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load wagtailimages_tags static humanize %}

<div class="dwds-engagement content-item content-custom-sidebar-wrapper">
<div class="content-item content-custom-sidebar-wrapper">
<div class="content-custom-sidebar">
{% include "dwds/elements/content_image.html" with content_image=thumbnail %}

Expand All @@ -12,10 +12,9 @@
<h3>
<a class="no-underline" href="{{ url }}">{{ title }}</a>
</h3>
{% if post_title_date and post_title_time %}
{% if post_title %}
<div class="post-title-container">
<h4 class="post-title">{{ post_title_date }}</h4>
<h4 class="post-title">{{ post_title_time }}</h4>
<h4 class="post-title">{{ post_title }}</h4>
</div>
{% endif %}
{% if excerpt %}<p>{{ excerpt|truncatewords:16 }}</p>{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/dw_design_system/dwds/components/engagement_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class EngagementCardBlock(blocks.StructBlock):
page = blocks.PageChooserBlock(page_type="content.ContentPage")

class Meta:
template = "dwds/components/engagement_card.html"
template = "dwds/components/engagement.html"
icon = "doc-empty"
label = "Engagement Card"

Expand Down
5 changes: 2 additions & 3 deletions src/dw_design_system/dwds/components/one_up.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
<h2>
<a class="no-underline" href="{{ url }}">{{ title }}</a>
</h2>
{% if post_title_date and post_title_time %}
{% if post_title %}
<div class="post-title-container">
<h4 class="post-title">{{ post_title_date }}</h4>
<h4 class="post-title">{{ post_title_time }}</h4>
<h4 class="post-title">{{ post_title }}</h4>
</div>
{% endif %}
{% if excerpt %}<p>{{ excerpt|truncatewords:16 }}</p>{% endif %}
Expand Down
4 changes: 4 additions & 0 deletions src/dw_design_system/dwds/layouts/content_grid.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.content-grid {
display: grid;
grid-gap: var(--space);

.content-item {
display: flex;
}
}

.content-grid.image-left,
Expand Down
95 changes: 95 additions & 0 deletions src/events/migrations/0004_remove_eventpage_end_time_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Generated by Django 4.2.15 on 2024-10-02 12:42

import datetime
from django.db import migrations, models
from datetime import datetime as dt
import django.utils.timezone


def copy_events(apps, schema_editor):
EventPage = apps.get_model("events", "EventPage")

for event_page in EventPage.objects.all():
event_page.event_start = dt.combine(
event_page.event_date, event_page.start_time
)
event_page.event_end = dt.combine(event_page.event_date, event_page.end_time)
event_page.save()


def reverse_copy_events(apps, schema_editor):
EventPage = apps.get_model("events", "EventPage")

for event_page in EventPage.objects.all():
event_page.event_date = event_page.event_start.date()
event_page.start_time = event_page.event_start.time()
event_page.end_time = event_page.event_end.time()
event_page.save()


class Migration(migrations.Migration):

dependencies = [
("events", "0003_alter_eventpage_event_recording_url_and_more"),
]

operations = [
migrations.AddField(
model_name="eventpage",
name="event_start",
field=models.DateTimeField(
default=django.utils.timezone.now,
help_text="Start date/time of the event.",
),
preserve_default=False,
),
migrations.AddField(
model_name="eventpage",
name="event_end",
field=models.DateTimeField(
default=datetime.datetime(
2024, 10, 2, 12, 42, 15, 793134, tzinfo=datetime.timezone.utc
),
help_text="End date/time of the event.",
),
preserve_default=False,
),
migrations.AlterField(
model_name="eventpage",
name="event_date",
field=models.DateField(
help_text="Date and time should be entered based on the time in London/England.",
blank=True,
null=True,
),
),
migrations.AlterField(
model_name="eventpage",
name="start_time",
field=models.TimeField(
blank=True,
null=True,
),
),
migrations.AlterField(
model_name="eventpage",
name="end_time",
field=models.TimeField(
blank=True,
null=True,
),
),
migrations.RunPython(copy_events, reverse_code=reverse_copy_events),
migrations.RemoveField(
model_name="eventpage",
name="event_date",
),
migrations.RemoveField(
model_name="eventpage",
name="start_time",
),
migrations.RemoveField(
model_name="eventpage",
name="end_time",
),
]
24 changes: 10 additions & 14 deletions src/events/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime as dt
from datetime import timedelta

from django.db import models
Expand All @@ -8,7 +7,7 @@
from content.models import BasePage, ContentPage
from core.models import fields
from events import types
from events.utils import get_event_date, get_event_time
from events.utils import get_event_datetime_display_string


class EventsHome(BasePage):
Expand All @@ -33,11 +32,12 @@ class EventPage(ContentPage):
parent_page_types = ["events.EventsHome"]
template = "events/event_page.html"

event_date = models.DateField(
help_text="Date and time should be entered based on the time in London/England.",
event_start = models.DateTimeField(
help_text="Start date/time of the event.",
)
event_end = models.DateTimeField(
help_text="End date/time of the event.",
)
start_time = models.TimeField()
end_time = models.TimeField()
online_event_url = fields.URLField(
blank=True,
null=True,
Expand Down Expand Up @@ -90,11 +90,10 @@ class EventPage(ContentPage):
content_panels = ContentPage.content_panels + [
MultiFieldPanel(
[
FieldPanel("event_date"),
FieldRowPanel(
[
FieldPanel("start_time"),
FieldPanel("end_time"),
FieldPanel("event_start"),
FieldPanel("event_end"),
]
),
],
Expand Down Expand Up @@ -135,15 +134,12 @@ def get_context(self, request, *args, **kwargs):
is_online=self.event_type == types.EventType.ONLINE,
is_in_person=self.event_type == types.EventType.IN_PERSON,
is_hybrid=self.event_type == types.EventType.HYBRID,
event_date=get_event_date(self),
event_time=get_event_time(self),
event_date_range=get_event_datetime_display_string(self),
)

return context

@property
def is_past_event(self) -> bool:
adjusted_datetime = timezone.make_aware(
dt.combine(self.event_date, self.end_time) + timedelta(hours=1)
)
adjusted_datetime = timezone.make_aware(self.event_end + timedelta(hours=1))
return timezone.now() > adjusted_datetime
4 changes: 1 addition & 3 deletions src/events/templates/events/event_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<dl>
<dt class="dwds-sr-only">When</dt>
<dd class="text-xlarge">
{{ event_date }}
<br>
{{ event_time }}
{{ event_date_range }}
</dd>
{% if is_in_person or is_hybrid %}
<dt>Location</dt>
Expand Down
2 changes: 1 addition & 1 deletion src/events/templates/events/events_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h2 class="govuk-heading-m">
<a href="{% pageurl event %}">{{ event.title }}</a>
</h2>
<p class="govuk-body-s">{{ event.event_date }}</p>
<p class="govuk-body-s">{{ event.event_start|date:"d M Y" }}</p>
{% image event.preview_image width-540 %}
<p class="govuk-body">{{ event.description }}</p>
</li>
Expand Down
22 changes: 16 additions & 6 deletions src/events/utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
from typing import TYPE_CHECKING

from django.utils.safestring import mark_safe

from core.utils import format_time


if TYPE_CHECKING:
from events.models import EventPage


def get_event_date(event: "EventPage") -> str:
return event.event_date.strftime("%-d %B %Y")
def get_event_datetime_display_string(event: "EventPage") -> str:
event_start_date = event.event_start.strftime("%-d %B %Y")
event_end_date = event.event_end.strftime("%-d %B %Y")
event_start_time = format_time(event.event_start.time())
event_end_time = format_time(event.event_end.time())

if event_start_date == event_end_date:
event_post_title = mark_safe( # noqa S308
f"{event_start_date} <br>{event_start_time} - {event_end_time}"
)
else:
event_post_title = mark_safe( # noqa S308
f"{event_start_date} {event_start_time} - <br>{event_end_date} {event_end_time}"
)

def get_event_time(event: "EventPage") -> str:
start_time = format_time(event.start_time)
end_time = format_time(event.end_time)
return f"{start_time} - {end_time}"
return event_post_title
4 changes: 2 additions & 2 deletions src/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ def get_context(self, request, *args, **kwargs):
events = (
EventPage.objects.live()
.public()
.filter(event_date__gte=timezone.now().date())
.filter(event_end__gte=timezone.now())
.exclude(id__in=priority_page_ids)
.order_by("event_date", "start_time")
.order_by("event_start")
)

context.update(
Expand Down
22 changes: 4 additions & 18 deletions src/home/templatetags/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from django.utils.safestring import SafeString

from events.models import EventPage
from events.utils import get_event_date, get_event_time
from events.utils import (
get_event_datetime_display_string,
)
from news.models import NewsPage


Expand All @@ -30,27 +32,11 @@ def page_to_display_context(page: NewsPage | EventPage):
)

if issubclass(type(page), EventPage):
context.update(
post_title_date=get_event_date(page),
post_title_time=get_event_time(page),
)
context.update(post_title=get_event_datetime_display_string(page))

return context


@register.simple_tag
def page_to_card(page: NewsPage | EventPage, hide_shadow: bool = False):
return {
**page_to_display_context(page),
"template": "dwds/components/engagement_card.html",
}


@register.simple_tag
def pages_to_cards(pages: list[NewsPage | EventPage], hide_shadow: bool = False):
return [page_to_card(page, hide_shadow=hide_shadow) for page in pages]


class RenderableComponent:
def __init__(self, template_name: str, context: dict):
self.template_name = template_name
Expand Down

0 comments on commit ce95228

Please sign in to comment.