Introduce UserConfigForm for managing user preferences

This commit is contained in:
jeremystretch
2021-12-21 16:29:01 -05:00
parent 5e32c69e0e
commit 70f257b1ea
8 changed files with 103 additions and 105 deletions

View File

@@ -1,57 +1,27 @@
{% extends 'users/base.html' %}
{% load helpers %}
{% load form_helpers %}
{% block title %}User Preferences{% endblock %}
{% block content %}
<form method="post" action="" id="preferences-update">
{% csrf_token %}
<div class="field-group mb-3">
<h5>Color Mode</h5>
<p class="text-muted">Set preferred UI color mode</p>
{% with color_mode=preferences|get_key:'ui.colormode'%}
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="ui.colormode" id="color-mode-preference-dark" value="dark"{% if color_mode == 'dark'%} checked{% endif %}>
<label class="form-check-label" for="color-mode-preference-dark">Dark</label>
{% for group, fields in form.Meta.fieldsets %}
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{{ group }}</h5>
</div>
{% for name in fields %}
{% render_field form|getfield:name %}
{% endfor %}
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="ui.colormode" id="color-mode-preference-light" value="light"{% if color_mode == 'light'%} checked{% endif %}>
<label class="form-check-label" for="color-mode-preference-light">Light</label>
</div>
{% endwith %}
{% endfor %}
<div class="text-end my-3">
<a class="btn btn-outline-secondary" href="{% url 'user:preferences' %}">Cancel</a>
<button type="submit" name="_update" class="btn btn-primary">Save </button>
</div>
<div class="row mb-3">
<div class="col">
<button type="submit" class="btn btn-primary" name="_update">Save</button>
</div>
</div>
{% if preferences %}
<div class="field-group mb-3">
<h5>Other Preferences</h5>
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" class="toggle form-check-input" title="Toggle All"></th>
<th>Preference</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in preferences.items %}
<tr>
<td class="min-width"><input class="form-check-input" type="checkbox" name="pk" value="{{ key }}"></td>
<td><samp>{{ key }}</samp></td>
<td><samp>{{ value }}</samp></td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="submit" class="btn btn-danger" name="_delete">
<span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> Clear Selected
</button>
</div>
{% else %}
<h3 class="text-muted text-center">No preferences found</h3>
{% endif %}
</form>
{% endblock %}