The Middleware object, not the SheetSync object, needs to know about shifts

pull/441/merge
Christopher Usher 3 weeks ago
parent 71a8789c4b
commit 4041040af0

@ -276,11 +276,10 @@ class EventsSync(SheetSync):
"category", "category",
} }
def __init__(self, name, middleware, stop, dbmanager, reverse_sync=False, media_dir=None, shifts=None): def __init__(self, name, middleware, stop, dbmanager, reverse_sync=False, media_dir=None):
super().__init__(name, middleware, stop, dbmanager, reverse_sync) super().__init__(name, middleware, stop, dbmanager, reverse_sync)
self.media_dir = media_dir self.media_dir = media_dir
self.media_downloads = None if media_dir is None else {} self.media_downloads = None if media_dir is None else {}
self.shifts = shifts
def observe_rows(self, rows): def observe_rows(self, rows):
@ -482,12 +481,18 @@ def main(dbconnect, sync_configs, metrics_port=8005, backdoor_port=0, media_dir=
client_secret=creds['client_secret'], client_secret=creds['client_secret'],
refresh_token=creds['refresh_token'], refresh_token=creds['refresh_token'],
) )
if config["type"] in ("events", "archive"): if config["type"] == "events":
middleware_cls = { middleware = SheetsEventsMiddleware(
"events": SheetsEventsMiddleware, client,
"archive": SheetsArchiveMiddleware, config["sheet_id"],
}[config["type"]] config["worksheets"],
middleware = middleware_cls( common.dateutil.parse(config["bustime_start"]),
config["edit_url"],
shifts,
allocate_ids,
)
elif config["type"] == "archive":
middleware = SheetsArchiveMiddleware(
client, client,
config["sheet_id"], config["sheet_id"],
config["worksheets"], config["worksheets"],
@ -528,8 +533,6 @@ def main(dbconnect, sync_configs, metrics_port=8005, backdoor_port=0, media_dir=
"archive": ArchiveSync, "archive": ArchiveSync,
}[config["type"]] }[config["type"]]
sync_class_kwargs = {} sync_class_kwargs = {}
if config["type"] == "events":
sync_class_kwargs["shifts"] = shifts
if config["type"] == "events" and config.get("download_media", False): if config["type"] == "events" and config.get("download_media", False):
sync_class_kwargs["media_dir"] = media_dir sync_class_kwargs["media_dir"] = media_dir
sync = sync_class(config["name"], middleware, stop, dbmanager, reverse_sync, **sync_class_kwargs) sync = sync_class(config["name"], middleware, stop, dbmanager, reverse_sync, **sync_class_kwargs)

@ -269,10 +269,11 @@ class SheetsEventsMiddleware(SheetsMiddleware):
'id': 15, 'id': 15,
} }
def __init__(self, client, sheet_id, worksheets, bustime_start, edit_url, allocate_ids=False): def __init__(self, client, sheet_id, worksheets, bustime_start, edit_url, shifts, allocate_ids=False):
super().__init__(client, sheet_id, worksheets, allocate_ids) super().__init__(client, sheet_id, worksheets, allocate_ids)
self.bustime_start = bustime_start self.bustime_start = bustime_start
self.edit_url = edit_url self.edit_url = edit_url
self.shifts = shifts
self.latest_shifts = common.shifts.parse_shifts(self.shifts) self.latest_shifts = common.shifts.parse_shifts(self.shifts)

Loading…
Cancel
Save