added finals

parent 4ddda822
from django import forms
from .models import WidgetUser, Department
class AddUserForm(forms.ModelForm):
class Meta:
model = WidgetUser
fields = '__all__'
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-22 14:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0004_widgetuser_department'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='pfp',
field=models.ImageField(default='userpfp/default.png', upload_to='userpfp/'),
),
]
...@@ -5,6 +5,9 @@ class Department(models.Model): ...@@ -5,6 +5,9 @@ class Department(models.Model):
dept_name = models.CharField(max_length=50) dept_name = models.CharField(max_length=50)
home_unit = models.CharField(max_length=50) home_unit = models.CharField(max_length=50)
def __str__(self):
return self.dept_name
class WidgetUser(models.Model): class WidgetUser(models.Model):
first_name = models.CharField(max_length=50, default="A") first_name = models.CharField(max_length=50, default="A")
middle_name = models.CharField(max_length=50, default="B") middle_name = models.CharField(max_length=50, default="B")
...@@ -12,6 +15,7 @@ class WidgetUser(models.Model): ...@@ -12,6 +15,7 @@ class WidgetUser(models.Model):
id_num = models.CharField(max_length=7, default = "") id_num = models.CharField(max_length=7, default = "")
email = models.CharField(max_length=100, default = "") email = models.CharField(max_length=100, default = "")
department = models.ForeignKey(Department, on_delete = models.CASCADE, null=True) department = models.ForeignKey(Department, on_delete = models.CASCADE, null=True)
pfp = models.ImageField(upload_to="userpfp/", default="userpfp/default.png")
def __str__(self): def __str__(self):
return self.first_name return self.first_name
\ No newline at end of file
body{
font-size: 1.15em;
}
\ No newline at end of file
{%extends "homepage/base.html" %}
{%load static%}
{%block body%}
<link rel="stylesheet" type="text/css" href="{%static 'homepage/css/home.css'%}">
<div class="container main">
<form method="POST" action="{%url 'adduser'%}" enctype="multipart/form-data">
{%csrf_token%}
<p> Profile pictures must have this file name format: "user_id.png".</p>
{{form.as_p}}
<input type='submit' value='Add User'>
</form>
<a href="{%url 'homepage'%}"> Return to Homepage </a>
</div>
{%endblock%}
\ No newline at end of file
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
<link rel="stylesheet" type="text/css" href="{%static 'homepage/css/details.css'%}"> <link rel="stylesheet" type="text/css" href="{%static 'homepage/css/details.css'%}">
<div class="container main"> <div class="container main">
<img id="profilepic" src="{%static imgurl%}"> <br><br> <img id="profilepic" src="{{imgurl}}"> <br><br>
<h1>{{widget_user.last_name}}, {{widget_user.first_name}} {{widget_user.middle_name}}</h1> <h1>{{widget_user.last_name}}, {{widget_user.first_name}} {{widget_user.middle_name}}</h1>
<h2>{{widget_user.id_num}}</h2> <h2>{{widget_user.id_num}}</h2>
<h3>{{widget_user.email}}</h3> <h3>{{widget_user.email}}</h3>
<h4>{{widget_user.department.dept_name}}</h4> <h4>{{widget_user.department.dept_name}}</h4>
<h4>{{widget_user.department.home_unit}}</h4> <h4>{{widget_user.department.home_unit}}</h4> <br>
<a href="{%url 'homepage'%}"> Return to Homepage </a>
</div> </div>
{%endblock%} {%endblock%}
\ No newline at end of file
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
{%for w in widget_users%} {%for w in widget_users%}
<li><a href="{%url 'details' w.id_num%}">{{w.last_name}}, {{w.first_name}} {{w.middle_name}}</a></li> <li><a href="{%url 'details' w.id_num%}">{{w.last_name}}, {{w.first_name}} {{w.middle_name}}</a></li>
{%endfor%} {%endfor%}
</ol> </ol> <br>
<h2><a href="{%url 'adduser'%}">Add User</a></h2>
</div> </div>
{%endblock%} {%endblock%}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import UserDetailsView
urlpatterns = [ urlpatterns = [
path('', views.homepage_view, name='homepage'), path('', views.homepage_view, name='homepage'),
path('users/<user_id>/details', views.details, name='details') path('users/<user_id>/details', UserDetailsView.as_view(), name='details'),
path('users/add', views.addUser, name='adduser')
] ]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.views import View
from .models import Department, WidgetUser from .models import Department, WidgetUser
from .homepage_forms import AddUserForm
# Create your views here. # Create your views here.
""" """
...@@ -24,12 +26,36 @@ def homepage_view(request): ...@@ -24,12 +26,36 @@ def homepage_view(request):
} }
return render(request, "homepage/home.html", homepage_dict) return render(request, "homepage/home.html", homepage_dict)
#CBV
"""
def details(request, user_id): def details(request, user_id):
widget_user = WidgetUser.objects.get(id_num=user_id) widget_user = WidgetUser.objects.get(id_num=user_id)
imgurl = f"homepage/images/{user_id}.png" imgurl = f"../../../media/userpfp/{user_id}.png"
details_dict = { details_dict = {
"widget_user" : widget_user, "widget_user" : widget_user,
"imgurl" : imgurl "imgurl" : imgurl
} }
return render(request, "homepage/details.html", details_dict) return render(request, "homepage/details.html", details_dict)
\ No newline at end of file """
class UserDetailsView(View):
def get(self, request, user_id):
widget_user = WidgetUser.objects.get(id_num=user_id)
imgurl = f"../../../media/userpfp/{user_id}.png"
details_dict = {
"widget_user" : widget_user,
"imgurl" : imgurl
}
return render(request, "homepage/details.html", details_dict)
#FBV
def addUser(request):
form = AddUserForm()
if request.method == 'POST':
form = AddUserForm(request.POST, request.FILES)
if form.is_valid():
form.save()
context = {
"form" : form
}
return render(request, "homepage/adduser.html", context)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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