Convert homepage details view to CBV

parent 20bec783
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
{% if user_list %} {% if user_list %}
<ol> <ol>
{% for user in user_list %} {% 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 %} {% endfor %}
</ol> </ol>
{% else %} {% else %}
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">
{% endblock %} {% endblock %}
{% block title %}{{user.user_id}}{% endblock %} {% block title %}{{object.pk}}{% endblock %}
{% block content %} {% block content %}
<nav class="topnav"> <nav class="topnav">
<a href="{% url 'homepage:indexHomepage' %}">Homepage</a> <a href="{% url 'homepage:indexHomepage' %}">Homepage</a>
...@@ -16,16 +16,16 @@ ...@@ -16,16 +16,16 @@
<div class="flex-container"> <div class="flex-container">
<div class="user-card"> <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> <div>
{% if user.image %} {% if object.image %}
<img class="user-image flex-item" src = "{{ user.image.url }}"> <img class="user-image flex-item" src = "{{ object.image.url }}">
{% endif %} {% endif %}
<ul class="flex-item"> <ul class="flex-item">
<li>ID Number: {{user.id_num}}</li> <li>ID Number: {{object.id_num}}</li>
<li>Email Address: {{user.email}}</li> <li>Email Address: {{object.email}}</li>
<li>Department: {{user.department.dept_name}}</li> <li>Department: {{object.department.dept_name}}</li>
<li>Home Unit: {{user.department.home_unit}}</li> <li>Home Unit: {{object.department.home_unit}}</li>
</ul> </ul>
</div> </div>
</div> </div>
......
...@@ -4,5 +4,5 @@ from . import views ...@@ -4,5 +4,5 @@ from . import views
app_name = "homepage" app_name = "homepage"
urlpatterns = [ urlpatterns = [
path('', views.index, name="indexHomepage"), 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.http import Http404
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import WidgetUser from .models import WidgetUser
def index(request): def index(request):
...@@ -10,10 +11,5 @@ def index(request): ...@@ -10,10 +11,5 @@ def index(request):
return render(request, "homepage/index.html", context) return render(request, "homepage/index.html", context)
def details(request, user_id): class UserDetailView(DetailView):
try: model = WidgetUser
user = WidgetUser.objects.get(pk=user_id) \ No newline at end of file
except WidgetUser.DoesNotExist:
raise Http404("User does not exist!")
return render(request, "homepage/detail.html", {"user": user})
\ 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