Commit 8781eaa5 authored by Teo Quinto's avatar Teo Quinto

added new page to add new users and buttons to navigate between pages

parent 91976c48
from django.forms import ModelForm
from .models import WidgetUser
class WidgetUserForm(ModelForm):
class Meta:
model = WidgetUser
fields = ["last_name", "first_name", "middle_name",
"id_num", "email", "department", "profile"]
\ No newline at end of file
{% extends 'homepage/base.html' %}
{% block title %}Add User{% endblock %}
{% block content %}
<h1>Add Widget User</h1>
<form method="POST" action="{% url 'homepage:add' %}"
enctype="multipart/form-data">
{% csrf_token %}
{{ widgetUserForm.as_p }}
<button class="button" type="submit">Save New User</button>
<button onclick="window.location.href='../..';">Back to Homepage</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -10,6 +10,8 @@
<br />Department name: {{ user.department.dept_name }}
<br />Home unit: {{ user.department.home_unit }}
{% load static %}
<br /><br /><br /><img src="{{ user.profile.url }}" alt="{{user.last_name}}" style="width:50%">
<br /><br /><img src="{{ user.profile.url }}" alt="{{user.last_name}}"
style="width:50%"><br />
<button onclick="window.location.href='../../..';">Back to Homepage</button>
</p>
{% endblock %}
\ No newline at end of file
......@@ -8,10 +8,12 @@
{% if users %}
<ol>
{% for user in users %}
<li><a href="users/{{ user.id }}/details/">{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}</a></li>
<li><a href="users/{{ user.id }}/details/">{{ user.last_name }},
{{ user.first_name }} {{ user.middle_name }}</a></li>
{% endfor %}
</ol>
{% else %}
<p>No users are available</p>
{% endif %}
<button onclick="window.location.href='users/add/';">Add Widget User</button>
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,9 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
# homepage/users/1/details/
path("users/<int:user_id>/details/", views.details, name="details")
path("users/<int:user_id>/details/", views.details, name="details"),
# homepage/users/add/
path("users/add/", views.add, name="add"),
]
app_name = "homepage"
\ No newline at end of file
from django.http import Http404, HttpResponse
from django.shortcuts import render
from django.shortcuts import render, redirect
from .models import Department, WidgetUser
users = WidgetUser.objects.order_by("last_name")
from .forms import WidgetUserForm
# Create your views here.
def index(request):
users = WidgetUser.objects.order_by("last_name")
context = {
"users": users,
}
......@@ -16,6 +16,7 @@ def details(request, user_id):
user = WidgetUser.objects.get(pk=user_id)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist!")
users = WidgetUser.objects.order_by("last_name")
for person in users:
if person.id == user_id:
user = person
......@@ -24,4 +25,15 @@ def details(request, user_id):
"user": user,
"user_id": user_id
}
return render(request, "homepage/details.html", context)
\ No newline at end of file
return render(request, "homepage/details.html", context)
def add(request):
if request.method == "POST":
widgetUserForm = WidgetUserForm(request.POST, request.FILES)
if widgetUserForm.is_valid():
new_user = widgetUserForm.save()
return redirect("homepage:index")
else:
widgetUserForm = WidgetUserForm()
return render(request, "homepage/add.html",
{"widgetUserForm": widgetUserForm})
\ No newline at end of file
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