Convert homepage details view to CBV

parent 20bec783
......@@ -20,7 +20,7 @@
{% if user_list %}
<ol>
{% for user in user_list %}
<li><a href="{% url 'homepage:details' user.id%}">{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</a></li>
<li><a href="{% url 'homepage:userDetails' user.id%}">{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</a></li>
{% endfor %}
</ol>
{% else %}
......
......@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">
{% endblock %}
{% block title %}{{user.user_id}}{% endblock %}
{% block title %}{{object.pk}}{% endblock %}
{% block content %}
<nav class="topnav">
<a href="{% url 'homepage:indexHomepage' %}">Homepage</a>
......@@ -16,16 +16,16 @@
<div class="flex-container">
<div class="user-card">
<h1>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</h1>
<h1>{{object.last_name}}, {{object.first_name}} {{object.middle_name}}</h1>
<div>
{% if user.image %}
<img class="user-image flex-item" src = "{{ user.image.url }}">
{% if object.image %}
<img class="user-image flex-item" src = "{{ object.image.url }}">
{% endif %}
<ul class="flex-item">
<li>ID Number: {{user.id_num}}</li>
<li>Email Address: {{user.email}}</li>
<li>Department: {{user.department.dept_name}}</li>
<li>Home Unit: {{user.department.home_unit}}</li>
<li>ID Number: {{object.id_num}}</li>
<li>Email Address: {{object.email}}</li>
<li>Department: {{object.department.dept_name}}</li>
<li>Home Unit: {{object.department.home_unit}}</li>
</ul>
</div>
</div>
......
......@@ -4,5 +4,5 @@ from . import views
app_name = "homepage"
urlpatterns = [
path('', views.index, name="indexHomepage"),
path('<int:user_id>/details', views.details, name="details")
path('<int:pk>/details', views.UserDetailView.as_view(), name="userDetails")
]
\ No newline at end of file
from django.http import Http404
from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import WidgetUser
def index(request):
......@@ -10,10 +11,5 @@ def index(request):
return render(request, "homepage/index.html", context)
def details(request, user_id):
try:
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist!")
return render(request, "homepage/detail.html", {"user": user})
\ No newline at end of file
class UserDetailView(DetailView):
model = WidgetUser
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment