Commit a44b0381 authored by Teo Quinto's avatar Teo Quinto

Formatted html templates for lab 3 for homepage.

parent b9fa2f67
# Generated by Django 4.0.3 on 2022-05-20 20:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_widgetuser_department_widgetuser_email_and_more'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='profile',
field=models.ImageField(default='default.jpg', upload_to='static/homepage'),
),
]
# Generated by Django 4.0.3 on 2022-05-20 20:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0004_widgetuser_profile'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile',
field=models.ImageField(default='default.jpg', upload_to='homepage/static/homepage'),
),
]
# Generated by Django 4.0.3 on 2022-05-20 20:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0005_alter_widgetuser_profile'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='profile',
field=models.ImageField(default='default.jpg', upload_to=None),
),
]
......@@ -20,6 +20,7 @@ class WidgetUser(models.Model):
id_num = models.IntegerField(default=DEFAULT_ID_NUM, validators=[MaxValueValidator(9999999)])
email = models.EmailField(max_length=320, default="email@address.com")
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=DEFAULT_DEPARTMENT_ID)
profile = models.ImageField(upload_to="homepage", default="default.jpg")
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
\ No newline at end of file
h1 {
text-align: center;
color:rgb(3, 4, 94);
text-shadow:2px 2px 5px rgb(101, 15, 158);
font-family: "Brush Script MT", "Brush Script Std", cursive;
font-size: 50px;
}
h2 {
color:rgb(0, 94, 216);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
body {
background-color: rgb(202, 240, 248);
}
p {
color:rgb(0, 180, 216);
font-size: 25px;
font-family: "New Century Schoolbook", "TeX Gyre Schola", serif;
}
a {
color:rgb(0, 119, 182);
font-size: 20px;
font-family: "Arial Narrow", sans-serif;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale-1.0">
<link rel="stylesheet" href="{% static 'homepage/style.css' %}">
<title>{% block title %}Woah a page{% endblock %}</title>
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}User no. {{ user_id }}{% endblock %}
{% block content %}
<p>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.dept_name }}
<br />Home unit: {{ user.department.home_unit }}
{% load static %}
<br /><br /><br /><img src="{{ user.profile.url }}" alt="{{user.last_name}}" style="width:50%">
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Homepage{% endblock %}
{% block content %}
<h1>Welcome to Widget!</h1>
<p>Widget Users:</p>
{% if users %}
<ol>
{% for user in users %}
<li><a href="users/{{ user.id }}/details/">{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}</li>
{% endfor %}
</ol>
{% else %}
<p>No users are available</p>
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -3,7 +3,9 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
path('', views.index, name='index'),
# homepage/users/1/details/
path("users/<int:user_id>/details/", views.details, name="details")
]
app_name = "homepage"
\ No newline at end of file
from django.http import HttpResponse
from django.http import Http404, HttpResponse
from django.shortcuts import render
from .models import Department, WidgetUser
users = WidgetUser.objects.all()
displayString = "WIDGET USERS:"
for i in users:
userString = '<br />{}, {} {}: {}, {}, {}, {}'.format(i.last_name, i.first_name, i.middle_name, i.id_num, i.email, i.department.dept_name, i.department.home_unit)
displayString += userString
users = WidgetUser.objects.order_by("last_name")
# Create your views here.
def index(request):
context = {
"users": users,
}
return render(request, "homepage/index.html", context)
return HttpResponse(displayString)
\ No newline at end of file
def details(request, user_id):
try:
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist!")
for person in users:
if person.id == user_id:
user = person
break
context = {
"user": user,
"user_id": user_id
}
return render(request, "homepage/details.html", context)
\ No newline at end of file
......@@ -132,3 +132,6 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
\ No newline at end of file
......@@ -15,6 +15,9 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from . import settings
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('homepage/', include('homepage.urls', namespace="homepage")),
......@@ -22,4 +25,4 @@ urlpatterns = [
path('forum/', include('forum.urls')),
path('announcements/', include('announcements.urls')),
path('admin/', admin.site.urls),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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