Skip to content
Snippets Groups Projects
Commit f9984f92 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Add a utility script to create json exports for individual events

This consists of a bash script to call and prepare as well as a python script to process the dump created by django and restrict it to the entries related to the event
parent 2fec1402
No related branches found
No related tags found
1 merge request!114Introduce utility to export all data related to an event to json
Pipeline #79690 passed
import json
import sys
event_id = int(sys.argv[1])
target_name = sys.argv[2]
print(f"Creating export for event '{event_id}' as '{target_name}'")
# Load json file just created by django
with open('backups/akplanning_only.json', 'r') as json_file:
exported_entries = json.load(json_file)
print(f"Loaded {len(exported_entries)} entries in total, restricting to event...")
entries_without_event = 0
entries_out = []
virtual_rooms_to_preserve = set()
# Loop over all dumped entries
for entry in exported_entries:
# Handle all entries with event reference
if "event" in entry['fields']:
event = int(entry['fields']['event'])
# Does this entry belong to the event we are looking for?
if event == event_id:
# Store for backup
entries_out.append(entry)
# Remember the primary keys of all rooms of this event
# Required for special handling of virtual rooms,
# since they inherit from normal rooms and have no direct event reference
if entry['model'] == "AKModel.room":
virtual_rooms_to_preserve.add(entry['pk'])
# Handle entries without event reference
else:
# Backup virtual rooms of that event
if entry['model'] == "AKOnline.virtualroom":
if entry['pk'] in virtual_rooms_to_preserve:
entries_out.append(entry)
# Backup the event itself
elif entry['model'] == "AKModel.event":
if int(entry['pk']) == event_id:
entries_out.append(entry)
# Backup tags
elif entry['model'] == "AKModel.aktag":
# No restriction needed, backup all tags
entries_out.append(entry)
else:
# This should normally not happen (all other models should have a reference to the event)
entries_without_event += 1
print(entry)
print(f"Ignored entries without event: {entries_without_event}")
print(f"Exporting {len(entries_out)} entries for event")
with open(f'backups/{target_name}.json', 'w') as json_file:
json.dump(entries_out, json_file, indent=2)
#!/usr/bin/env bash
# Update AKPlanning
# execute as Utils/update.sh id_to_export target_name_to_export_to [--prod]
# abort on error, print executed commands
set -ex
# activate virtualenv if necessary
if [ -z ${VIRTUAL_ENV+x} ]; then
source venv/bin/activate
fi
# set environment variable when we want to update in production
if [ "$3" = "--prod" ]; then
export DJANGO_SETTINGS_MODULE=AKPlanning.settings_production
fi
# before potentially breaking anything, create a data backup
mkdir -p ../backups/
python manage.py dumpdata AKDashboard AKModel AKOnline AKPlan AKScheduling AKSubmission --indent=2 > "backups/akplanning_only.json" --traceback
python ./Utils/json_export.py $1 $2
rm backups/akplanning_only.json
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