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

28 lines
993 B
Python

from django.shortcuts import render
from django.contrib.auth.decorators import login_required
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/")
def ProfileEditView(request):
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})