Commit e7be278c authored by Pierre Ashley Salcedo's avatar Pierre Ashley Salcedo

feat: add views and add templates to views in homepage app

parent 739ba144
body {
background-color: rgb(40, 105, 239);
font-family: 'Montserrat', serif;
color: rgb(255, 255, 255);
margin: 0;
}
header {
background-color:rgb(27, 27, 27);
color:rgb(241, 65, 65);
}
h1 {
text-transform: uppercase;
text-align: center;
padding: 10px;
margin: 0;
}
h2 {
padding: 10px;
font-weight: 700;
}
ul, ol {
font-weight: 500;
margin: 1em;
}
ul { list-style-type: none; }
li { margin: 10px 0; }
a { color: rgb(255, 255, 255); }
img { width: 400px; }
#userInfo {
display: flex;
flex-flow: row wrap-reverse;
justify-content: space-evenly;
}
#userInfo > div {
flex: 0 1 auto;
}
\ No newline at end of file
<!-- project/template/base.html -->
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<link rel="stylesheet" href="{% static 'homepage\style.css' %}">
<meta charset="UTF-8">
<meta name ="viewport" content="width-device width, initial scale=1">
<title> {% block title%} Homepage {% endblock %} </title>
</head>
<body>
<div id="content">
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "homepage/base.html" %}
{% load static %}
{% block title%} {{user.last_name}}, {{user.first_name}} {{user.middle_name}} {% endblock %}
{% block content %}
<header><h1> {{user.last_name}}, {{user.first_name}} {{user.middle_name}} </h1></header>
<div id="userInfo">
<div>
<ul>
<li> ID number: {{user.id_num}} </li>
<li> Email address: {{user.email}} </li>
<li> Department name: {{user.department.dept_name}} </li>
<li> Home unit: {{user.department.home_unit}} </li>
</ul>
</div>
<div>
<img src = "{% static 'homepage/images/test.jpg' %}" alt = "profile image">
</div>
</div>
{% endblock %}
\ No newline at end of file
{% extends "homepage/base.html" %}
{% block content %}
<header><h1> Welcome to Widget! </h1></header>
<h2>Widget Users: </h2>
{% if user_list %}
<ol>
{% for user in user_list %}
<li> <a href = "{% url 'homepage:detail' user.id_num %}">
{{user.last_name}}, {{user.first_name}} {{user.middle_name}}
</a></li>
{% endfor %}
</ol>
{% else %}
<p> No users available. </p>
{% endif %}
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
app_name = "homepage"
urlpatterns = [ urlpatterns = [
path("", views.index, name="homepage") path("", views.index, name="homepage"),
path("<int:user_id>/details", views.detail, name="detail")
] ]
\ No newline at end of file
app_name = "homepage"
from django.http import HttpResponse from django.shortcuts import render
from django.http import Http404, HttpResponse
from .models import WidgetUser from .models import WidgetUser
# Create your views here. # Create your views here.
def index(request): def index(request):
widget_users = WidgetUser.objects.all() user_list = WidgetUser.objects.order_by("last_name")
context = {
"user_list": user_list
}
return render(request, "homepage/index.html", context)
html = "<html><body><h1>WIDGET USERS:</h1>" def detail(request, user_id):
for widget_user in widget_users: try:
html += "<p> {}, {} {}: {}, {}, {}, {} </p>".format( user = WidgetUser.objects.get(id_num = user_id)
widget_user.last_name, except WidgetUser.DoesNotExist:
widget_user.first_name, raise Http404("User does not exist!")
widget_user.middle_name, context = {
widget_user.id_num, "user": user
widget_user.email, }
widget_user.department.dept_name, return render(request, "homepage/detail.html", context)
widget_user.department.home_unit \ No newline at end of file
)
html += "</body></html>"
return HttpResponse(html)
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