diff --git a/dolt/middleware.py b/dolt/middleware.py index 5fb8d5b..6a6bf5d 100644 --- a/dolt/middleware.py +++ b/dolt/middleware.py @@ -7,7 +7,6 @@ from dolt.constants import ( DOLT_BRANCH_KEYWORD, - DOLT_VERSIONED_URL_PREFIXES, DOLT_DEFAULT_BRANCH, ) from dolt.context_managers import AutoDoltCommit @@ -15,40 +14,14 @@ class DoltBranchMiddleware: + # DOLT_BRANCH_KEYWORD = "branch" + def __init__(self, get_response): self.get_response = get_response def __call__(self, request): - # check for a `branch` query string param - branch = request.GET.get(DOLT_BRANCH_KEYWORD, None) - - if branch: - # update the session cookie with the active branch - request.session[DOLT_BRANCH_KEYWORD] = branch - elif self._is_vcs_route(request): - # route is under version control, but no branch was specified, - # lookup the active branch in the session cookie. - branch = request.session.get(DOLT_BRANCH_KEYWORD, DOLT_DEFAULT_BRANCH) - # provide the `branch` query string param and redirect - return redirect(f"{request.path}?{DOLT_BRANCH_KEYWORD}={branch}") - return self.get_response(request) - @staticmethod - def _is_vcs_route(request): - """ - Determines whether the requested page is under version-control - and needs to be redirected to read from a specific branch. - """ - if request.GET.get(DOLT_BRANCH_KEYWORD, None): - # if a branch is already specified in the - # query string, don't redirect - return False - - return ( - request.path.startswith(DOLT_VERSIONED_URL_PREFIXES) or request.path == "/" - ) - def process_view(self, request, view_func, view_args, view_kwargs): # lookup the active branch in the session cookie branch = request.session.get(DOLT_BRANCH_KEYWORD, DOLT_DEFAULT_BRANCH) @@ -62,9 +35,8 @@ def process_view(self, request, view_func, view_args, view_kwargs): f"""