many styling changes to applets and palettes applet esp.; all applets seeded w. < 3rows bumped to 3 w. new migration in apps.applets; setting palette no longer reloads entire page, only preset background-color vars; two new ITs in apps.dash.tests.ITs.test_views.SetPaletteTest to ensure dash.views functionality fires; unified h2 applet title html structure & styled its text vertically to waste less applet space
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Disco DeDisco
2026-03-24 00:26:22 -04:00
parent cc02419e8d
commit 62f6c27806
16 changed files with 147 additions and 17 deletions

View File

@@ -8,3 +8,27 @@ const initialize = (inputSelector) => {
textInput.classList.remove("is-invalid");
};
};
const bindPaletteForms = () => {
document.querySelectorAll('form[action*="set_palette"]').forEach(form => {
form.addEventListener("submit", async (e) => {
e.preventDefault();
const resp = await fetch(form.action, {
method: "POST",
headers: { "Accept": "application/json" },
body: new FormData(form, e.submitter),
});
if (!resp.ok) return;
const { palette } = await resp.json();
// Swap body palette class
[...document.body.classList]
.filter(c => c.startsWith("palette-"))
.forEach(c => document.body.classList.remove(c));
document.body.classList.add(palette);
// Update active swatch indicator
document.querySelectorAll(".swatch").forEach(sw => {
sw.classList.toggle("active", sw.classList.contains(palette));
});
});
});
};

View File

@@ -299,6 +299,24 @@ class SetPaletteTest(TestCase):
response = self.client.post("/dashboard/set_palette", data={"palette": "palette-default"})
self.assertRedirects(response, "/", fetch_redirect_response=False)
def test_set_palette_returns_json_when_requested(self):
response = self.client.post(
"/dashboard/set_palette",
data={"palette": "palette-sepia"},
headers={"Accept": "application/json"},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {"palette": "palette-sepia"})
def test_locked_palette_returns_unchanged_json(self):
response = self.client.post(
"/dashboard/set_palette",
data={"palette": "palette-nirvana"},
headers={"Accept": "application/json"},
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {"palette": "palette-default"})
def test_dashboard_contains_set_palette_form(self):
response = self.client.get(self.url)
parsed = lxml.html.fromstring(response.content)

View File

@@ -122,6 +122,8 @@ def set_palette(request):
if palette in UNLOCKED_PALETTES:
request.user.palette = palette
request.user.save(update_fields=["palette"])
if "application/json" in request.headers.get("Accept", ""):
return JsonResponse({"palette": request.user.palette})
return redirect("home")
@login_required(login_url="/")