Skip to content

Commit 13ee3d3

Browse files
committed
templates/profile: Add theme selector to settings
Add a Light/Dark theme selector to the user profile settings box and persist the preference in localStorage. Signed-off-by: Andrea Cervesato <andrea.cervesato@mailbox.org> Assisted-by: Gemini 3.8 Flash
1 parent 032d7e8 commit 13ee3d3

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎patchwork/templates/patchwork/profile.html‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,19 @@ <h2>Bundles</h2>
120120
<div class="box">
121121
<h2>Settings</h2>
122122

123-
<form method="post">
123+
<form method="post" id="profile-settings-form">
124124
{% csrf_token %}
125125
<table class="form">
126126
{{ profileform }}
127+
<tr>
128+
<th><label for="theme-select">Theme:</label></th>
129+
<td>
130+
<select id="theme-select" name="theme">
131+
<option value="light">Light</option>
132+
<option value="dark">Dark</option>
133+
</select>
134+
</td>
135+
</tr>
127136
<tr>
128137
<td></td>
129138
<td><input type="submit" value="Apply"/></td>
@@ -168,4 +177,36 @@ <h2>Authentication</h2>
168177
</div>
169178

170179
<p style="clear: both"></p>
180+
<script>
181+
$(document).ready(function() {
182+
var themeSelect = document.getElementById('theme-select');
183+
if (!themeSelect) {
184+
return;
185+
}
186+
var savedTheme = 'light';
187+
try {
188+
savedTheme = localStorage.getItem('pw_theme') || 'light';
189+
} catch (e) {}
190+
themeSelect.value = savedTheme;
191+
192+
function applySelectedTheme(val) {
193+
try {
194+
localStorage.setItem('pw_theme', val);
195+
} catch (e) {}
196+
if (val === 'dark') {
197+
document.documentElement.setAttribute('data-theme', 'dark');
198+
} else {
199+
document.documentElement.removeAttribute('data-theme');
200+
}
201+
}
202+
203+
$(themeSelect).change(function() {
204+
applySelectedTheme(this.value);
205+
});
206+
207+
$('#profile-settings-form').submit(function() {
208+
applySelectedTheme(themeSelect.value);
209+
});
210+
});
211+
</script>
171212
{% endblock %}

‎patchwork/tests/unit/views/test_user.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ def test_user_profile_invalid_post(self):
427427
user_profile = UserProfile.objects.get(user=self.user.id)
428428
self.assertEqual(user_profile.items_per_page, old_ppp)
429429

430+
def test_user_profile_theme_setting(self):
431+
response = self.client.get(reverse('user-profile'))
432+
self.assertContains(response, 'id="theme-select"')
433+
self.assertContains(response, 'Theme:')
434+
430435

431436
class PasswordChangeTest(_UserTestCase):
432437
def test_password_change_form(self):

0 commit comments

Comments
 (0)