1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add page for user to view/clear preferences

This commit is contained in:
Jeremy Stretch
2020-04-24 10:29:06 -04:00
parent 7c8c85e435
commit 587339bea0
4 changed files with 56 additions and 11 deletions

View File

@ -12,6 +12,9 @@
<li{% ifequal active_tab "profile" %} class="active"{% endifequal %}>
<a href="{% url 'user:profile' %}">Profile</a>
</li>
<li{% ifequal active_tab "preferences" %} class="active"{% endifequal %}>
<a href="{% url 'user:preferences' %}">Preferences</a>
</li>
{% if not request.user.ldap_username %}
<li{% ifequal active_tab "change_password" %} class="active"{% endifequal %}>
<a href="{% url 'user:change_password' %}">Change Password</a>

View File

@ -4,15 +4,32 @@
{% block title %}User Preferences{% endblock %}
{% block usercontent %}
{% if preferences %}
<form method="post" action="">
{% csrf_token %}
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" class="toggle" title="Toggle all"></th>
<th>Preference</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for %}
{% for key, value in preferences.items %}
<tr>
<td class="min-width"><input type="checkbox" name="pk" value="{{ key }}"></td>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="submit" class="btn btn-danger">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Clear Selected
</button>
</form>
{% else %}
<h3 class="text-muted text-center">No preferences found</h3>
{% endif %}
{% endblock %}

View File

@ -6,6 +6,7 @@ app_name = 'user'
urlpatterns = [
path('profile/', views.ProfileView.as_view(), name='profile'),
path('preferences/', views.UserConfigView.as_view(), name='preferences'),
path('password/', views.ChangePasswordView.as_view(), name='change_password'),
path('api-tokens/', views.TokenListView.as_view(), name='token_list'),
path('api-tokens/add/', views.TokenEditView.as_view(), name='token_add'),

View File

@ -111,6 +111,30 @@ class ProfileView(LoginRequiredMixin, View):
})
class UserConfigView(LoginRequiredMixin, View):
template_name = 'users/preferences.html'
def get(self, request):
return render(request, self.template_name, {
'preferences': request.user.config.all(),
'active_tab': 'preferences',
})
def post(self, request):
userconfig = request.user.config
data = userconfig.all()
# Delete selected preferences
for key in request.POST.getlist('pk'):
if key in data:
userconfig.clear(key)
userconfig.save()
messages.success(request, "Your preferences have been updated.")
return redirect('user:preferences')
class ChangePasswordView(LoginRequiredMixin, View):
template_name = 'users/change_password.html'