Skip to content

Commit

Permalink
Location for apple in ics files
Browse files Browse the repository at this point in the history
  • Loading branch information
autoantwort committed Aug 29, 2024
1 parent 55b4085 commit 5b3a53c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.dispatch import receiver
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
from ics.grammar.parse import ContentLine

from .consumers import CHANNEL_GROUP_NAME
from django.contrib.auth.models import User
from django.db import models
Expand Down Expand Up @@ -125,7 +127,7 @@ def ics_url_path(self):
return reverse("download_bar_events_ics", args=[slugify(self.name), self.id])

def google_maps_url(self):
return f"https://maps.google.com/?q={ self.name }, { self.street }, { self.zip_code } { self.city }"
return f"https://maps.google.com/?q={self.name}, {self.street}, {self.zip_code} {self.city}"

def content_description(self):
if self.description:
Expand Down Expand Up @@ -186,12 +188,21 @@ def to_ics_event(self) -> IcsEvent:
ics_event.begin = self.start_date
ics_event.end = self.end_date if self.end_date else self.start_date + timedelta(hours=4)
ics_event.description = self.description
ics_event.location = f"{self.bar.street}, {self.bar.zip_code} {self.bar.city}"
ics_event.location = f"{self.bar.name}\n{self.bar.street}, {self.bar.zip_code} {self.bar.city}, Germany"
if self.bar.latitude and self.bar.longitude:
ics_event.geo = Geo(self.bar.latitude, self.bar.longitude)
ics_event.status = "CONFIRMED"
ics_event.uid = f"event-{self.id}@studibars-ac.de"
ics_event.organizer = Organizer(common_name=self.bar.name, email="[email protected]")
ics_event.extra.append(ContentLine(name="X-APPLE-STRUCTURED-LOCATION",
params={
"VALUE": ["URI"],
"X-ADDRESS": [
f"\"{self.bar.name}, {self.bar.street}, {self.bar.zip_code} {self.bar.city}, Germany\""],
"X-APPLE-RADIUS": ["15"],
"X-TITLE": [self.bar.name],
},
value=f"geo:{self.bar.latitude},{self.bar.longitude}"))

# Add an alarm/reminder
alarm = DisplayAlarm(trigger=timedelta(days=-1))
Expand Down

0 comments on commit 5b3a53c

Please sign in to comment.