can now add users and pfp

parent 79241fd7
# Generated by Django 4.0.3 on 2022-05-22 15:43
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('assignments', '0007_auto_20220518_1124'),
('assignments', '0009_alter_course_course_code_alter_course_course_title'),
]
operations = [
]
...@@ -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
...@@ -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%}
...@@ -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%}
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 = {
"widget_user" : widget_user,
"imgurl" : imgurl
}
return render(request, "homepage/details.html", details_dict)
"""
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 = { 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)
#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)
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