コード例 #1
0
ファイル: views.py プロジェクト: Raider992/MyShop_server
def profile(request):
    if request.method == "POST":
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           instance=request.user.userprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:profile'))

    else:
        form = UserProfileForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)

    carts = Cart.objects.filter(user=request.user)

    context = {
        'title': 'профиль',
        'style_link': 'css/profile.css',
        'carts': carts,
        'form': form,
        'profile_form': profile_form
    }

    return render(request, 'authapp/profile.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: iionov-hub/geekshop
def profile(request):
    user = request.user
    title = 'редактирование'

    if request.method == 'POST':
        edit_form = UserProfileForm(request.POST,
                                    request.FILES,
                                    instance=request.user)
        profile_form = UserProfileEditForm(request.POST,
                                           instance=request.user.userprofile)
        if edit_form.is_valid() and profile_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        edit_form = UserProfileForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)
    baskets = Basket.objects.filter(user=user)
    content = {
        'title': title,
        'form': edit_form,
        'baskets': baskets,
        'profile_form': profile_form
    }

    return render(request, 'authapp/profile.html', content)
コード例 #3
0
def edit(request):
    title = 'edit'

    if request.method == 'POST':
        edit_form = UserEditForm(request.POST,
                                 request.FILES,
                                 instance=request.user)
        edit_profile_form = UserProfileEditForm(
            request.POST, instance=request.user.myuserprofile)
        if edit_form.is_valid() and edit_profile_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(reverse('main:index'))

    else:
        edit_form = UserEditForm(instance=request.user)
        edit_profile_form = UserProfileEditForm(
            instance=request.user.myuserprofile)

    context = {
        'title': title,
        'body_class': 'authform',
        'edit_form': edit_form,
        'profile_form': edit_profile_form
    }
    if request.user.myuserprofile.photo_link != '':
        context['avatar_vk'] = request.user.myuserprofile.photo_link

    return render(request, 'authapp/edit.html', context)
コード例 #4
0
    def post(self, request, *args, **kwargs):
        """
        Handles POST request.
        :param request: request object.
        :param args: additional arguments.
        :param kwargs: additional key-value arguments.
        :return: HTTP response.
        """
        user = User.objects.get(pk=kwargs['pk'])

        user_form = UserEditForm(self.request.POST,
                                 self.request.FILES,
                                 instance=user)
        profile_form = UserProfileEditForm(
            self.request.POST,
            instance=user.profile,
        )

        if user_form.is_valid() and profile_form.is_valid():
            with transaction.atomic():
                user_form.save()
                profile_form.save()
            return HttpResponseRedirect(reverse('admin:users'))

        context = self.get_context_data()
        context['user_form'] = user_form
        context['profile_form'] = profile_form

        return render(request, self.template_name, context)
コード例 #5
0
def profile(request):
    title = 'редактирование'

    if request.method == 'POST':
        edit_form = UserProfileForm(data=request.POST,
                                    files=request.FILES,
                                    instance=request.user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           files=request.FILES,
                                           instance=request.user.userprofile)

        if edit_form.is_valid() and profile_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        edit_form = UserProfileForm(data=request.POST,
                                    files=request.FILES,
                                    instance=request.user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           files=request.FILES,
                                           instance=request.user.userprofile)

    context = {
        'title': title,
        'form': edit_form,
        'profile_form': profile_form,
    }
    return render(request, 'authapp/profile.html', context)
コード例 #6
0
ファイル: views.py プロジェクト: Fedortsov-AV/geekshop
 def post(self, request, *args, **kwargs):
     user_form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user)
     profile_form = UserProfileEditForm(data=request.POST, instance=request.user.userprofile)
     if user_form.is_valid() and profile_form.is_valid():
         user_form.save()
         return HttpResponseRedirect(reverse('authapp:profile', args=[request.user.pk]))
     else:
         return super(ProfileView, self).get(request, *args, **kwargs)
コード例 #7
0
 def form_valid(self, form, *args, **kwargs):
     profile_form = UserProfileEditForm(
         data=self.request.POST,
         files=self.request.FILES,
         instance=self.request.user.userprofile)
     if profile_form.is_valid():
         form.save()
         profile_form.save()
         return HttpResponseRedirect(self.success_url)
     return render(self.request, self.template_name, {
         "form": form,
         "profile_form": profile_form
     })
コード例 #8
0
ファイル: views.py プロジェクト: Fedortsov-AV/geekshop
 def get_context_data(self, *, object_list=None, **kwargs):
     context = super().get_context_data(**kwargs)
     context.update({'title': 'GeekShop - Профиль пользователя ' + str(User.objects.get(id=self.kwargs['pk']))})
     context.update({'baskets': Basket.objects.filter(user=self.kwargs['pk'])})
     profile_form = UserProfileEditForm(instance=self.request.user.userprofile)
     context.update({'profile_form': profile_form})
     return context
コード例 #9
0
ファイル: views.py プロジェクト: Anastazia17/GeekShop517
    def post(self, request, *args, **kwargs):
        user = User.objects.get(pk=self.request.user.pk)
        edit_form = UserEditForm(data=request.POST,
                                 files=request.FILES,
                                 instance=user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           files=request.FILES,
                                           instance=user.userprofile)

        if edit_form.is_valid() and profile_form.is_valid():
            edit_form.save()
            user.userprofile.save()
            return HttpResponseRedirect(self.success_url)

        return render(request, self.template_name, {
            'form': edit_form,
            'profile_form': profile_form,
        })
コード例 #10
0
ファイル: views.py プロジェクト: Tot741/geekshop_server_2
def edit(request):
    if request.method == 'POST':
        profile_form = UserProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user)
        ext_profile_form = UserProfileEditForm(
            request.POST, instance=request.user.userprofile)
        if profile_form.is_valid() and ext_profile_form.is_valid():
            profile_form.save()
            return HttpResponseRedirect(reverse('auth:edit'))
    else:
        profile_form = UserProfileForm(instance=request.user)
        ext_profile_form = UserProfileEditForm(
            instance=request.user.userprofile)
    context = {
        'title': 'Редактрирование дополнительных данных',
        'profile_form': profile_form,
        'ext_profile_form': ext_profile_form
    }
    return render(request, 'authapp/edit.html', context)
コード例 #11
0
def edit(request):
    if request.method == 'POST':
        form = UserEditForm(request.POST, request.FILES, instance=request.user)
        profile_form = UserProfileEditForm(request.POST,
                                           request.FILES,
                                           instance=request.user.userprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:edit'))
    else:
        form = UserEditForm(instance=request.user)
        profile_form = UserProfileEditForm(request.POST,
                                           request.FILES,
                                           instance=request.user.userprofile)
    context = {
        'title': 'редактирование',
        'form': form,
        'profile_form': profile_form,
    }
    return render(request, 'authapp/edit.html', context)
コード例 #12
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           instance=request.user.userprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('authapp:profile'))
    else:
        form = UserProfileForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)
    baskets = Basket.objects.filter(user=request.user)
    context = {
        'title': 'Профиль',
        'form': form,
        'profile_form': profile_form,
        'baskets': baskets,
    }
    return render(request, 'authapp/profile.html', context)
コード例 #13
0
def profile(request):
    user = request.user
    if request.method == 'POST':
        user_form = UserProfileForm(data=request.POST,
                                    files=request.FILES,
                                    instance=user)
        user_profile_form = UserProfileEditForm(data=request.POST,
                                                files=request.FILES,
                                                instance=user.userprofile)
        if user_form.is_valid() and user_profile_form.is_valid():
            with transaction.atomic():
                user_form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        user_form = UserProfileForm(instance=user)
        user_profile_form = UserProfileEditForm(instance=user.userprofile)
    context = {
        'user_form': user_form,
        'user_profile_form': user_profile_form,
        'baskets': Basket.objects.filter(user=user),
    }
    return render(request, 'authapp/profile.html', context)
コード例 #14
0
 def get(self, request, *args, **kwargs):
     """
     Handles GET request.
     :param request: request object.
     :param args: additional arguments.
     :param kwargs: additional key-value arguments.
     :return: HTTP response.
     """
     context = self.get_context_data()
     user = User.objects.get(pk=kwargs['pk'])
     context['user_form'] = UserEditForm(instance=user)
     context['profile_form'] = UserProfileEditForm(instance=user.profile)
     return render(request, self.template_name, context)