From fec09edb888013c5cb9c062d5cdb2220bc1a217d Mon Sep 17 00:00:00 2001 From: raphael Date: Sat, 25 Jul 2020 11:27:24 +0200 Subject: [PATCH] adds calendar_type settings to calendar --- __init__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index c8bb63b..dc84ffd 100644 --- a/__init__.py +++ b/__init__.py @@ -16,8 +16,9 @@ API_SERVICE_NAME = 'calendar' API_VERSION = 'v3' class Calendar: - def __init__(self, name, calendarId, toggle='False', color="#000000"): + def __init__(self, name, calendarId, calType, toggle='False', color="#000000"): self.name = name + self.calType = calType self.color = color self.toggle=toggle self.calendarId = calendarId @@ -80,7 +81,8 @@ def updateCalendars(user, calendars, colors): for calendar in calendars: if not user.hasCalendar(calendar.calendarId): color = fromColorIdGetColor(calendar.color, colormap, colors) - c = dbCalendar(calendar_id=calendar.calendarId, + c = dbCalendar(calendar_id = calendar.calendarId, + calendar_type = calendar.calType, name = calendar.name, toggle = "False", color = color) @@ -96,8 +98,9 @@ def calendarsFromDb(user): calendarId = calendar.calendar_id toggle = calendar.toggle color = calendar.color + calType = calendar.calendar_type - pyCalendars.append(Calendar(name, calendarId, toggle, color)) + pyCalendars.append(Calendar(name, calendarId, calType, toggle, color)) return pyCalendars @@ -110,6 +113,7 @@ def purgeCalendars(calendars, visibleCalendars): return purged # remaps a event color id to a calendar color id +# for google calendars def toCalendarColorId(colormap, colorId): for remap in colormap['eventRemap']: if remap['from'] == colorId: @@ -119,6 +123,7 @@ def toCalendarColorId(colormap, colorId): return colorId # remaps a calendar color ID to its natural color +# for google calendars def toNaturalColor(colormap, orgColor): for remap in colormap['colors']: if remap['api'] == orgColor: @@ -127,7 +132,9 @@ def toNaturalColor(colormap, orgColor): print(f"failed with {orgColor}") return orgColor -# use the event color id to convert it to a hex color +# uses the event color id to convert it to a hex color +# does this for every event in events +# this is used for Google Calendars def colorizeEvents(events, colors): COLORS_FILE = os.path.join(os.path.dirname(__file__), 'colors.json') with open(COLORS_FILE) as f: @@ -138,10 +145,12 @@ def colorizeEvents(events, colors): event.colorHex = forEventGetColor(event, colormap, colors) # returns a color for a specific calendar color id +# for google calendars def fromColorIdGetColor(color, colormap, colors): return toNaturalColor(colormap, colors['calendar'][color]['background']) # generates the natural color for a event color id +# for google calendars def forEventGetColor(event, colormap, colors): calColorId = toCalendarColorId(colormap, event.eventColorId) bg = colors['calendar'][calColorId]['background']