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 import django.core.validators
from django.db import migrations, models from django.db import migrations, models
...@@ -11,6 +11,11 @@ class Migration(migrations.Migration): ...@@ -11,6 +11,11 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.AddField(
model_name='widgetuser',
name='profile_url',
field=models.FileField(null=True, upload_to='homepage/static/'),
),
migrations.AlterField( migrations.AlterField(
model_name='widgetuser', model_name='widgetuser',
name='id_num', 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): ...@@ -19,7 +19,7 @@ class WidgetUser(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
null=True, null=True,
related_name='department') 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): def __str__(self):
return self.first_name 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 @@ ...@@ -5,16 +5,22 @@
{% block content %} {% block content %}
<div style = "position: relative; left:80px; top:30px;"> <div style = "position: relative; left:80px; top:30px;">
<h1>WELCOME TO WIDGET!</h1> <h1>WELCOME TO WIDGET!</h1>
</div> </div>
<div style = "position:relative; left:80px; top:35px;"> <div style = "position:relative; left:80px; top:35px;">
<p>Widget Users: <p>Widget Users:</p>
<p>
{% if widget_user %}
<ol> <ol>
{% for user in widget_user %} {% for user in widget_user %}
<li><a href="/users/{{ user.id_num }}/details/"> <li><a href="/users/{{ user.id_num }}/details/">
{{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }} {{ user.last_name }}, {{ user.first_name }} {{ user.middle_name }}
</a></li> </a></li>
{% endfor %} {% endfor %}
<button onclick="location.href = '/users/add'">Add Widget User</button>
</ol> </ol>
</p> </p>
{% else %}
<p>No users are available.</p>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
app_name = 'homepage'
urlpatterns = [ urlpatterns = [
path('homepage/', views.index, name='index'), path('homepage/', views.HomePageView.as_view(), name='index'),
path('welcome', views.welcome, name='welcome'), path('welcome', views.welcome, name='welcome'),
path('users/add/', views.add, name='add'),
path("users/<int:id_num>/details/", views.details, name='details') 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 django.http import HttpResponse, Http404
from .models import Department, WidgetUser from .models import Department, WidgetUser
from .forms import UserForm
from django.views import View
# Create your views here. # Create your views here.
def welcome(request): def welcome(request):
return HttpResponse('Welcome to Widget!') return HttpResponse('Welcome to Widget!')
def index(request): class HomePageView(View):
def get(self, request):
widget_user = WidgetUser.objects.order_by("last_name") widget_user = WidgetUser.objects.order_by("last_name")
context = { return render(request, "homepage/index.html", {"widget_user": widget_user})
"widget_user": widget_user
}
return render(request, "homepage/index.html", context)
''' '''
...@@ -36,7 +36,17 @@ def index(request): ...@@ -36,7 +36,17 @@ def index(request):
def details(request, id_num): def details(request, id_num):
try: try:
details = WidgetUser.objects.get(pk=id_num) details = WidgetUser.objects.get(id_num=id_num)
except WidgetUser.DoesNotExist: except WidgetUser.DoesNotExist:
raise Http404("User does not exist.") raise Http404("User does not exist.")
return render(request, "homepage/details.html", {"details": details}) 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