Commit 1f0595db authored by Ramon Angelo Enriquez's avatar Ramon Angelo Enriquez

Added functional homepage form that accepts all input for a new user,...

Added functional homepage form that accepts all input for a new user, including their profile picture
parents 3d0391a0 87c9c6d3
......@@ -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)
from django import forms
from django.forms import ModelForm
from .models import WidgetUser, Department
class UserForm(ModelForm):
class Meta:
model = WidgetUser
fields = ["last_name", "first_name", "middle_name", "id_num", "email",
"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
h1, h2 {
h1, h2, h3 {
color: black;
font-family: 'Montserrat', sans-serif;
position: relative;
......
......@@ -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">
......
......@@ -12,4 +12,5 @@
{% else %}
<p>No users found.</p>
{% endif %}
<h3><a href="/homepage/users/add">Add Widget User</a></h3>
{% endblock %}
{% extends "homepage/base.html" %}
{% block content %}
<form class="" action="{% url 'homepage:adduser' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ user_form.as_p }}
<button class="button" type="submit">Save New User</button>
<h3><a href="{% url 'homepage:home' %}">Return to Homepage</a></h3>
</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="home"),
path('users/<int:user_id>/details/', HomepageDetailsView.as_view(), name="details"),
path('users/add', views.adduser, name="adduser"),
]
from django.http import HttpResponse, Http404
from distutils.command.upload import upload
from tkinter import Widget
from homepage.models import WidgetUser, Department
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.template import loader
from .forms import UserForm
from django.views import View
# Create your views here.
def index(request):
user_list = WidgetUser.objects.order_by("last_name")
context = {
"user_list": user_list,
}
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)
return render(request, "homepage/index.html", context)
class HomepageDetailsView(View):
def get(self, request, user_id):
try:
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist.")
context = {
"user": user,
}
return render(request, "homepage/details.html", context)
def details(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.")
def adduser(request):
if request.method == "POST":
user_form = UserForm(request.POST, request.FILES)
if user_form.is_valid():
user_form.save()
return redirect("homepage:adduser")
else:
user_form = UserForm()
context = {
"user": user,
"userDept": userDept,
"user_form": user_form,
}
return render(request, "homepage/details.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