Commit ad1923ae authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴

Modified the views.py, models.py, and urls.py to implement a better views,...

Modified the views.py, models.py, and urls.py to implement a better views, Created templates, html files, and css files for design, added an image for the profile picture.
parent cbd1b286
...@@ -12,7 +12,7 @@ class Department(models.Model): ...@@ -12,7 +12,7 @@ class Department(models.Model):
def get_dept_info(self): def get_dept_info(self):
return '{}, {}'.format(self.dept_name, self.home_unit) return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model): class WidgetUser(models.Model):
def ID_validator(value): def ID_validator(value):
if value.isdigit() != True: if value.isdigit() != True:
......
body {
background-color: paleturquoise;
font-family: Helvetica, Arial, sans-serif;
}
header {
color: blue;
font-size: 200%;
}
p {
color: black;
font-size: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="base.css">
<title>{% block title %} {% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'homepage/base.html' %}
{% load static %}
{% block title %} User Details {% endblock %}
{% block styles %} <link rel="stylesheet" href="{% static 'base.css' %}"> {% endblock %}
{% block content %}
Complete name: {{user.last_name}}, {{user.first_name}} {{user.middle_name}} </br>
ID number: {{user.id_num}} </br>
Email address: {{user.email}} </br>
Department name: {{user.department}} </br>
Home unit: {{user.department.home_unit}} </br>
Profile Picture: <img src="{% static 'profile-picture.jpg' %}" alt="Profile Picture"> </br>
{% endblock %}
\ No newline at end of file
{% extends 'homepage/base.html' %}
{% load static %}
{% block title %} Homepage {% endblock %}
{% block styles %} <link rel="stylesheet" href="{% static 'base.css' %}"> {% endblock %}
{% block content %}
<header> Welcome to the Widget! </header>
<p>
Widget Users:
<ol type = '1'>
{% for user in user_list %}
<a href = "{% url 'homepage:details' user.id_num %}"">
<li>{{user.last_name}}, {{user.first_name}} {{user.middle_name}} </br> </a> </li> </p>
{% endfor %}
</ol>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from homepage import views
from .views import index
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', views.index, name='index'),
path('users/<str:user_id>/details', views.details, name='details'),
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from re import A, template
from django.shortcuts import render from django.shortcuts import render
from django.template import loader
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser from .models import WidgetUser
# Create your views here. # Create your views here.
def index(request): def index(request):
model = WidgetUser user_list = WidgetUser.objects.order_by("last_name")
widget_users = model.objects.all() template = loader.get_template("homepage/index.html")
homepage_response = "WIDGET USERS: </br>" context = {
"user_list" : user_list,
}
return HttpResponse(template.render(context,request))
for user in widget_users:
homepage_response += user.get_user_info()
return HttpResponse(homepage_response) def details(request,user_id):
\ No newline at end of file user = WidgetUser.objects.get(id_num=user_id)
template = loader.get_template("homepage/details.html")
context = {
"user" : user,
}
return HttpResponse(template.render(context,request))
#model = WidgetUser
#widget_users = model.objects.all()
#homepage_response = "WIDGET USERS: </br>"
#for user in widget_users:
#homepage_response += user.get_user_info()
#return HttpResponse(homepage_response)
\ 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