Commit f5b1de8f authored by Vaughn Fajardo's avatar Vaughn Fajardo

feat: new html interface of homepage and details of each widgetuser

parent f5660e23
# Generated by Django 4.0.3 on 2022-05-06 09:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0007_alter_widgetuser_id_num'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='homeunit',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='homeunit', to='homepage.department'),
),
]
# Generated by Django 4.0.3 on 2022-05-06 09:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('homepage', '0008_widgetuser_homeunit'),
]
operations = [
migrations.RemoveField(
model_name='widgetuser',
name='homeunit',
),
]
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Details</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<div class="Details Information">
<ul>
<p>{{details.last_name}}, {{details.first_name}} {{details.middle_name}}</p>
<p>{{ details.id_num }}</p>
<p>{{ details.email }}</p>
<p>{{ details.department.dept_name }}</p>
<p>{{ details.department.home_unit }}</p>
</ul>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Homepage</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<div class="Homepage Display">
<h1>Welcome to Widget!</h1>
<p>Widget Users:
<ol>
{% for user in widget_user %}
<li><a href="/users/{{ user.id_num }}/details/">
{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}
</a></li>
{% endfor %}
</ol>
</p>
</div>
</body>
</html>
......@@ -2,6 +2,7 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('welcome', views.welcome, name='welcome')
path('homepage/', views.index, name='index'),
path('welcome', views.welcome, name='welcome'),
path("users/<int:id_num>/details/", views.details, name='details')
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from .models import Department, WidgetUser
# Create your views here.
......@@ -7,9 +7,20 @@ def welcome(request):
return HttpResponse('Welcome to Widget!')
def index(request):
widget_user_view = 'WIDGET USERS: '
widget_user = WidgetUser.objects.all()
widget_user = WidgetUser.objects.order_by("last_name")
context = {
"widget_user": widget_user
}
return render(request, "homepage/index.html", context)
'''
NOTE: Clean code dictates that
code be deleted. For grading purposes,
previous code will only be commented out.
widget_user_view = 'WIDGET USERS: '
for user in widget_user:
widget_user_view += "<br/> {}, {} {}: {}, {}, {}, {}".\
format(user.last_name,
......@@ -20,4 +31,12 @@ def index(request):
user.department.dept_name,
user.department.home_unit)
return HttpResponse(widget_user_view)
\ No newline at end of file
return HttpResponse(widget_user_view)
'''
def details(request, id_num):
try:
details = WidgetUser.objects.get(pk=id_num)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist.")
return render(request, "homepage/details.html", {"details": details})
\ No newline at end of file
......@@ -17,7 +17,7 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('homepage/', include('homepage.urls')),
path('', include('homepage.urls')),
path('admin/', admin.site.urls),
path('announcements/', include('announcements.urls')),
path('forum/', include('forum.urls')),
......
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