Commit aa45954c authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴

Created forms.py and WidgetUserForm, Modified views.py and urls.py, Created...

Created forms.py and WidgetUserForm, Modified views.py and urls.py, Created html and css file for adding widget users, Fixed code in html files
parent 896379f3
from .forms import ModelForm
from .models import WidgetUser
class WidgetUserForm(ModelForm):
class Meta:
model = WidgetUser
fields = "__all__"
\ No newline at end of file
from django.urls import path from django.urls import path
from homepage import views from homepage import views
from .views import (WidgetUserCreateView,HomepageView)
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', HomepageView.as_view(), name='homepage'),
path('users/<str:user_id>/details', views.details, name='details'), path('users/<str:user_id>/details', views.details, name='widgetuser_details'),
path('user/add', WidgetUserCreateView.as_view(), name="widgetuser_add")
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from re import A, template from django.shortcuts import render,redirect
from django.shortcuts import render
from django.template import loader from django.template import loader
from django.http import HttpResponse from django.http import HttpResponse
from .models import WidgetUser from .models import WidgetUser,Department
from django.views.generic.edit import CreateView
from django.views.generic import View
# Create your views here. # Create your views here.
def index(request):
user_list = WidgetUser.objects.order_by("last_name")
template = loader.get_template("homepage/homepage.html")
context = {
"user_list" : user_list,
}
return HttpResponse(template.render(context,request))
class HomepageView(View):
def get(self,request):
user_list = WidgetUser.objects.order_by("last_name")
return render(request,"homepage/homepage.html",{"user_list" : user_list})
def details(request,user_id): def details(request,user_id):
user = WidgetUser.objects.get(id_num=user_id) user = WidgetUser.objects.get(id_num=user_id)
template = loader.get_template("homepage/details.html") template = loader.get_template("homepage/widgetuser_details.html")
context = { context = {
"user" : user, "user" : user,
} }
return HttpResponse(template.render(context,request)) return HttpResponse(template.render(context,request))
#model = WidgetUser class WidgetUserCreateView(CreateView):
#widget_users = model.objects.all() model = WidgetUser
#homepage_response = "WIDGET USERS: </br>" fields = '__all__'
#for user in widget_users: def form_valid(request,form):
#homepage_response += user.get_user_info() if form.is_valid():
new_user = form.save()
return redirect("homepage:widgetuser_add")
#return HttpResponse(homepage_response) def get_context_data(self, **kwargs):
\ No newline at end of file context = super().get_context_data(**kwargs)
context["departments"] = Department.objects.all()
return context
...@@ -26,9 +26,28 @@ wu { ...@@ -26,9 +26,28 @@ wu {
font-size: 25px; font-size: 25px;
font-weight: 500; font-weight: 500;
} }
a { a {
color: black; color: black;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
text-decoration: none; text-decoration: none;
font-size: large; font-size: large;
} }
ol {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
button {
background-color: rgb(35,116,225);
border: 0px;
color: white;
margin-left: 40px;
font-size: 15px;
border-radius: 4px;
transition-duration: 0.4s;
}
button:hover{
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ header{ ...@@ -10,6 +10,7 @@ header{
margin: -9px; margin: -9px;
margin-bottom: 0px; margin-bottom: 0px;
} }
wid { wid {
float: left; float: left;
margin-top: 50px; margin-top: 50px;
...@@ -28,6 +29,7 @@ infohead{ ...@@ -28,6 +29,7 @@ infohead{
line-height: 40px; line-height: 40px;
font-weight: bold; font-weight: bold;
} }
info{ info{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 10px; line-height: 10px;
...@@ -44,3 +46,17 @@ img { ...@@ -44,3 +46,17 @@ img {
margin-right: 50px; margin-right: 50px;
} }
button {
background-color: rgb(35,116,225);
border: 2px;
margin-top: 10px;
color: white;
font-size: 18px;
border-radius: 4px;
transition-duration: 0.4s;
}
button:hover{
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
body{
background-color: rgb(227,229,231);
font-family: Helvetica, Arial, sans-serif;
}
header {
margin-top: -10px;
margin-left: -10px;
margin-right: -10px;
padding: 30px;
background-color: rgb(35,116,225);
text-align: center;
color: white;
font-size: 200%;
font-family: Klavika, Arial, Helvetica, sans-serif;
font-weight: bold;
}
form{
font-family: Helvetica, Arial, sans-serif;
}
button {
background-color: rgb(35,116,225);
border: 0px;
color: white;
font-size: 15px;
border-radius: 4px;
transition-duration: 0.4s;
}
button:hover{
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
#submit_button {
background-color: rgb(35,116,225);
border: 2px;
margin-top: 10px;
color: white;
font-size: 15px;
border-radius: 4px;
transition-duration: 0.4s;
}
#submit_button:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
<wu> Widget Users: </wu> <wu> Widget Users: </wu>
<ol type = '1'> <ol type = '1'>
{% for user in user_list %} {% for user in user_list %}
<a href = "{% url 'homepage:details' user.id_num %}""> <a href = "{% url 'homepage:widgetuser_details' user.id_num %}">
<li>{{user.last_name}}, {{user.first_name}} {{user.middle_name}} </br> </a> </li> </p> <li>{{user.last_name}}, {{user.first_name}} {{user.middle_name}} </br> </a> </li> </p>
{% endfor %} {% endfor %}
</ol> </ol>
<button onclick="window.location.href='{% url 'homepage:widgetuser_add'%}'" id="add_user_button"> Add Widget User </button>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% load static %} {% load static %}
{% block title %} User Details {% endblock %} {% block title %} User Details {% endblock %}
{% block styles %} <link rel="stylesheet" href="{% static 'homepage/css/details.css' %}"> {% endblock %} {% block styles %} <link rel="stylesheet" href="{% static 'homepage/css/widgetuser_details.css' %}"> {% endblock %}
{% block content %} {% block content %}
<wid>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</wid> <wid>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</wid>
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
Department name: {{user.department}} </br> Department name: {{user.department}} </br>
Home unit: {{user.department.home_unit}} </br> Home unit: {{user.department.home_unit}} </br>
</info> </info>
<button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Add User {% endblock %}
{% block styles %} <link rel="stylesheet" href="{% static 'homepage/css/widgetuser_form.css' %}"> {% endblock %}
{% block content %}
<header> Add Widget User: </header>
<form method = "POST" action="">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Save New User" id="submit_button"> <button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button>
</form>
{% endblock %}
\ 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