Skip to content

Commit 009a1c7

Browse files
manderjstephane
authored andcommitted
tests: serve common templates css through static files
1 parent af48c9b commit 009a1c7

File tree

8 files changed

+19
-67
lines changed

8 files changed

+19
-67
lines changed

testproj/README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
3 pip install ..
44
4. ./manage.py migrate
55
5. ./manage.py loaddata secretfiles
6-
6. ./manage.py runserver
6+
6. ./manage.py collectstatic
7+
7. ./manage.py runserver
78

89
To run tests: ./manage.py test

testproj/testproj/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
# Static files (CSS, JavaScript, Images)
122122
# https://docs.djangoproject.com/en/3.1/howto/static-files/
123123

124+
STATIC_ROOT = "static/"
124125
STATIC_URL = "/static/"
125126

126127
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

testproj/testproj/testapp/jinja2/env.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from jinja2.environment import Environment
22

33
from django.template.defaultfilters import yesno
4+
from django.templatetags.static import static
45
from webstack_django_sorting.jinja2_globals import (
56
sorting_anchor,
67
sort_queryset,
@@ -13,3 +14,4 @@ def __init__(self, **kwargs):
1314
self.filters["yesno"] = yesno
1415
self.globals["sorting_anchor"] = sorting_anchor
1516
self.globals["sort_queryset"] = sort_queryset
17+
self.globals["static"] = static

testproj/testproj/testapp/jinja2/secret_list.jinja2

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
<html>
22
<head>
3-
<style>
4-
body {
5-
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
6-
line-height: 1.42857143;
7-
color: #333;
8-
}
9-
10-
table {
11-
border-spacing: 0;
12-
border-collapse: collapse;
13-
}
14-
15-
thead>tr>th {
16-
vertical-align: bottom;
17-
border-bottom: 2px solid #ddd;
18-
text-align: left;
19-
}
20-
21-
thead>tr>th>a {
22-
text-decoration: none;
23-
}
24-
25-
thead>tr>th>a:visited {
26-
color: inherit;
27-
}
28-
29-
tr>th, tr>td {
30-
padding: 8px;
31-
line-height: 1.42857143;
32-
}
33-
</style>
3+
<link rel="stylesheet" href="{{ static('css/style.css') }}"/>
344
</head>
355
<body>
366
<h2>List of files</h2>

testproj/testproj/testapp/templates/secret_list.html

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
1-
{% load sorting_tags %}
1+
{% load static sorting_tags %}
22

33
<html>
44
<head>
5-
<style>
6-
body {
7-
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
8-
line-height: 1.42857143;
9-
color: #333;
10-
}
11-
12-
table {
13-
border-spacing: 0;
14-
border-collapse: collapse;
15-
}
16-
17-
thead>tr>th {
18-
vertical-align: bottom;
19-
border-bottom: 2px solid #ddd;
20-
text-align: left;
21-
}
22-
23-
thead>tr>th>a {
24-
text-decoration: none;
25-
}
26-
27-
thead>tr>th>a:visited {
28-
color: inherit;
29-
}
30-
31-
tr>th, tr>td {
32-
padding: 8px;
33-
line-height: 1.42857143;
34-
}
35-
</style>
5+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
366
</head>
377
<body>
388
<h2>List of files</h2>

testproj/testproj/testapp/templates/secret_list_nulls_first.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
{% load sorting_tags %}
1+
{% load static sorting_tags %}
22

33
<html>
4+
<head>
5+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
6+
</head>
47
<body>
58
<h2>List of files</h2>
69
{% autosort secret_files nulls_first=True %}

testproj/testproj/testapp/templates/secret_list_nulls_last.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
{% load sorting_tags %}
1+
{% load static sorting_tags %}
22

33
<html>
4+
<head>
5+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
6+
</head>
47
<body>
58
<h2>List of files</h2>
69
{% autosort secret_files nulls_last=True %}

testproj/testproj/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from django.contrib import admin
2+
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
23
from django.urls import path
34

45
from .testapp import views
56

7+
68
urlpatterns = [
79
path("", views.secret_list, name="secret_list"),
810
path("nulls_first", views.secret_list_nulls_first, name="nulls_first"),
911
path("nulls_last", views.secret_list_nulls_last, name="nulls_last"),
1012
path("jinja2", views.secret_list_jinja2, name="secret_list_jinja2"),
1113
path("admin/", admin.site.urls),
12-
]
14+
] + staticfiles_urlpatterns()

0 commit comments

Comments
 (0)