from django.shortcuts import redirect
from multidb.pinning import pin_this_thread, unpin_this_thread
from .models import Service, StopPoint


def real_ip_middleware(get_response):
    def middleware(request):
        if 'HTTP_X_REAL_IP' in request.META:
            request.META['REMOTE_ADDR'] = request.META['HTTP_X_REAL_IP']
        return get_response(request)
    return middleware


def pin_db_middleware(get_response):
    def middleware(request):
        if (
            request.method == 'POST'
            or request.path.startswith('/admin/')
            or request.path.startswith('/accounts/')
            or '/edit' in request.path
        ):
            pin_this_thread()
        else:
            unpin_this_thread()
        return get_response(request)

    return middleware

@@ -1,42 +1,4 @@
-from django.shortcuts import redirect%0A
 from
@@ -60,47 +60,8 @@
 ead%0A
-from .models import Service, StopPoint%0A
 %0A%0Ade

remove unused imports