Add: basic profile page
This commit is contained in:
parent
3f762419df
commit
03ccac13b6
3 changed files with 146 additions and 1 deletions
7
archivist/apps/user/urls.py
Normal file
7
archivist/apps/user/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.urls import path
|
||||
from .views import edit_profile
|
||||
|
||||
urlpatterns = [
|
||||
# Other URL patterns
|
||||
path('profile/', edit_profile, name='profile'),
|
||||
]
|
|
@ -1,3 +1,28 @@
|
|||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
# Create your views here.
|
||||
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 edit_profile(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})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue