Skip to content
Snippets Groups Projects
Commit 47a87400 authored by Andreas Hubel's avatar Andreas Hubel
Browse files

feat(scheduleimport): add legacy_id=drop option, so id can be recomputed from uuid

parent bb7a9c5e
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,10 @@ from django.utils import timezone ...@@ -7,10 +7,10 @@ from django.utils import timezone
from django.utils.module_loading import import_string 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 {} computed_fields = computed_fields or {}
return { 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 } | computed_fields
......
...@@ -22,6 +22,7 @@ class ScheduleJSONSupport(BaseScheduleSupport): ...@@ -22,6 +22,7 @@ class ScheduleJSONSupport(BaseScheduleSupport):
'kind': ('string', 'assembly', False, 'kind of events, either `assembly` or `official` or `sos` or `lightning`'), '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'), 'headers': ('dict', {}, False, 'HTTP headers to send with the request e.g. Authorization'),
'auth': ('string', None, False, 'HTTP Authentification header e.g. `Token 123456`'), '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'), 'legacy_id_offset': ('int', None, False, 'Offset to add to the legacy integer `id` to avoid collisions with other sources'),
} }
# fmt: on # fmt: on
...@@ -57,6 +58,10 @@ class ScheduleJSONSupport(BaseScheduleSupport): ...@@ -57,6 +58,10 @@ class ScheduleJSONSupport(BaseScheduleSupport):
kind = self.conf_value('kind') 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): def ensure_full_url(uri):
if not uri: if not uri:
return None return None
...@@ -85,7 +90,7 @@ class ScheduleJSONSupport(BaseScheduleSupport): ...@@ -85,7 +90,7 @@ class ScheduleJSONSupport(BaseScheduleSupport):
'kind': kind, 'kind': kind,
'speakers': e.get('persons', []), 'speakers': e.get('persons', []),
'banner_image_url': ensure_full_url(e.get('logo')), '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() for e in schedule.events()
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment