Commit 2df198f4 authored by John Tamano's avatar John Tamano

Added final project changes; created add user for homepage and converted displayWidgetUser to CBV

parent ced295d0
from tkinter import Widget
from django.forms import ModelForm
from .models import WidgetUser, Department
class addWidgetUserForm(ModelForm):
class Meta:
model = WidgetUser
fields = ["first_name", "middle_name", "last_name", "id_num", "email", "department"]
\ No newline at end of file
{% extends "homepage/base.html" %}
{% block content %}
<h1>Add Widget User</h1>
<form action="{% url 'homepage:addWidgetUser' %}" method="POST">
{% csrf_token %}
{{ addwidgetuser }}
<button class="button" type="submit">Save New User</button>
</form>
<br>
<p1>
<a href = "/homepage/">Back to Homepage</a>
</p1>
{% endblock %}
\ No newline at end of file
......@@ -10,4 +10,8 @@
</p1>
{% endfor %}
</ol>
<br>
<form action="/users/add">
<input type="submit" value="Add Widget User" />
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import displayWidgetUsers, displayUserDetails
from .views import displayWidgetUsers, displayUserDetails, addWidgetUser
urlpatterns = [
path('homepage/',displayWidgetUsers, name='displayWidgetUsers'),
path('users/<int:user_id>/details',displayUserDetails, name='displayUserDetails')
path('homepage/',displayWidgetUsers.as_view(), name='displayWidgetUsers'),
path('users/<int:user_id>/details',displayUserDetails, name='displayUserDetails'),
path('users/add',addWidgetUser, name='addWidgetUser')
]
app_name = "homepage"
\ No newline at end of file
from tkinter import Widget
from django.shortcuts import render
from django.template.loader import get_template
from django.shortcuts import redirect, render
from django.views import View
from homepage.models import Department, WidgetUser
from django.template import Template, Context
from django.http import Http404, HttpResponse
from . import models
from .forms import addWidgetUserForm
def index(request):
return HttpResponse('Welcome to Widget!')
def displayWidgetUsers(request):
class displayWidgetUsers(View):
template = 'homepage/homepage.html'
def get(self,request):
WidgetUsers = models.WidgetUser.objects.order_by("last_name")
context = {
"WidgetUsers": WidgetUsers
}
return render(request, "homepage/homepage.html", context)
return render(request, self.template, context)
def displayUserDetails(request, user_id):
try:
......@@ -27,4 +30,16 @@ def displayUserDetails(request, user_id):
}
return render(request, "homepage/details.html", context)
def addWidgetUser(request):
Departments = models.Department.objects.all()
if request.method == "POST":
add_WidgetUser = addWidgetUserForm(request.POST)
if add_WidgetUser.is_valid():
new_WidgetUser = add_WidgetUser.save()
return redirect("homepage:addWidgetUser")
else:
add_WidgetUser = addWidgetUserForm()
return render (request, "homepage/adduser.html", {"addwidgetuser": add_WidgetUser})
# Create your views here.
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