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