import os

with open('core/views.py', 'r') as f:
    lines = f.readlines()

new_lines = []
skip = False
for i, line in enumerate(lines):
    if "return render(request, 'core/log_door_visit.html', context)" in line:
        new_lines.append(line)
        # Look ahead to see if there is duplicated code
        if i + 3 < len(lines) and "default_caller = None" in lines[i+3]:
            skip = True
            continue
    if skip:
        if "return redirect(redirect_url)" in line:
            skip = False
        continue
    new_lines.append(line)

with open('core/views.py', 'w') as f:
    f.writelines(new_lines)
