Skip to content

Commit b7e4e3f

Browse files
Benjamin Brassoclaude
authored andcommitted
Remove CDC Landscape themes from theme selection dropdown
"CDC Landscape (Default)" (landscape-cdc-blue) and "CDC Landscape (Light)" (landscape-cdc-white) are unused and should no longer be selectable in the Builder's theme dropdown (#479). Filter them out in NofoThemeOptionsForm rather than removing them from models.THEME_CHOICES: Nofo.save() calls full_clean(), which validates the theme field against THEME_CHOICES on every save, not just theme changes. Removing the values there would make any pre-existing NOFO with one of these themes fail to save at all. Keeping them in THEME_CHOICES but excluding them from the form's dropdown choices removes them from selection while leaving existing NOFOs fully renderable and editable. If a NOFO's current theme is one of the two, it's still included in its own "Legacy" optgroup so the edit form shows/preserves that value instead of silently switching it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 9210d91 commit b7e4e3f

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

nofos/nofos/forms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def __init__(self, *args, user=None, **kwargs):
154154
# Keep legacy theme values valid on stored NOFOs, but do not offer them for new selection.
155155
RETIRED_THEME_CHOICES = {
156156
"portrait-hrsa-blue": "HRSA (Default, legacy)",
157+
"landscape-cdc-blue": "CDC Landscape (Default, legacy)",
158+
"landscape-cdc-white": "CDC Landscape (Light, legacy)",
157159
}
158160

159161

nofos/nofos/tests_nofos/test_theme_options.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,84 @@ def test_retired_hrsa_theme_submission_is_rejected(self):
323323
form = NofoThemeOptionsForm(data, instance=self.nofo, user=self.user)
324324
self.assertFalse(form.is_valid())
325325
self.assertIn("theme", form.errors)
326+
327+
328+
class RetiredCdcLandscapeThemeTests(TestCase):
329+
"""
330+
The "CDC Landscape (Default)" and "CDC Landscape (Light)" themes
331+
(landscape-cdc-blue / landscape-cdc-white) were removed from the
332+
Builder's theme selection dropdown (issue #479) because they were
333+
unused. They must not be offered as a choice on any NOFO, but a NOFO
334+
that already has one of these themes assigned must still show/preserve
335+
that value instead of silently switching to something else.
336+
"""
337+
338+
def setUp(self):
339+
self.user = _make_user("cdc")
340+
341+
def test_retired_themes_excluded_for_nofo_with_current_theme(self):
342+
nofo = _make_nofo("cdc", theme="portrait-cdc-blue")
343+
form = NofoThemeOptionsForm(instance=nofo, user=self.user)
344+
theme_values = _theme_choice_values(form)
345+
self.assertNotIn("landscape-cdc-blue", theme_values)
346+
self.assertNotIn("landscape-cdc-white", theme_values)
347+
348+
def test_retired_theme_preserved_when_already_assigned(self):
349+
nofo = _make_nofo("cdc", theme="landscape-cdc-blue")
350+
form = NofoThemeOptionsForm(instance=nofo, user=self.user)
351+
theme_values = _theme_choice_values(form)
352+
# The NOFO's own (retired) theme is preserved as a choice...
353+
self.assertIn("landscape-cdc-blue", theme_values)
354+
# ...but the *other* retired theme is still not offered.
355+
self.assertNotIn("landscape-cdc-white", theme_values)
356+
357+
def test_retired_theme_not_reintroduced_for_other_nofos(self):
358+
# Assigning the retired theme to one NOFO must not leak it back
359+
# into the choices offered for a different NOFO.
360+
_make_nofo("cdc", theme="landscape-cdc-blue")
361+
other_nofo = _make_nofo("cdc", theme="portrait-cdc-white")
362+
form = NofoThemeOptionsForm(instance=other_nofo, user=self.user)
363+
self.assertNotIn("landscape-cdc-blue", _theme_choice_values(form))
364+
365+
def test_get_edit_view_preserves_retired_theme(self):
366+
nofo = _make_nofo(
367+
"cdc",
368+
theme="landscape-cdc-white",
369+
cover="nofo--cover-page--hero",
370+
icon_style="nofo--icons--border",
371+
)
372+
client = Client()
373+
client.login(email="cdc@example.com", password="testpass123")
374+
url = reverse("nofos:nofo_edit_theme_options", kwargs={"pk": nofo.id})
375+
376+
response = client.get(url)
377+
378+
self.assertEqual(response.status_code, 200)
379+
nofo.refresh_from_db()
380+
self.assertEqual(nofo.theme, "landscape-cdc-white")
381+
self.assertContains(response, "CDC Landscape (Light, legacy)")
382+
self.assertContains(response, 'value="landscape-cdc-white" selected')
383+
384+
def test_valid_submission_can_keep_existing_retired_theme(self):
385+
# A user shouldn't be forced off a retired theme just because
386+
# it's no longer offered for *new* selections.
387+
nofo = _make_nofo("cdc", theme="landscape-cdc-blue")
388+
data = {
389+
"theme": "landscape-cdc-blue",
390+
"cover": "nofo--cover-page--text",
391+
"icon_style": "nofo--icons--solid",
392+
}
393+
form = NofoThemeOptionsForm(data, instance=nofo, user=self.user)
394+
self.assertTrue(form.is_valid(), form.errors)
395+
396+
def test_retired_theme_submission_is_rejected_for_other_nofo(self):
397+
# Switching *into* a retired theme from a non-retired one must fail.
398+
nofo = _make_nofo("cdc", theme="portrait-cdc-blue")
399+
data = {
400+
"theme": "landscape-cdc-blue",
401+
"cover": "nofo--cover-page--text",
402+
"icon_style": "nofo--icons--solid",
403+
}
404+
form = NofoThemeOptionsForm(data, instance=nofo, user=self.user)
405+
self.assertFalse(form.is_valid())
406+
self.assertIn("theme", form.errors)

0 commit comments

Comments
 (0)