#!/usr/bin/env python3
"""
Script to remove legacy Verpachtung views from views.py
"""

import re
import sys

def remove_legacy_verpachtung_views():
    with open('app/stiftung/views.py', 'r', encoding='utf-8') as f:
        content = f.read()
    
    # Remove verpachtung_export function
    export_pattern = r'@login_required\s+def verpachtung_export\([^)]+\):[^@]*?pass\s*\n\n'
    content = re.sub(export_pattern, '', content, flags=re.DOTALL)
    
    # More aggressive pattern for verpachtung_export
    export_pattern2 = r'@login_required\s+def verpachtung_export.*?(?=@login_required|def \w+.*?\(.*?\):|\Z)'
    content = re.sub(export_pattern2, '', content, flags=re.DOTALL)
    
    # Remove comment and all verpachtung views until next comment
    verpachtung_section_pattern = r'# Verpachtung Views.*?(?=# [A-Z][^#\n]*Views|\Z)'
    content = re.sub(verpachtung_section_pattern, '', content, flags=re.DOTALL)
    
    with open('app/stiftung/views.py', 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("Legacy Verpachtung views removed from views.py")

if __name__ == "__main__":
    remove_legacy_verpachtung_views()
