Add a form to edit basic user settings

- First / last name
- Email address
This commit is contained in:
Oliver Walters 2019-05-14 13:33:47 +10:00
parent 3c6d5756c5
commit 0032ea3409
4 changed files with 68 additions and 5 deletions

View File

@ -7,7 +7,7 @@ from __future__ import unicode_literals
from django import forms
from crispy_forms.helper import FormHelper
from django.contrib.auth.models import User
class HelperForm(forms.ModelForm):
""" Provides simple integration of crispy_forms extension. """
@ -33,3 +33,16 @@ class DeleteForm(forms.Form):
fields = [
'confirm_delete'
]
class EditUserForm(HelperForm):
""" Form for editing user information
"""
class Meta:
model = User
fields = [
'first_name',
'last_name',
'email'
]

View File

@ -30,7 +30,7 @@ from django.conf.urls.static import static
from django.views.generic.base import RedirectView
from rest_framework.documentation import include_docs_urls
from .views import IndexView, SearchView, SettingsView
from .views import IndexView, SearchView, SettingsView, EditUserView
from users.urls import user_urls
@ -64,6 +64,8 @@ urlpatterns = [
url(r'^settings/', SettingsView.as_view(), name='settings'),
url(r'^edit-user/', EditUserView.as_view(), name='edit-user'),
url(r'^admin/', admin.site.urls, name='inventree-admin'),
url(r'^qr_code/', include(qr_code_urls, namespace='qr_code')),

View File

@ -17,7 +17,7 @@ from django.views.generic.base import TemplateView
from part.models import Part
from .forms import DeleteForm
from .forms import DeleteForm, EditUserForm
from .helpers import str2bool
from rest_framework import views
@ -371,6 +371,18 @@ class AjaxDeleteView(AjaxMixin, UpdateView):
return self.renderJsonResponse(request, form, data=data, context=context)
class EditUserView(AjaxUpdateView):
""" View for editing user information """
ajax_template_name = "modal_form.html"
ajax_form_title = "Edit User Information"
form_class = EditUserForm
def get_object(self):
return self.request.user
class IndexView(TemplateView):
""" View for InvenTree index page """

View File

@ -5,10 +5,36 @@ InvenTree | Settings
{% endblock %}
{% block content %}
<h3>Settings</h3>
<h3>InvenTree Settings</h3>
<hr>
Logged in as {{ user.username }}
<div class='row'>
<div class='col-sm-6'>
<h4>User Information</h4>
</div>
<div class='col-sm-6'>
<div class='btn-group' style='float: right;'>
<div class='btn btn-primary' type='button' id='edit-user' title='Edit User Information'>Edit</div>
<div class='btn btn-primary' type='button' id='edit-password' title='Change Password'>Set Password</div>
</div>
</div>
</div>
<table class='table table-striped table-condensed'>
<tr>
<td>First Name</td>
<td>{{ user.first_name }}</td>
</tr>
<tr>
<td>Last Name</td>
<td>{{ user.last_name }}</td>
</tr>
<tr>
<td>Email Address</td>
<td>{{ user.email }}</td>
</tr>
</table>
{% endblock %}
@ -18,4 +44,14 @@ Logged in as {{ user.username }}
{% block js_ready %}
{{ block.super }}
$("#edit-user").on('click', function() {
launchModalForm(
"{% url 'edit-user' %}",
{
reload: true,
}
);
});
{% endblock %}