from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render

from projects.api.views.files import ProjectsFilesViewSet


@login_required
def list(request: HttpRequest, *args, **kwargs) -> HttpResponse:
    """
    Get a list of project files.

    The trailing part of the URL becomes the `prefix` query
    parameter, consistent with API ending e.g.

      /<account>/<project>/files/sub?search=foo

    is equivalent to:

      /api/projects/<project>/files?prefix=sub&search=foo
    """
    prefix = kwargs.get("prefix")
    if prefix and not prefix.endswith("/"):
        prefix += "/"

    request.GET = request.GET.copy()
    request.GET["prefix"] = prefix
    request.GET["aggregate"] = True

    viewset = ProjectsFilesViewSet.init("list", request, args, kwargs)
    project = viewset.get_project()
    files = viewset.get_queryset(project)

    # List of tuples for directory breadcrumbs
    dirs = [("root", "")]
    path = ""
    for name in prefix.split("/"):
        if name:
            path += name + "/"
            dirs.append((name, path))

    return render(
        request,
        "projects/files/list.html",
        dict(prefix=prefix, dirs=dirs, files=files, project=project,),
    )

@@ -571,109 +571,8 @@
 %22%22%22%0A
-    prefix = kwargs.get(%22prefix%22)%0A    if prefix and not prefix.endswith(%22/%22):%0A        prefix += %22/%22%0A%0A
     
@@ -636,50 +636,28 @@
 %5D = 
-prefix%0A    request.GET%5B%22aggregate%22%5D = True
+kwargs.get(%22prefix%22)
 %0A%0A  
@@ -807,215 +807,65 @@
 ct)%0A
-%0A
     
-# List of tuples for directory breadcrumbs%0A    dirs = %5B(%22root%22, %22%22)%5D%0A    path = %22%22%0A    for name in prefix.split(%22/%22):%0A        if name:%0A            path += name + %22/%22%0A            dirs.append((name, path)
+context = viewset.get_response_context(queryset=files
 )%0A%0A 
@@ -898,24 +898,16 @@
 request,
-%0A       
  %22projec
@@ -930,61 +930,14 @@
 ml%22,
-%0A        dict(prefix=prefix, dirs=dirs, files=files, 
+ dict(
 proj
@@ -948,16 +948,26 @@
 project,
+ **context
 ),%0A    )

Update view for change in viewset