diff --git a/archivist/apps/templates/accounts/profile.html b/archivist/apps/templates/accounts/profile.html new file mode 100644 index 0000000..214167f --- /dev/null +++ b/archivist/apps/templates/accounts/profile.html @@ -0,0 +1,113 @@ +{% extends "layouts/base-electric.html" %} + +{% load static %} + +{% block title %} Sites {% endblock title %} + +{% block stylesheets %} + +{% endblock stylesheets %} + +{% block content %} + + {% include "includes/navigation-transparent.html" %} + +
+
+
+ +

Profile Info

+ +
+ + + + + + + + + + + + + + + +
Last Login{{ user.last_login }}
Registration Date{{ user.date_joined }}
Admin Status + {% if user.is_staff %} + Yes + {% else %} + No + {% endif %} +
+
+ +
+
+ +
+
+ +

Profile Settings

+ +

Edit your profile

+ +
+ {% csrf_token %} + {{ user_form.as_p }} + {{ profile_form.as_p }} + +
+ +
+
+ +
+ + +{% endblock content %} + + \ No newline at end of file diff --git a/archivist/apps/user/urls.py b/archivist/apps/user/urls.py new file mode 100644 index 0000000..b891dca --- /dev/null +++ b/archivist/apps/user/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from .views import edit_profile + +urlpatterns = [ + # Other URL patterns + path('profile/', edit_profile, name='profile'), +] diff --git a/archivist/apps/user/views.py b/archivist/apps/user/views.py index 91ea44a..dc4c9e9 100644 --- a/archivist/apps/user/views.py +++ b/archivist/apps/user/views.py @@ -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})