diff --git a/accounts_app/forms.py b/accounts_app/forms.py index a29d771..f8fcc82 100644 --- a/accounts_app/forms.py +++ b/accounts_app/forms.py @@ -47,3 +47,9 @@ class UserPermissionsForm(forms.ModelForm): class Meta: model = UserProfile fields = 'user_permissions', + + +class UserProfileForm(forms.ModelForm): + class Meta: + model = UserProfile + exclude = ('avatar',) diff --git a/accounts_app/locale/ru/LC_MESSAGES/django.po b/accounts_app/locale/ru/LC_MESSAGES/django.po index f619350..3e62963 100644 --- a/accounts_app/locale/ru/LC_MESSAGES/django.po +++ b/accounts_app/locale/ru/LC_MESSAGES/django.po @@ -233,10 +233,6 @@ msgstr "Сбросить" msgid "User name" msgstr "Логин" -#: templates/accounts/index.html:17 templates/accounts/settings/ch_info.html:19 -msgid "Name and surname" -msgstr "Фамилия и Имя" - #: templates/accounts/index.html:21 msgid "Is enable" msgstr "Включён-ли" @@ -313,14 +309,6 @@ msgstr "Изменение прав доступа для выбранного msgid "The list of user groups to which the account has access" msgstr "Список групп абонентов, к которым учётка имеет доступ" -#: templates/accounts/settings/ch_info.html:48 -msgid "Old password" -msgstr "Старый пароль" - -#: templates/accounts/settings/ch_info.html:57 -msgid "New password" -msgstr "Новый пароль" - #: views.py:33 msgid "Wrong login or password, please try again" msgstr "Неправильный логин или пароль, попробуйте ещё раз" @@ -385,3 +373,6 @@ msgstr "Лог действий" msgid "Administrator" msgstr "Сотрудник" + +msgid "Saved successfully" +msgstr "Успешно сохранено" diff --git a/accounts_app/templates/accounts/settings/ch_info.html b/accounts_app/templates/accounts/settings/ch_info.html deleted file mode 100644 index b716525..0000000 --- a/accounts_app/templates/accounts/settings/ch_info.html +++ /dev/null @@ -1,75 +0,0 @@ -{% extends request.is_ajax|yesno:'nullcont.htm,accounts/settings/ext.htm' %} -{% load globaltags i18n %} -{% block content %} - -
{% csrf_token %} - -
- - -
- - -
-
- -
- - -
- - -
-
- -
- - -
- - -
-
- -
- - -
- - -
-
- -
- - -
- - -
-
- -
- - -
- - -
-
- -
- - -
- -
- -{% endblock %} \ No newline at end of file diff --git a/accounts_app/templates/accounts/userprofile_form.html b/accounts_app/templates/accounts/userprofile_form.html new file mode 100644 index 0000000..b35e322 --- /dev/null +++ b/accounts_app/templates/accounts/userprofile_form.html @@ -0,0 +1,20 @@ +{% extends request.is_ajax|yesno:'nullcont.htm,accounts/settings/ext.htm' %} +{% load globaltags i18n bootstrap3 %} +{% block content %} + +
{% csrf_token %} + + {% bootstrap_form form %} + +
+ + +
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/accounts_app/urls.py b/accounts_app/urls.py index 6318a28..45f5687 100644 --- a/accounts_app/urls.py +++ b/accounts_app/urls.py @@ -15,7 +15,7 @@ urlpatterns = [ path('add/', views.create_profile, name='create_profile'), - path('settings/', views.ch_info, name='setup_info'), + path('settings/', views.UpdateSelfAccount.as_view(), name='setup_info'), path('settings/change_ava/', views.AvatarUpdateView.as_view(), name='setup_avatar'), path('/', views.profile_show, name='other_profile'), diff --git a/accounts_app/views.py b/accounts_app/views.py index 19f1841..5417e14 100644 --- a/accounts_app/views.py +++ b/accounts_app/views.py @@ -2,6 +2,7 @@ from django.apps import apps from django.contrib.auth.decorators import login_required from django.contrib.auth import logout, login, authenticate from django.contrib.auth.forms import AuthenticationForm +from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.views import LoginView from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect @@ -16,7 +17,7 @@ from django.conf import settings from group_app.models import Group from .models import UserProfile, UserProfileLog -from .forms import AvatarChangeForm, UserPermissionsForm, MyUserObjectPermissionsForm +from .forms import AvatarChangeForm, UserPermissionsForm, MyUserObjectPermissionsForm, UserProfileForm from djing import lib from djing.lib.decorators import only_admins from guardian.decorators import permission_required_or_403 as permission_required @@ -100,36 +101,18 @@ class AvatarUpdateView(UpdateView): return resolve_url('acc_app:other_profile', uid=self.request.user.id) -@login_required -@only_admins -def ch_info(request): - if request.method == 'POST': - user = request.user - user.username = request.POST.get('username') - user.fio = request.POST.get('fio') - user.email = request.POST.get('email') - user.telephone = request.POST.get('telephone') +class UpdateSelfAccount(LoginRequiredMixin, UpdateView): + form_class = UserProfileForm + model = UserProfile + template_name = 'accounts/userprofile_form.html' - psw = request.POST.get('oldpasswd') - if psw != '' and psw is not None: - if user.check_password(psw): - newpasswd = request.POST.get('newpasswd') - if newpasswd != '' and newpasswd is not None: - user.set_password(newpasswd) - user.save() - request.user = user - logout(request) - return redirect('acc_app:other_profile', uid=user.pk) - else: - messages.error(request, _('New password is empty, fill it')) - else: - messages.error(request, _('Wrong password')) - else: - messages.warning(request, _('Empty password, fill it')) + def get_object(self, queryset=None): + return self.request.user - return render(request, 'accounts/settings/ch_info.html', { - 'user': request.user - }) + def form_valid(self, form): + r = super(UpdateSelfAccount, self).form_valid(form) + messages.success(self.request, _('Saved successfully')) + return r @login_required