def try_reorder_realm_custom_profile_fields(realm: Realm, order: List[int]) -> None:
    order_mapping = {_[1]: _[0] for _ in enumerate(order)}
    fields = CustomProfileField.objects.filter(realm=realm)
    for field in fields:
        if (field.id not in order_mapping):
            raise JsonableError(_('Invalid order mapping.'))
    for field in fields:
        field.order = order_mapping[field.id]
        field.save(update_fields=['order'])
    notify_realm_custom_profile_fields(realm, 'update')
def try_reorder_realm_custom_profile_fields(realm: Realm, order: List[int]) -> None:
    order_mapping = {_[1]: _[0] for _ in enumerate(order)}
    fields = CustomProfileField.objects.filter(realm=realm)
    for field in fields:
        if (field.id not in order_mapping):
            raise JsonableError(_('Invalid order mapping.'))
    for field in fields:
        field.order = order_mapping[field.id]
        field.save(update_fields=['order'])
    notify_realm_custom_profile_fields(realm, 'update')