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

Added a new WidgetUser form that accepts the information for a new user; only...

Added a new WidgetUser form that accepts the information for a new user; only WidgetUser fields functional, Department fields still need extra work
parent bba2fb18
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"]
class DepartmentForm(ModelForm):
class Meta:
model = Department
fields = ["dept_name", "home_unit"]
h1, h2 { h1, h2, h3 {
color: black; color: black;
font-family: 'Montserrat', sans-serif; font-family: 'Montserrat', sans-serif;
position: relative; position: relative;
......
...@@ -12,4 +12,5 @@ ...@@ -12,4 +12,5 @@
{% else %} {% else %}
<p>No users found.</p> <p>No users found.</p>
{% endif %} {% endif %}
<h3><a href="/homepage/users/add">Add Widget User</a></h3>
{% endblock %} {% endblock %}
{% extends "homepage/base.html" %}
{% block content %}
<form class="" action="index.html" method="post">
{% csrf_token %}
{{ user_form.as_p }}
{{ dept_form }}
<button type="button" name="submit">Save New User</button>
</form>
{% endblock %}
from django.urls import path from django.urls import path
from . import views from . import views
app_name = "homepage"
urlpatterns = [ urlpatterns = [
path('', views.index, name="homepage"), path('', views.index, name="homepage"),
path('users/<int:user_id>/details/', views.details, name="details"), path('users/<int:user_id>/details/', views.details, name="details"),
path('users/add', views.adduser, name="adduser"),
] ]
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from homepage.models import WidgetUser, Department from homepage.models import WidgetUser, Department
from django.shortcuts import render from django.shortcuts import render, redirect
from django.template import loader from django.template import loader
from .forms import UserForm, DepartmentForm
# Create your views here. # Create your views here.
...@@ -26,3 +27,21 @@ def details(request, user_id): ...@@ -26,3 +27,21 @@ def details(request, user_id):
"userDept": userDept, "userDept": userDept,
} }
return render(request, "homepage/details.html", context) return render(request, "homepage/details.html", context)
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():
user_form.save()
dept_form.save()
return redirect("homepage")
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