Commit bb1f3a69 authored by Ramon Angelo Enriquez's avatar Ramon Angelo Enriquez

Homepage form is now functional, except for the profile picture field

parent f8f6ec95
......@@ -3,19 +3,19 @@ from .models import WidgetUser, Department
# Register your models here.
class DepartmentAdminInline(admin.TabularInline):
model = Department
class WidgetUserAdmin(admin.ModelAdmin):
class WidgetUserAdminInline(admin.TabularInline):
model = WidgetUser
inlines = [DepartmentAdminInline]
class DepartmentAdmin(admin.ModelAdmin):
model = Department
inlines = [WidgetUserAdminInline]
class WidgetUserAdmin(admin.ModelAdmin):
model = WidgetUser
admin.site.register(WidgetUser, WidgetUserAdmin)
admin.site.register(Department, DepartmentAdmin)
......@@ -6,9 +6,4 @@ class UserForm(ModelForm):
class Meta:
model = WidgetUser
fields = ["last_name", "first_name", "middle_name", "id_num", "email",
"picture"]
class DepartmentForm(ModelForm):
class Meta:
model = Department
fields = ["dept_name", "home_unit"]
"picture", "department"]
# Generated by Django 4.0.3 on 2022-05-19 09:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0011_alter_widgetuser_picture'),
]
operations = [
migrations.RemoveField(
model_name='department',
name='widget_user',
),
migrations.AddField(
model_name='widgetuser',
name='department',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.department'),
),
]
......@@ -2,7 +2,17 @@ from django.db import models
# Create your models here.
class Department(models.Model):
dept_name = models.CharField(max_length=50, null=True)
home_unit = models.CharField(max_length=50, null=True)
def __str__(self):
return self.dept_name + ", " + self.home_unit
class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete=models.CASCADE,
blank=True, null=True)
first_name = models.CharField(max_length=50, null=True)
middle_name = models.CharField(max_length=50, null=True)
last_name = models.CharField(max_length=50, null=True)
......@@ -12,13 +22,3 @@ class WidgetUser(models.Model):
def __str__(self):
return self.last_name + ", " + self.first_name
class Department(models.Model):
widget_user = models.ForeignKey(WidgetUser, on_delete=models.CASCADE,
blank=True, null=True)
dept_name = models.CharField(max_length=50, null=True)
home_unit = models.CharField(max_length=50, null=True)
def __str__(self):
return self.dept_name + ", " + self.home_unit
......@@ -4,14 +4,14 @@
<div class="rectangleDetailsHeader"></div>
<a href="/homepage/"><div class="arrow"></div></a>
<h1 class="detailsHeaderName">{{ user.first_name }} {{ user.last_name }}</h1>
<h3 class="detailsHeaderDept">Department of {{ userDept.dept_name }}</h3>
<h3 class="detailsHeaderDept">Department of {{ user.department.dept_name }}</h3>
<h2 style="position: absolute; left: 300px; top: 270px; background-color: #fcf4dd;">Personal Information</h2>
<h2 style="position: absolute; left: 300px; top: 450px; background-color: #fcf4dd;">Department Information</h2>
<h2 style="position: absolute; left: 850px; top: 270px; background-color: #fcf4dd;">Contact Details</h2>
<p style="position:absolute; left: 300px; top: 325px;">Complete Name: {{ user.last_name }}, {{user.first_name }} {{ user.middle_name }}</p>
<p style="position:absolute; left: 300px; top: 370px;">ID Number: {{ user.id_num }}</p>
<p style="position: absolute; left: 300px; top: 500px;">Department: {{ userDept.dept_name }}</p>
<p style="position: absolute; left: 300px; top: 545px;">Home Unit: {{ userDept.home_unit }}</p>
<p style="position: absolute; left: 300px; top: 500px;">Department: {{ user.department.dept_name }}</p>
<p style="position: absolute; left: 300px; top: 545px;">Home Unit: {{ user.department.home_unit }}</p>
<p style="position: absolute; left: 850px; top: 325px;">Email: {{ user.email }}</p>
<div class="picShadow"></div>
<img src="{{ user.picture.url }}" width="200" height="200">
......
{% extends "homepage/base.html" %}
{% block content %}
<form class="" action="index.html" method="post">
<form class="" action="{% url 'homepage:adduser' %}" method="post">
{% csrf_token %}
{{ user_form.as_p }}
{{ dept_form }}
<button type="button" name="submit">Save New User</button>
<button class="button" type="submit">Save New User</button>
</form>
{% endblock %}
from django.urls import path
from . import views
from .views import HomepageView, HomepageDetailsView
app_name = "homepage"
urlpatterns = [
path('', views.index, name="homepage"),
path('users/<int:user_id>/details/', views.details, name="details"),
path('', HomepageView.as_view(), name="homepage"),
path('users/<int:user_id>/details/', HomepageDetailsView.as_view(), name="details"),
path('users/add', views.adduser, name="adduser"),
]
......@@ -2,29 +2,29 @@ from django.http import HttpResponse, Http404
from homepage.models import WidgetUser, Department
from django.shortcuts import render, redirect
from django.template import loader
from .forms import UserForm, DepartmentForm
from .forms import UserForm
from django.views import View
# Create your views here.
def index(request):
class HomepageView(View):
def get(self, request):
user_list = WidgetUser.objects.order_by("last_name")
context = {
"user_list": user_list,
}
return render(request, "homepage/index.html", context)
def details(request, user_id):
class HomepageDetailsView(View):
def get(self, request, user_id):
try:
user = WidgetUser.objects.get(pk=user_id)
userDept = Department.objects.get(widget_user=user)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist.")
context = {
"user": user,
"userDept": userDept,
}
return render(request, "homepage/details.html", context)
......@@ -32,16 +32,12 @@ def details(request, user_id):
def adduser(request):
if request.method == "POST":
user_form = UserForm(request.POST)
dept_form = DepartmentForm(request.POST)
if user_form.is_valid() and dept_form.is_valid():
if user_form.is_valid():
user_form.save()
dept_form.save()
return redirect("homepage")
return redirect("homepage:adduser")
else:
user_form = UserForm()
dept_form = DepartmentForm(request.POST)
context = {
"user_form": user_form,
"dept_form": dept_form,
}
return render(request, "homepage/newuser.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