new _applets partial to govern applet list; home.html updated accordingly to incl partial; fixed seed migrations for palette convention from last commit; new text_view ITs & views to govern applet visibility/toggling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -4,7 +4,7 @@ from django.db import migrations
|
||||
def seed_applets(apps, schema_editor):
|
||||
Applet = apps.get_model("dashboard", "Applet")
|
||||
Applet.objects.get_or_create(slug="username", defaults={"name": "Username"})
|
||||
Applet.objects.get_or_create(slug="theme-switcher", defaults={"name": "Theme Switcher"})
|
||||
Applet.objects.get_or_create(slug="palette", defaults={"name": "Palette"})
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -210,7 +210,11 @@ class ShareListTest(TestCase):
|
||||
f"/dashboard/list/{our_list.id}/share_list",
|
||||
data={"recipient": "nobody@example.com"},
|
||||
)
|
||||
self.assertRedirects(response, f"/dashboard/list/{our_list.id}/")
|
||||
self.assertRedirects(
|
||||
response,
|
||||
f"/dashboard/list/{our_list.id}/",
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
def test_share_list_does_not_add_owner_as_recipient(self):
|
||||
owner = User.objects.create(email="owner@example.com")
|
||||
@@ -374,3 +378,27 @@ class ToggleAppletsViewTest(TestCase):
|
||||
HTTP_HX_REQUEST="true",
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_htmx_post_renders_visible_applets_only(self):
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"applets": ["username"]},
|
||||
HTTP_HX_REQUEST="true",
|
||||
)
|
||||
parsed = lxml.html.fromstring(response.content)
|
||||
self.assertEqual(len(parsed.cssselect("#id_applet_username")), 1)
|
||||
self.assertEqual(len(parsed.cssselect("#id_applet_palette")), 0)
|
||||
|
||||
class AppletVisibilityContextTest(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create(email="disco@test.io")
|
||||
self.client.force_login(self.user)
|
||||
self.username_applet, _ = Applet.objects.get_or_create(slug="username", defaults={"name": "Username"})
|
||||
self.palette_applet, _ = Applet.objects.get_or_create(slug="palette", defaults={"name": "Palette"})
|
||||
UserApplet.objects.create(user=self.user, applet=self.palette_applet, visible=False)
|
||||
|
||||
def test_dash_reflects_user_applet_visibility(self):
|
||||
response = self.client.get("/")
|
||||
applet_map = {entry["applet"].slug: entry["visible"] for entry in response.context["applets"]}
|
||||
self.assertFalse(applet_map["palette"])
|
||||
self.assertTrue(applet_map["username"])
|
||||
|
||||
@@ -16,12 +16,18 @@ PALETTES = [
|
||||
]
|
||||
|
||||
|
||||
def _applet_context(user):
|
||||
ua_map = {ua.applet_id: ua.visible for ua in user.user_applets.all()}
|
||||
return [
|
||||
{"applet": applet, "visible": ua_map.get(applet.pk, applet.default_visible)}
|
||||
for applet in Applet.objects.all()
|
||||
]
|
||||
|
||||
def home_page(request):
|
||||
return render(
|
||||
request, "apps/dashboard/home.html", {
|
||||
"form": ItemForm(),
|
||||
"palettes": PALETTES,
|
||||
})
|
||||
context = {"form": ItemForm(), "palettes": PALETTES}
|
||||
if request.user.is_authenticated:
|
||||
context["applets"] = _applet_context(request.user)
|
||||
return render(request, "apps/dashboard/home.html", context)
|
||||
|
||||
def new_list(request):
|
||||
form = ItemForm(data=request.POST)
|
||||
@@ -100,5 +106,8 @@ def toggle_applets(request):
|
||||
defaults={"visible": applet.slug in checked},
|
||||
)
|
||||
if request.headers.get("HX-Request"):
|
||||
return HttpResponse("")
|
||||
return render(request, "apps/dashboard/_partials/_applets.html", {
|
||||
"applets": _applet_context(request.user),
|
||||
"palettes": PALETTES,
|
||||
})
|
||||
return redirect("home")
|
||||
|
||||
Reference in New Issue
Block a user