Ejemplo n.º 1
0
 def dispatch(self, request, *args, **kwargs):
     action = request.POST.get('action')
     self.profile_form = UserProfileForm(
         (request.POST if action == 'profile' else None),
         (request.FILES if action == 'profile' else None),
         prefix='profile',
         instance=request.user)
     self.password_form = UserPasswordChangeForm(
         request.user, (request.POST if action == 'password' else None),
         prefix='password')
     self.email_form = UserEmailChangeForm(
         request.user, (request.POST if action == 'email' else None),
         prefix='email')
     return super(UserSettingsView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 2
0
class UserSettingsView(TemplateView):
    template_name = 'users/settings.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        action = request.POST.get('action')
        self.profile_form = UserProfileForm(
            (request.POST if action == 'profile' else None),
            (request.FILES if action == 'profile' else None),
            prefix='profile',
            instance=request.user)
        self.password_form = UserPasswordChangeForm(
            request.user, (request.POST if action == 'password' else None),
            prefix='password')
        self.email_form = UserEmailChangeForm(
            request.user, (request.POST if action == 'email' else None),
            prefix='email')
        return super(UserSettingsView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(UserSettingsView, self).get_context_data(**kwargs)
        context['profile_form'] = self.profile_form
        context['password_form'] = self.password_form
        context['email_form'] = self.email_form
        return context

    def post(self, request, *args, **kwargs):
        if self.profile_form.is_valid():
            self.profile_form.save()
            messages.success(request, _(u'Профиль успешно сохранен.'))
            return redirect(request.path)
        elif self.password_form.is_valid():
            self.password_form.save()
            request.user.backend = request.session[BACKEND_SESSION_KEY]
            login(request, request.user)
            messages.success(request, _(u'Пароль успешно изменен.'))
            return redirect(request.path)
        elif self.email_form.is_valid():
            self.email_form.save()
            messages.success(request, _(u'Email успешно изменен.'))
            return redirect(request.path)
        return self.get(request, *args, **kwargs)
Ejemplo n.º 3
0
 def dispatch(self, request, *args, **kwargs):
     action = request.POST.get('action')
     self.profile_form = UserChangeProfileForm(
             (request.POST if action == 'profile' else None),
             (request.FILES if action == 'profile' else None),
             instance=request.user, prefix='profile'
     )
     self.password_form = UserPasswordChangeForm(request.user, (request.POST if action == 'password' else None),
                                                 prefix='password')
     self.email_form = UserEmailChangeForm(request.user, request.POST if action == 'email' else None, prefix='email')
     return super(UserSettingsView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 4
0
class UserSettingsView(TemplateView):
    template_name = 'users/settings.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        action = request.POST.get('action')
        self.profile_form = SettingsForm(
            (request.POST if action == 'profile' else None),
            (request.FILES if action == 'profile' else None),
            prefix='profile', instance=request.user
        )
        self.password_form = UserPasswordChangeForm(request.user, (request.POST if action == 'password' else None),
                                                    prefix='password')
        self.email_form = UserEmailChangeForm(request.user, (request.POST if action == 'email' else None),
                                              prefix='email')
        return super(UserSettingsView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(UserSettingsView, self).get_context_data(**kwargs)
        context['profile_form'] = self.profile_form
        context['password_form'] = self.password_form
        context['email_form'] = self.email_form
        return context

    def post(self, request, *args, **kwargs):
        if self.profile_form.is_valid():
            self.profile_form.save()
            messages.success(request, _(u'Profile success update.'))
            return redirect(request.path)
        elif self.password_form.is_valid():
            self.password_form.save()
            request.user.backend = request.session[BACKEND_SESSION_KEY]
            login(request, request.user)
            messages.success(request, _(u'Password success update.'))
            return redirect(request.path)
        elif self.email_form.is_valid():
            self.email_form.save()
            messages.success(request, _(u'Email success update.'))
            return redirect(request.path)
        return self.get(request, *args, **kwargs)