Commit 7bd38a61 authored by Vaughn Fajardo's avatar Vaughn Fajardo

feat: add widget user page and button from homepage, CBV display of homepage

parent 6c6e44db
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", "department",
"profile_url"]
# Generated by Django 4.0.3 on 2022-04-05 11:02
# Generated by Django 4.0.3 on 2022-05-15 15:43
import django.core.validators
from django.db import migrations, models
......@@ -11,6 +11,11 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='profile_url',
field=models.FileField(null=True, upload_to='homepage/static/'),
),
migrations.AlterField(
model_name='widgetuser',
name='id_num',
......
# Generated by Django 4.0.3 on 2022-05-06 09:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0007_alter_widgetuser_id_num'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='homeunit',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='homeunit', to='homepage.department'),
),
]
# Generated by Django 4.0.3 on 2022-05-06 09:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('homepage', '0008_widgetuser_homeunit'),
]
operations = [
migrations.RemoveField(
model_name='widgetuser',
name='homeunit',
),
]
# Generated by Django 4.0.3 on 2022-05-15 09:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('homepage', '0009_remove_widgetuser_homeunit'),
]
operations = [
migrations.AddField(
model_name='widgetuser',
name='profile_url',
field=models.FileField(blank=True, null=True, upload_to='homepage/static/'),
),
]
......@@ -19,7 +19,7 @@ class WidgetUser(models.Model):
on_delete=models.CASCADE,
null=True,
related_name='department')
profile_url = models.FileField(upload_to='homepage/static/', blank=True, null=True)
profile_url = models.FileField(upload_to='static/', null=True)
def __str__(self):
return self.first_name
......
{% extends "base.html" %}
{% block page-title %}Add Widget User{% endblock %}
{% block content %}
<div style = "position: relative; left:80px; top:30px;">
<h1>ADD WIDGET USER</h1>
</div>
<div style = "position: relative; left:80px; top:30px;">
<form method="POST" action ="{% url 'homepage:add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ user_form.as_p }}
<button class="button" type="Save New User">Save New User</button>
<button onclick="location.href = '/homepage'">Return to Homepage</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
......@@ -5,16 +5,22 @@
{% block content %}
<div style = "position: relative; left:80px; top:30px;">
<h1>WELCOME TO WIDGET!</h1>
</div>
</div>
<div style = "position:relative; left:80px; top:35px;">
<p>Widget Users:
<ol>
{% for user in widget_user %}
<li><a href="/users/{{ user.id_num }}/details/">
{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}
</a></li>
{% endfor %}
</ol>
<p>Widget Users:</p>
<p>
{% if widget_user %}
<ol>
{% for user in widget_user %}
<li><a href="/users/{{ user.id_num }}/details/">
{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}
</a></li>
{% endfor %}
<button onclick="location.href = '/users/add'">Add Widget User</button>
</ol>
</p>
{% else %}
<p>No users are available.</p>
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
app_name = 'homepage'
urlpatterns = [
path('homepage/', views.index, name='index'),
path('homepage/', views.HomePageView.as_view(), name='index'),
path('welcome', views.welcome, name='welcome'),
path('users/add/', views.add, name='add'),
path("users/<int:id_num>/details/", views.details, name='details')
]
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse, Http404
from .models import Department, WidgetUser
from .forms import UserForm
from django.views import View
# Create your views here.
def welcome(request):
return HttpResponse('Welcome to Widget!')
def index(request):
widget_user = WidgetUser.objects.order_by("last_name")
context = {
"widget_user": widget_user
}
return render(request, "homepage/index.html", context)
class HomePageView(View):
def get(self, request):
widget_user = WidgetUser.objects.order_by("last_name")
return render(request, "homepage/index.html", {"widget_user": widget_user})
'''
......@@ -36,7 +36,17 @@ def index(request):
def details(request, id_num):
try:
details = WidgetUser.objects.get(pk=id_num)
details = WidgetUser.objects.get(id_num=id_num)
except WidgetUser.DoesNotExist:
raise Http404("User does not exist.")
return render(request, "homepage/details.html", {"details": details})
\ No newline at end of file
return render(request, "homepage/details.html", {"details": details})
def add(request):
if request.method == "POST":
user_form = UserForm(request.POST, request.FILES)
if user_form.is_valid():
user_form.save()
return redirect("/homepage")
else:
user_form = UserForm()
return render(request,"homepage/add.html", {"user_form": user_form})
\ 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