Gallery-Archivist/archivist/apps/user/views.py

29 lines
993 B
Python
Raw Normal View History

2023-10-21 15:18:07 +02:00
from django.shortcuts import render
2024-07-02 22:10:32 +02:00
from django.contrib.auth.decorators import login_required
2023-10-21 15:18:07 +02:00
2024-07-02 22:10:32 +02:00
from rest_framework import status
from rest_framework.response import Response
from apps.user.models import UserProfile, SeenPost
from apps.sites.models import Submissions
from .forms import UserProfileForm, UserForm
@login_required(login_url="/login/")
2024-07-03 22:05:22 +02:00
def ProfileEditView(request):
2024-07-02 22:10:32 +02:00
if request.method == 'POST':
user_form = UserForm(request.POST, instance=request.user)
profile_form = UserProfileForm(request.POST, instance=request.user.userprofile)
if user_form.is_valid() and profile_form.is_valid():
user_form.save()
profile_form.save()
# Redirect to a success page or home page
else:
user_form = UserForm(instance=request.user)
profile_form = UserProfileForm(instance=request.user.userprofile)
return render(request, 'accounts/profile.html', {'user_form': user_form, 'profile_form': profile_form})