Skip to content

Commit 72d69b2

Browse files
authored
Feat: base template setup (#97)
2 parents 988af59 + 08e3474 commit 72d69b2

File tree

12 files changed

+245
-4
lines changed

12 files changed

+245
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.tmp
66
*.egg-info
77
static/
8+
!pems/static
89
__pycache__/
910
.coverage
1011
.DS_Store

pems/core/context_processors.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
The core application: context processors for enriching request context data.
3+
"""
4+
5+
from pems import __version__
6+
7+
8+
def pems_version(request):
9+
"""Context processor adds information about the PeMS application's version."""
10+
11+
return {"pems_version": __version__}

pems/core/templates/core/base.html

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Performance Measurement System (PeMS)</title>
7+
<meta name="Author" content="State of California" />
8+
<meta name="Description" content="Caltrans" />
9+
<meta name="Keywords" content="California, government" />
10+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
11+
<!-- Public Sans font google API -->
12+
<link rel="preconnect" href="https://fonts.googleapis.com" />
13+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
14+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,100..900;1,100..900&display=block" />
15+
<!-- State Template CDN CSS -->
16+
<link rel="stylesheet"
17+
href="https://cdn.cdt.ca.gov/cdt/statetemplate/6.4.1/css/cagov.core.css"
18+
integrity="sha256-OGe4kV30/3p8qPhmiORxFvLS/NrPhdifrumYA6W5W5k="
19+
crossorigin="anonymous" />
20+
<link rel="stylesheet"
21+
href="https://cdn.cdt.ca.gov/cdt/statetemplate/6.4.1/css/colortheme-oceanside.css"
22+
integrity="sha256-PC5Yszm8bAjYYFmjeL8EeB8mHo+S4dJbQt4OwA4aTmg="
23+
crossorigin="anonymous" />
24+
<link rel="stylesheet" href="{% static "css/styles.css" %}">
25+
<!-- State Template JavaScript CDN -->
26+
<script src="https://cdn.cdt.ca.gov/cdt/statetemplate/6.4.1/js/cagov.core.js"
27+
integrity="sha256-TOklMoh1iWoUNIVyzn+Wq8bS56lQWa0R8qklisvEALo="
28+
defer
29+
crossorigin="anonymous"></script>
30+
</head>
31+
<body class="primary">
32+
<header role="banner" id="header" class="global-header fixed">
33+
<!-- Utility header structural component -->
34+
<div class="utility-header">
35+
<div class="container">
36+
<div class="flex-row">
37+
<div class="social-media-links">
38+
<div class="header-cagov-logo">
39+
<a href="https://www.ca.gov">
40+
<span class="sr-only">CA.gov</span>
41+
<span class="ca-gov-logo-svg"></span>
42+
</a>
43+
</div>
44+
<p class="official-tag">
45+
<span class="desktop-only">Official website of the</span>
46+
State of California
47+
</p>
48+
</div>
49+
<div class="settings-links">
50+
<a href="https://github.com/compilerla/pems/releases">PeMS {{ pems_version }}</a>
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
<!-- header branding with light gray background -->
56+
<div class="section-default">
57+
<div class="branding">
58+
<div class="header-organization-banner">
59+
<a href="{% url 'core:index' %}">
60+
<div class="logo-assets">
61+
<img class="logo-img" width="150" height="26" src="{% static "img/caltranslogo.png" %}" alt="Caltrans official logo" />
62+
<div class="logo-text">
63+
<span class="logo-state">Caltrans</span>
64+
<span class="logo-dept">Performance Measurement System (PeMS)</span>
65+
</div>
66+
</div>
67+
</a>
68+
</div>
69+
</div>
70+
</div>
71+
<!-- mobile navigation controls -->
72+
<div class="mobile-controls">
73+
<span class="mobile-control-group mobile-header-icons">
74+
<!-- Add more mobile controls here. These will be on the right side of the mobile page header section -->
75+
</span>
76+
<div class="mobile-control-group main-nav-icons">
77+
<button id="nav-icon3" type="button" class="mobile-control toggle-menu" aria-expanded="false" aria-controls="navigation">
78+
<span aria-hidden="true"></span>
79+
<span aria-hidden="true"></span>
80+
<span aria-hidden="true"></span>
81+
<span aria-hidden="true"></span>
82+
<span class="sr-only">Menu</span>
83+
</button>
84+
</div>
85+
</div>
86+
<!-- Top Level Navigation Only -->
87+
<div class="navigation-search full-width-nav container">
88+
<div id="head-search" class="search-container featured-search">
89+
<div class="d-block d-lg-none">
90+
<a href="{% url 'core:index' %}" class="drawer-logo-link first-level-link">
91+
<img src="https://cdn.cdt.ca.gov/cdt/cagov/cagov-lockup/cagov-lockup-flag/cagov-lockup-flag-gradient/cagov-lockup-flag-gradient.svg"
92+
alt="CA.gov official logo"
93+
class="drawer-logo mb-4" />
94+
</a>
95+
</div>
96+
</div>
97+
<nav id="navigation" class="main-navigation singlelevel" aria-label="Main navigation">
98+
<ul id="nav_list" class="top-level-nav">
99+
<li class="nav-item">
100+
<a href="{% url 'core:index' %}" class="first-level-link">Home</a>
101+
</li>
102+
<li class="nav-item">
103+
<a href="{% url 'districts:index' %}" class="first-level-link">Districts</a>
104+
</li>
105+
<li class="nav-item">
106+
<a href="" class="first-level-link">Clearinghouse</a>
107+
</li>
108+
<li class="nav-item">
109+
<a href="" class="first-level-link">About</a>
110+
</li>
111+
</ul>
112+
</nav>
113+
</div>
114+
</header>
115+
<div id="main-content" class="main-content">
116+
<div class="container">
117+
<main class="main-primary">
118+
<h1>
119+
{% block headline %}
120+
{% endblock headline %}
121+
</h1>
122+
{% block inner-content %}
123+
{% endblock inner-content %}
124+
</main>
125+
</div>
126+
</div>
127+
<!-- Global Footer -->
128+
<footer id="footer" class="global-footer">
129+
<div class="container">
130+
<div class="d-flex">
131+
<a href="https://www.ca.gov" class="cagov-logo">
132+
<span class="sr-only">CA.gov</span>
133+
<span class="ca-gov-logo-svg"></span>
134+
</a>
135+
<ul class="footer-links">
136+
<li>
137+
<a href="{% url 'core:index' %}">Conditions of use</a>
138+
</li>
139+
<li>
140+
<a href="{% url 'core:index' %}">Privacy policy</a>
141+
</li>
142+
</ul>
143+
<ul class="socialsharer-container">
144+
<li>
145+
<a href="https://github.com/compilerla/pems/">
146+
<span class="ca-gov-icon-github" aria-hidden="true"></span>
147+
<span class="sr-only">GitHub</span>
148+
</a>
149+
</li>
150+
</ul>
151+
</div>
152+
</div>
153+
<!-- Copyright Statement -->
154+
<div class="copyright">
155+
<div class="container text-right">
156+
<span aria-hidden="true">©</span>
157+
<span id="thisyear">
158+
<script>document.getElementById('thisyear').appendChild(document.createTextNode(new Date().getFullYear()))</script>
159+
</span>
160+
State of California
161+
</div>
162+
</div>
163+
<button class="return-top">
164+
<span class="sr-only">Back to top</span>
165+
</button>
166+
</footer>
167+
</body>
168+
</html>

pems/core/templates/core/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "core/base.html" %}
2+
{% block headline %}
3+
Home page
4+
{% endblock headline %}
5+
{% block inner-content %}
6+
<p>This is the home page</p>
7+
{% endblock inner-content %}

pems/core/urls.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.urls import path
2+
from django.views.generic import TemplateView
3+
4+
app_name = "core"
5+
6+
# /
7+
urlpatterns = [
8+
path("", TemplateView.as_view(template_name="core/index.html"), name="index"),
9+
]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>District {{ district }}</h1>
2-
<p> URL of route: {% url "districts:district" district%} </p>
2+
<p>URL of route: {% url "districts:district" district %}</p>
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<h1>Districts</h1>
1+
{% extends "core/base.html" %}
2+
{% block headline %}
3+
Districts
4+
{% endblock headline %}
5+
{% block inner-content %}
6+
<p>Districts</p>
7+
{% endblock inner-content %}

pems/settings.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _filter_empty(ls):
3131
"django.contrib.sessions",
3232
"django.contrib.messages",
3333
"django.contrib.staticfiles",
34+
"pems.core",
3435
"pems.districts",
3536
"pems.streamlit_sample",
3637
]
@@ -59,6 +60,7 @@ def _filter_empty(ls):
5960
"django.template.context_processors.request",
6061
"django.contrib.auth.context_processors.auth",
6162
"django.contrib.messages.context_processors.messages",
63+
"pems.core.context_processors.pems_version",
6264
],
6365
},
6466
},
@@ -113,10 +115,25 @@ def _filter_empty(ls):
113115
# Static files (CSS, JavaScript, Images)
114116
# https://docs.djangoproject.com/en/5.1/howto/static-files/
115117

116-
STATIC_URL = "static/"
118+
STATIC_URL = "/static/"
119+
120+
STATICFILES_DIRS = [os.path.join(BASE_DIR, "pems", "static")]
121+
122+
# use Manifest Static Files Storage by default
123+
STORAGES = {
124+
"default": {
125+
"BACKEND": "django.core.files.storage.FileSystemStorage",
126+
},
127+
"staticfiles": {
128+
"BACKEND": os.environ.get(
129+
"DJANGO_STATICFILES_STORAGE", "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
130+
)
131+
},
132+
}
117133

118134
STATIC_ROOT = os.path.join(BASE_DIR, "static")
119135

136+
120137
# Default primary key field type
121138
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
122139

pems/static/css/styles.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
header {
2+
> div.navigation-search {
3+
> div.search-container > div.d-block > a.drawer-logo-link {
4+
outline-offset: -3px;
5+
> img.drawer-logo {
6+
width: 232px;
7+
filter: brightness(0) invert(1);
8+
aspect-ratio: 18/5;
9+
}
10+
}
11+
}
12+
}

pems/static/img/caltranslogo.png

6.84 KB
Loading

pems/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.urls import include, path
33

44
urlpatterns = [
5+
path("", include("pems.core.urls")),
56
path("admin/", admin.site.urls),
67
path("districts/", include("pems.districts.urls")),
78
path("streamlit/", include("pems.streamlit_sample.urls")),

pyproject.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ maintainers = [{ name = "Compiler LLC", email = "[email protected]" }]
1010
dependencies = ["Django==5.1.6", "gunicorn==23.0.0"]
1111

1212
[project.optional-dependencies]
13-
dev = ["black", "flake8", "pre-commit", "setuptools_scm>=8"]
13+
dev = ["black", "djlint", "flake8", "pre-commit", "setuptools_scm>=8"]
1414

1515
test = ["coverage", "pytest", "pytest-django", "pytest-mock", "pytest-socket"]
1616

@@ -34,6 +34,15 @@ relative_files = true
3434
source = ["pems", "streamlit_app"]
3535
omit = ["streamlit_app/apps/*"]
3636

37+
[tool.djlint]
38+
ignore = "H006,H017,H031"
39+
indent = 2
40+
max_attribute_length = 127
41+
max_line_length = 127
42+
profile = "django"
43+
preserve_blank_lines = true
44+
use_gitignore = true
45+
3746
[tool.pytest.ini_options]
3847
DJANGO_SETTINGS_MODULE = "pems.settings"
3948

0 commit comments

Comments
 (0)