diff --git a/src/core/schedules/base.py b/src/core/schedules/base.py index 7735ba89ee0c2d2bfccceb47de4f512bc436042f..36e763e69ccb537ba018e5f458b3860c2ad6281f 100644 --- a/src/core/schedules/base.py +++ b/src/core/schedules/base.py @@ -7,10 +7,10 @@ from django.utils import timezone from django.utils.module_loading import import_string -def filter_additional_data(data: dict, computed_fields: dict | None = None) -> dict: +def filter_additional_data(data: dict, computed_fields: dict | None = None, others=[]) -> dict: computed_fields = computed_fields or {} return { - k: v for k, v in data.items() if (v and k not in ['guid', 'room', 'start', 'date', 'duration', 'title', 'abstract', 'description', 'language']) + k: v for k, v in data.items() if (v and k not in ['guid', 'room', 'start', 'date', 'duration', 'title', 'abstract', 'description', 'language', *others]) } | computed_fields diff --git a/src/core/schedules/schedulejson.py b/src/core/schedules/schedulejson.py index 63063eae8895a1a935b19114ba8aca7f75a7259f..f6c92eaab1bd7d66db490e0ba30d121b2c68ce73 100644 --- a/src/core/schedules/schedulejson.py +++ b/src/core/schedules/schedulejson.py @@ -22,6 +22,8 @@ class ScheduleJSONSupport(BaseScheduleSupport): 'kind': ('string', 'assembly', False, 'kind of events, either `assembly` or `official` or `sos` or `lightning`'), 'headers': ('dict', {}, False, 'HTTP headers to send with the request e.g. Authorization'), 'auth': ('string', None, False, 'HTTP Authentification header e.g. `Token 123456`'), + 'legacy_id': ('string', None, False, 'Use `drop` to regenerate legacy ids from the event guid, to avoid collisions with other sources'), + 'legacy_id_offset': ('int', None, False, 'Offset to add to the legacy integer `id` to avoid collisions with other sources'), } # fmt: on @@ -56,6 +58,10 @@ class ScheduleJSONSupport(BaseScheduleSupport): kind = self.conf_value('kind') + other_fields_to_drop = [] + if self.conf_value('legacy_id') == 'drop': + other_fields_to_drop.append('id') + def ensure_full_url(uri): if not uri: return None @@ -84,17 +90,23 @@ class ScheduleJSONSupport(BaseScheduleSupport): 'kind': kind, 'speakers': e.get('persons', []), 'banner_image_url': ensure_full_url(e.get('logo')), - 'additional_data': filter_additional_data(e, self.computed_data(e)), + 'additional_data': filter_additional_data(e, self.computed_data(e), other_fields_to_drop), } for e in schedule.events() }, } def computed_data(self, event: dict): - # TODO only add feedback_url if feedback is enabled via configuraiton_fields in ScheduleSource config + data = {} + data['origin_url'] = event['url'] + + # add feedback_url if feedback is enabled via configuraiton_fields in ScheduleSource config if self.conf_value('feedback'): - return {'feedback_url': f"{event['url']}feedback/"} - return {} + data['feedback_url'] = f"{event['url']}feedback/" + if self.conf_value('legacy_id_offset'): + data['id'] = int(event['id']) + int(self.conf_value('legacy_id_offset') or 0) + + return data class ScheduleJSON: