Commit 4aef3fdf authored by John Tamano's avatar John Tamano

Merge branch 'tamano/homepage_final'

parents 2a7e03cd 4d4e7cba
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 @@ ...@@ -10,4 +10,8 @@
</p1> </p1>
{% endfor %} {% endfor %}
</ol> </ol>
<br>
<form action="/users/add">
<input type="submit" value="Add Widget User" />
</form>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import displayWidgetUsers, displayUserDetails from .views import displayWidgetUsers, displayUserDetails, addWidgetUser
urlpatterns = [ urlpatterns = [
path('homepage/',displayWidgetUsers, name='displayWidgetUsers'), path('homepage/',displayWidgetUsers.as_view(), name='displayWidgetUsers'),
path('users/<int:user_id>/details',displayUserDetails, name='displayUserDetails') path('users/<int:user_id>/details',displayUserDetails, name='displayUserDetails'),
path('users/add',addWidgetUser, name='addWidgetUser')
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from tkinter import Widget from django.shortcuts import redirect, render
from django.shortcuts import render from django.views import View
from django.template.loader import get_template
from homepage.models import Department, WidgetUser from homepage.models import Department, WidgetUser
from django.template import Template, Context from django.template import Template, Context
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from . import models from . import models
from .forms import addWidgetUserForm
def index(request): def index(request):
return HttpResponse('Welcome to Widget!') 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") WidgetUsers = models.WidgetUser.objects.order_by("last_name")
context = { context = {
"WidgetUsers": WidgetUsers "WidgetUsers": WidgetUsers
} }
return render(request, "homepage/homepage.html", context) return render(request, self.template, context)
def displayUserDetails(request, user_id): def displayUserDetails(request, user_id):
try: try:
...@@ -27,4 +30,16 @@ def displayUserDetails(request, user_id): ...@@ -27,4 +30,16 @@ def displayUserDetails(request, user_id):
} }
return render(request, "homepage/details.html", context) 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. # 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