Skip to content

Commit 78d7bbe

Browse files
committed
Refactor the file content rendering to have a base template.
This ensures we have all the styles/scripts we need, and proper html page, so we can use our components if needed, but is free from the general styling (e.g. header) that the main base.html provides, so suitable for including in an iframe. The csv template already included this, but this change factors that out into a shared base template used by both the free text and csv templates. Along the way there's few small QoL changes 1) use the filename as the page title 2) don't add additional newlines to preformatted text. This was unoticed before, but now that we have a proper html template, with indentation, it was obviously incorrectly adding the indentation inside the <pre> tag.
1 parent 89a0a5f commit 78d7bbe

File tree

7 files changed

+92
-74
lines changed

7 files changed

+92
-74
lines changed

airlock/renderers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def from_contents(
9898
def get_response(self):
9999
if self.template:
100100
context = self.context()
101+
context.setdefault("filename", self.filename)
101102
response: HttpResponseBase = SimpleTemplateResponse(
102103
self.template.template, context
103104
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% load static %}
2+
{% load django_vite %}
3+
4+
<!DOCTYPE html>
5+
<html lang="en" class="min-h-screen">
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
11+
<title>{% block metatitle %}Airlock{% endblock metatitle %}</title>
12+
13+
{% block extra_meta %}{% endblock %}
14+
15+
{% vite_hmr_client %}
16+
{% vite_asset "assets/src/scripts/base.js" app="job_server" %}
17+
{% vite_asset "assets/src/scripts/main.js" %}
18+
19+
<link rel="stylesheet" href="{% static 'assets/components.css' %}">
20+
<link rel="stylesheet" href="{% static 'assets/icons.css' %}">
21+
22+
{% block extra_styles %}{% endblock %}
23+
24+
<link rel="icon" href="{% static "favicon.ico" %}">
25+
<link rel="icon" href="{% static "icon.svg" %}" type="image/svg+xml">
26+
</head>
27+
28+
<body class="flex flex-col min-h-screen text-slate bg-white">
29+
{% block content %}{% endblock %}
30+
</body>
31+
</html>
Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,65 @@
1+
{% extends "file_browser/file_content/content_base.html" %}
12
{% load airlock %}
2-
{% load django_vite %}
3-
{% load static %}
4-
5-
<!DOCTYPE html>
6-
<html lang="en" class="min-h-screen">
7-
<head>
8-
<meta charset="UTF-8">
9-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11-
12-
{% vite_hmr_client %}
13-
{% vite_asset "assets/src/scripts/main.js" %}
14-
15-
</head>
16-
17-
<body>
18-
19-
<div id="airlock-table">
20-
{% if use_clusterize_table %}
21-
{% fragment as header_row %}
22-
<tr>
23-
<th class="sort-ascending">
3+
{% block metatitle %}{{ filename }}{% endblock %}
4+
{% block content %}
5+
<div id="airlock-table">
6+
{% if use_clusterize_table %}
7+
{% fragment as header_row %}
8+
<tr>
9+
<th class="sort-ascending">
10+
<button class="clusterize-table-sorter p-2 relative text-left w-full">
11+
<div class="flex flex-row gap-2 items-center">
12+
<span class="sort-icon h-4 w-4 [&_img]:h-4 [&_img]:w-4">
13+
{% datatable_sort_icon %}
14+
</span>
15+
</div>
16+
</button>
17+
</th>
18+
{% for header in headers %}
19+
<th>
2420
<button class="clusterize-table-sorter p-2 relative text-left w-full">
2521
<div class="flex flex-row gap-2 items-center">
22+
{{ header }}
2623
<span class="sort-icon h-4 w-4 [&_img]:h-4 [&_img]:w-4">
2724
{% datatable_sort_icon %}
2825
</span>
2926
</div>
3027
</button>
3128
</th>
29+
{% endfor %}
30+
</tr>
31+
{% endfragment %}
32+
{% #clusterize_table header_row=header_row %}
33+
{% for index, row in rows %}
34+
<tr><td class="datatable-row-number">{{ index }}</td>
35+
{% for cell in row %}<td>{{ cell }}</td>{% endfor %}</tr>
36+
{% endfor %}
37+
{% /clusterize_table %}
38+
39+
{% else %}
40+
<table>
41+
<thead>
42+
<tr>
43+
<th></th>
3244
{% for header in headers %}
3345
<th>
34-
<button class="clusterize-table-sorter p-2 relative text-left w-full">
35-
<div class="flex flex-row gap-2 items-center">
36-
{{ header }}
37-
<span class="sort-icon h-4 w-4 [&_img]:h-4 [&_img]:w-4">
38-
{% datatable_sort_icon %}
39-
</span>
40-
</div>
41-
</button>
46+
{{ header }}
4247
</th>
4348
{% endfor %}
4449
</tr>
45-
{% endfragment %}
46-
{% #clusterize_table header_row=header_row %}
50+
</thead>
51+
<tbody>
4752
{% for index, row in rows %}
48-
<tr><td class="datatable-row-number">{{ index }}</td>
49-
{% for cell in row %}<td>{{ cell }}</td>{% endfor %}</tr>
50-
{% endfor %}
51-
{% /clusterize_table %}
52-
53-
{% else %}
54-
<table>
55-
<thead>
5653
<tr>
57-
<th></th>
58-
{% for header in headers %}
59-
<th>
60-
{{ header }}
61-
</th>
54+
<td>{{ index }}</td>
55+
{% for cell in row %}
56+
<td>{{ cell }}</td>
6257
{% endfor %}
6358
</tr>
64-
</thead>
65-
<tbody>
66-
{% for index, row in rows %}
67-
<tr>
68-
<td>{{ index }}</td>
69-
{% for cell in row %}
70-
<td>{{ cell }}</td>
71-
{% endfor %}
72-
</tr>
73-
{% endfor %}
74-
</tbody>
75-
</table>
76-
{% endif %}
77-
78-
</div>
79-
</body>
59+
{% endfor %}
60+
</tbody>
61+
</table>
62+
{% endif %}
8063

81-
</html>
64+
</div>
65+
{% endblock %}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
{% if truncated|default:False %}
2-
{% #alert variant="info" title="Log truncated" class="mt-4" no_icon=True %}
3-
This file is too large, and we have only show you the last secion.
4-
{% /alert %}
5-
{% endif %}
6-
<pre class="{{ class }}">
7-
{{ text }}
8-
</pre>
1+
{% extends "file_browser/file_content/content_base.html" %}
2+
{% block metatitle %}{{ filename }}{% endblock %}
3+
{% block content %}
4+
{% if truncated|default:False %}
5+
{% #alert variant="info" title="Log truncated" class="mt-4" no_icon=True %}
6+
This file is too large, so we have only shown you the last section.
7+
{% /alert %}
8+
{% endif %}
9+
<pre class="{{ class }}">{{ text }}</pre>
10+
{% endblock %}

tests/integration/views/test_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_code_contents_file(airlock_client):
133133
f"/code/contents/workspace/{repo.commit}/file.unknown"
134134
)
135135
assert response.status_code == 200
136-
assert b'<pre class="unknown">\nunknown\n</pre>\n' in response.content
136+
assert b'<pre class="unknown">unknown</pre>\n' in response.content
137137

138138

139139
def test_code_contents_file_yaml(airlock_client):
@@ -143,7 +143,7 @@ def test_code_contents_file_yaml(airlock_client):
143143
f"/code/contents/workspace/{repo.commit}/project.yaml"
144144
)
145145
assert response.status_code == 200
146-
assert b'<pre class="yaml">\nyaml: true\n</pre>' in response.content
146+
assert b'<pre class="yaml">yaml: true</pre>' in response.content
147147

148148

149149
def test_code_contents_directory(airlock_client):

tests/integration/views/test_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def test_request_contents_file(airlock_client):
763763
f"/requests/content/{release_request.id}/default/file.txt"
764764
)
765765
assert response.status_code == 200
766-
assert b'<pre class="txt">\ntest\n</pre>' in response.content
766+
assert b'<pre class="txt">test</pre>' in response.content
767767
audit_log = bll.get_request_audit_log(
768768
user=airlock_client.user,
769769
request=release_request,

tests/integration/views/test_workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def test_workspace_contents_file(airlock_client):
456456
factories.write_workspace_file("workspace", "file.txt", "test")
457457
response = airlock_client.get("/workspaces/content/workspace/file.txt")
458458
assert response.status_code == 200
459-
assert b'<pre class="txt">\ntest\n</pre>' in response.content
459+
assert b'<pre class="txt">test</pre>' in response.content
460460

461461

462462
def test_workspace_contents_dir(airlock_client):

0 commit comments

Comments
 (0)