def administrator_update(request, pk): context = {} user = User.objects.get(pk=int(pk)) success_msg = u'' error_msg = u'' if request.method == 'POST': password1 = request.POST.get('password1') password2 = request.POST.get('password2') if password1 and password2: if password1 == password2: user.set_password(password1) success_msg = u'Пароль успешно изменён!' else: error_msg = u'Пароль и подтверждение пароля не совпадают!' form = UserUpdateForm(request.POST, instance=user) if form.is_valid(): form.save() success_msg += u' Изменения успешно сохранены' else: error_msg = u'Проверьте правильность ввода полей!' else: form = UserUpdateForm(instance=user) context.update({ 'success': success_msg, 'error': error_msg, 'form': form, 'object': user }) return render(request, 'administrator/administrator_update.html', context)
def manager_update(request, pk): context = {} manager = Manager.objects.get(pk=int(pk)) user = manager.user success_msg = u'' error_msg = u'' if request.method == 'POST': password1 = request.POST.get('password1') password2 = request.POST.get('password2') if password1 and password2: if password1 == password2: user.set_password(password1) success_msg = u'Пароль успешно изменён!' else: error_msg = u'Пароль и подтверждение пароля не совпадают!' u_form = UserUpdateForm(request.POST, instance=user) m_form = ManagerForm(request.POST, instance=manager) if u_form.is_valid() and m_form.is_valid(): u_form.save() m_form.save() success_msg += u' Изменения успешно сохранены' else: error_msg = u'Проверьте правильность ввода полей!' else: u_form = UserUpdateForm(instance=user) m_form = ManagerForm(instance=manager) if request.user.type == 1: m_form.fields['moderator'].queryset = User.objects.filter(type=2) elif request.user.type == 6: m_form.fields['moderator'].queryset = User.objects.filter(pk__in=request.user.superviser.moderator_id_list()) elif request.user.type == 2: m_form.fields['moderator'].queryset = User.objects.filter(pk=request.user.id) elif request.user.type == 5: manager = Manager.objects.get(user=request.user) m_form.fields['moderator'].queryset = User.objects.filter(pk=manager.moderator.id) try: request.session['manager_filtered_list'] except: request.session['manager_filtered_list'] = reverse('manager:list') context.update({ 'success': success_msg, 'error': error_msg, 'u_form': u_form, 'm_form': m_form, 'object': manager, 'back_to_list': request.session['manager_filtered_list'] }) return render(request, 'manager/manager_update.html', context)
def client_update(request, pk): context = {} client = Client.objects.get(pk=int(pk)) user = client.user success_msg = u'' error_msg = u'' if request.method == 'POST': password1 = request.POST.get('password1') password2 = request.POST.get('password2') if password1 and password2: if password1 == password2: user.set_password(password1) success_msg = u'Пароль успешно изменён!' else: error_msg = u'Пароль и подтверждение пароля не совпадают!' user_form = UserUpdateForm(request.POST, instance=user) client_form = ClientUpdateForm(request.POST, request=request, instance=client) if user_form.is_valid() and client_form.is_valid(): user_form.save() client_form.save() success_msg += u' Изменения успешно сохранены' else: error_msg = u'Проверьте правильность ввода полей!' else: user_form = UserUpdateForm(instance=user) client_form = ClientUpdateForm(request=request, instance=client) try: request.session['client_filtered_list'] except: request.session['client_filtered_list'] = reverse('client:list') context.update({ 'success': success_msg, 'error': error_msg, 'user_form': user_form, 'client_form': client_form, 'object': client, 'client': client, 'back_to_list': request.session['client_filtered_list'] }) return render(request, 'client/client_update.html', context)
def adjuster_update(request, pk): context = {} adjuster = Adjuster.objects.get(pk=int(pk)) user = adjuster.user success_msg = u'' error_msg = u'' if request.method == 'POST': password1 = request.POST.get('password1') password2 = request.POST.get('password2') if password1 and password2: if password1 == password2: user.set_password(password1) success_msg = u'Пароль успешно изменён!' else: error_msg = u'Пароль и подтверждение пароля не совпадают!' user_form = UserUpdateForm(request.POST, instance=user) adjuster_form = AdjusterUpdateForm(request.POST, request=request, instance=adjuster) if user_form.is_valid() and adjuster_form.is_valid(): user_form.save() adjuster_form.save() success_msg += u' Изменения успешно сохранены' else: error_msg = u'Проверьте правильность ввода полей!' else: user_form = UserUpdateForm(instance=user) adjuster_form = AdjusterUpdateForm(request=request, instance=adjuster) try: request.session['adjuster_filtered_list'] except: request.session['adjuster_filtered_list'] = reverse('adjuster:list') context.update({ 'success': success_msg, 'error': error_msg, 'user_form': user_form, 'adjuster_form': adjuster_form, 'adjuster': adjuster, 'back_to_list': request.session['adjuster_filtered_list'] }) return render(request, 'adjuster/adjuster_update.html', context)