Skip to content
Snippets Groups Projects
Verified Commit 4c0bc3b3 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Support additional meta information in calendar events for usage with own frontend only

parent 3b0e891b
No related branches found
No related tags found
1 merge request!1148Calendar events and iCal feeds
Pipeline #131244 failed
......@@ -195,6 +195,7 @@ export default {
end: new Date(event.end),
color: event.color ? event.color : cf.color,
timed: !event.allDay,
meta: JSON.parse(event.meta),
}))
);
},
......
......@@ -15,6 +15,7 @@ query ($start: Date, $end: Date) {
uid
allDay
status
meta
}
}
}
......
......@@ -15,6 +15,7 @@ class CalendarEventType(ObjectType):
uid = graphene.String()
all_day = graphene.Boolean()
status = graphene.String()
meta = graphene.String()
def resolve_name(root, info, **kwargs):
return root["SUMMARY"]
......@@ -40,6 +41,9 @@ class CalendarEventType(ObjectType):
def resolve_status(root, info, **kwargs):
return root.get("STATUS", "")
def resolve_meta(root, info, **kwargs):
return root.get("X-META", {})
class CalendarFeedType(ObjectType):
events = graphene.List(
......
import json
import os
from datetime import datetime, timedelta
from importlib import import_module, metadata
......@@ -498,6 +499,7 @@ feedgenerator.FEED_FIELD_MAP = feedgenerator.FEED_FIELD_MAP + (("color", "color"
feedgenerator.ITEM_ELEMENT_FIELD_MAP = feedgenerator.ITEM_ELEMENT_FIELD_MAP + (
("color", "color"),
("recurrence_id", "recurrence-id"),
("meta", "x-meta"),
)
......@@ -507,7 +509,7 @@ class ExtendedICal20Feed(feedgenerator.ICal20Feed):
Adds a method to return the actual calendar object.
"""
def get_calendar_object(self):
def get_calendar_object(self, with_meta=True):
cal = Calendar()
cal.add("version", "2.0")
cal.add("calscale", "GREGORIAN")
......@@ -517,28 +519,19 @@ class ExtendedICal20Feed(feedgenerator.ICal20Feed):
if val is not None:
cal.add(efield, val)
self.write_items(cal)
self.write_items(cal, with_meta=with_meta)
return cal
def write(self, outfile, encoding):
cal = Calendar()
cal.add("version", "2.0")
cal.add("calscale", "GREGORIAN")
for ifield, efield in feedgenerator.ITEM_ELEMENT_FIELD_MAP:
val = self.feed.get(ifield)
if val is not None:
cal.add(efield, val)
self.write_items(cal)
cal = self.get_calendar_object(with_meta=False)
to_ical = getattr(cal, "as_string", None)
if not to_ical:
to_ical = cal.to_ical
outfile.write(to_ical())
def write_items(self, calendar):
def write_items(self, calendar, with_meta=True):
for item in self.items:
component_type = item.get("component_type")
if component_type == "todo":
......@@ -554,6 +547,9 @@ class ExtendedICal20Feed(feedgenerator.ICal20Feed):
elif ifield == "valarm":
for list_item in val:
element.add_component(list_item)
elif ifield == "meta":
if with_meta:
element.add(efield, json.dumps(val))
else:
element.add(efield, val)
calendar.add_component(element)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment