Commit b6962c2d authored by N1o9r4b7e9r6to's avatar N1o9r4b7e9r6to
parents d2f803fd 4aef3fdf
...@@ -9,4 +9,6 @@ Video Link: ...@@ -9,4 +9,6 @@ Video Link:
lab 1: https://drive.google.com/file/d/1z2XHTnQ7nJKCFwqBej1j5oHdPeqlgw3a/view?usp=sharing lab 1: https://drive.google.com/file/d/1z2XHTnQ7nJKCFwqBej1j5oHdPeqlgw3a/view?usp=sharing
lab 2: https://drive.google.com/file/d/1vtu_kh7m-3JXMxij--QwdLjV5o4kjN_1/view?usp=sharing lab 2: https://drive.google.com/file/d/1vtu_kh7m-3JXMxij--QwdLjV5o4kjN_1/view?usp=sharing
\ No newline at end of file
lab 3: https://drive.google.com/file/d/1i3_PmheoFS91xp5YkXCobtHTS80JI16k/view?usp=sharing
\ No newline at end of file
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):
WidgetUsers = models.WidgetUser.objects.order_by("last_name") template = 'homepage/homepage.html'
context = { def get(self,request):
WidgetUsers = models.WidgetUser.objects.order_by("last_name")
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