Skip to content

Commit

Permalink
Use Rsvp for EventRegistration schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Oct 10, 2023
1 parent 1781df3 commit 672b5a8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
4 changes: 2 additions & 2 deletions funnel/models/rsvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Rsvp(UuidMixin, NoIdMixin, Model):
project_id = sa.orm.mapped_column(
sa.Integer, sa.ForeignKey('project.id'), nullable=False, primary_key=True
)
project = with_roles(
project: Mapped[Project] = with_roles(
relationship(Project, backref=backref('rsvps', cascade='all', lazy='dynamic')),
read={'owner', 'project_promoter'},
grants_via={None: project_child_role_map},
Expand All @@ -54,7 +54,7 @@ class Rsvp(UuidMixin, NoIdMixin, Model):
participant_id: Mapped[int] = sa.orm.mapped_column(
sa.ForeignKey('account.id'), nullable=False, primary_key=True
)
participant = with_roles(
participant: Mapped[Account] = with_roles(
relationship(Account, backref=backref('rsvps', cascade='all', lazy='dynamic')),
read={'owner', 'project_promoter'},
grants={'owner'},
Expand Down
79 changes: 42 additions & 37 deletions funnel/transports/email/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from baseframe import _, statsd

from ... import app
from ...models import Account, EmailAddress, EmailAddressBlockedError, Venue
from ...models import Account, EmailAddress, EmailAddressBlockedError, Rsvp
from ..exc import TransportRecipientError

__all__ = [
Expand All @@ -43,8 +43,9 @@ class EmailAttachment:


def jsonld_view_action(description: str, url: str, title: str) -> dict[str, object]:
"""Schema.org JSON-LD markup for an email view action."""
return {
'@context': 'http://schema.org',
'@context': 'https://schema.org',
'@type': 'EmailMessage',
'description': description,
'potentialAction': {'@type': 'ViewAction', 'name': title, 'url': url},
Expand All @@ -56,21 +57,29 @@ def jsonld_view_action(description: str, url: str, title: str) -> dict[str, obje
}


def jsonld_event_reservation(
description: str,
url: str,
title: str,
start_date: str,
location: str,
venue: Venue | None,
fullname: str,
) -> dict[str, object]:
location_schema: dict[str, object] = {
'@type': 'Place',
'name': location,
def jsonld_confirm_action(description: str, url: str, title: str) -> dict[str, object]:
"""Schema.org JSON-LD markup for an email confirmation action."""
return {
'@context': 'https://schema.org',
'@type': 'EmailMessage',
'description': description,
'potentialAction': {
'@type': 'ConfirmAction',
'name': title,
'handler': {'@type': 'HttpActionHandler', 'url': url},
},
}


def jsonld_event_reservation(rsvp: Rsvp) -> dict[str, object]:
"""Schema.org JSON-LD markup for an event reservation."""
location: str | dict[str, object]
venue = rsvp.project.primary_venue
if venue is not None:
location_schema['name'] = venue.title
location = {
'@type': 'Place',
'name': venue.title,
}
if venue.address1:
postal_address = {
'@type': 'PostalAddress',
Expand All @@ -80,43 +89,39 @@ def jsonld_event_reservation(
'postalCode': venue.postcode,
'addressCountry': venue.country,
}
location_schema['address'] = postal_address
location['address'] = postal_address
else:
location = rsvp.project.location
return {
'@context': 'http://schema.org',
'@context': 'https://schema.org',
'@type': 'EventReservation',
'reservationStatus': 'http://schema.org/Confirmed',
'reservationNumber': rsvp.uuid_b58,
'reservationStatus': (
'https://schema.org/ReservationConfirmed'
if rsvp.state.YES
else 'https://schema.org/ReservationCancelled'
if rsvp.state.NO
else 'https://schema.org/ReservationPending'
),
'underName': {
'@type': 'Person',
'name': fullname,
'name': rsvp.participant.fullname,
},
'reservationFor': {
'@type': 'Event',
'name': title,
'url': url,
'name': rsvp.project.joined_title,
'url': rsvp.project.absolute_url,
'startDate': rsvp.project.start_at,
'location': location,
'performer': {
'@type': 'Organization',
'name': description,
'name': rsvp.project.account.title,
},
'startDate': start_date,
'location': location_schema,
},
'numSeats': '1',
}


def jsonld_confirm_action(description: str, url: str, title: str) -> dict[str, object]:
return {
'@context': 'http://schema.org',
'@type': 'EmailMessage',
'description': description,
'potentialAction': {
'@type': 'ConfirmAction',
'name': title,
'handler': {'@type': 'HttpActionHandler', 'url': url},
},
}


def process_recipient(recipient: EmailRecipient) -> str:
"""
Process recipient in any of the given input formats.
Expand Down
10 changes: 1 addition & 9 deletions funnel/views/notifications/rsvp_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@ def email_content(self):
return render_template(
'notifications/rsvp_yes_email.html.jinja2',
view=self,
jsonld=email.jsonld_event_reservation(
self.rsvp.project.joined_title,
self.rsvp.project.url_for(_external=True),
self.rsvp.project.title,
self.rsvp.project.start_at,
self.rsvp.project.location,
self.rsvp.project.primary_venue,
self.rsvp.participant.fullname,
),
jsonld=email.jsonld_event_reservation(self.rsvp),
)

def sms(
Expand Down

0 comments on commit 672b5a8

Please sign in to comment.