diff --git a/titivillus/urls.py b/titivillus/urls.py index 35d0fe2..8f0fbe7 100644 --- a/titivillus/urls.py +++ b/titivillus/urls.py @@ -14,4 +14,5 @@ urlpatterns = [ path('signup/', include('signup.urls')), path('login/', include('login.urls')), path('logout/', include('logout.urls')), + path('user/', include('user.urls')), ] diff --git a/todo b/todo index 211c064..d7761c1 100644 --- a/todo +++ b/todo @@ -32,4 +32,3 @@ Adjust quote preview postioning Port from old code: Edit post Images -User page diff --git a/user/jinja2/user/profile.html b/user/jinja2/user/profile.html new file mode 100644 index 0000000..2992b86 --- /dev/null +++ b/user/jinja2/user/profile.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% block title %}{{ user.username }}{% endblock %} +{% block content %} +

{{ user.username }}'s profile

+ Signed up: {{ user.date_joined }}
+ Num. quests ran: {{ quests.count() }}
+{% endblock %} diff --git a/user/urls.py b/user/urls.py new file mode 100644 index 0000000..7899375 --- /dev/null +++ b/user/urls.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +""" +User URL configuration. +""" +from django.urls import path + +from . import views + +app_name = 'user' +urlpatterns = [ + path('', views.index, name='index'), + path('', views.profile, name='profile'), +] diff --git a/user/views.py b/user/views.py index 91ea44a..d9cf5fe 100644 --- a/user/views.py +++ b/user/views.py @@ -1,3 +1,29 @@ -from django.shortcuts import render +#!/usr/bin/env python3 +""" +/user app views. +""" +from django.http import HttpResponse +from django.shortcuts import redirect, render +from django.core.exceptions import ObjectDoesNotExist -# Create your views here. +from .models import User +from quest.models import Quest + +def index(request): + """ + The user index page. + """ + return HttpResponse("Hello, world. You're at the user index.") + + +def profile(request, user_id): + """ + User profile. + """ + try: + user = User.objects.get(id=user_id) + except ObjectDoesNotExist: + return HttpResponse(f"User_id {user_id} does not exist.") + quests = Quest.objects.filter(owner=user) + context = locals() + return render(request, 'user/profile.html', context)