Commit 1f5f5e5a authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴

Merged dumandan/homepage to master and resolved merge conflicts

parents d6c40e18 8d5dab61
from .forms import ModelForm
from .models import WidgetUser
#ModelForm allows for a easier creation of forms through simply identifying the model and fields
class WidgetUserForm(ModelForm):
class Meta:
model = WidgetUser
#__all__ accepts input for all fields
fields = "__all__"
\ No newline at end of file
from django.urls import path
from homepage import views
from .views import (WidgetUserCreateView,HomepageView)
urlpatterns = [
path('', views.index, name='index'),
path('users/<str:user_id>/details', views.details, name='details'),
path('', HomepageView.as_view(), name='homepage'),
path('users/<str:user_id>/details', views.details, name='widgetuser_details'),
path('user/add', WidgetUserCreateView.as_view(), name="widgetuser_add")
]
app_name = "homepage"
\ No newline at end of file
from re import A, template
from django.shortcuts import render
from django.shortcuts import render,redirect
from django.template import loader
from django.http import HttpResponse
from .models import WidgetUser
# 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))
from .models import WidgetUser,Department
from django.views.generic.edit import CreateView
from django.views.generic import View
#Converted from Function-based view
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):
user = WidgetUser.objects.get(id_num=user_id)
<<<<<<< HEAD
template = loader.get_template("homepage/details.html")
context = {
"user" : user,
}
return HttpResponse(template.render(context,request))
\ No newline at end of file
return HttpResponse(template.render(context,request))
=======
template = loader.get_template("homepage/widgetuser_details.html")
context = {"user" : user,}
return HttpResponse(template.render(context,request))
#View for adding a new WidgetUser
class WidgetUserCreateView(CreateView):
model = WidgetUser
fields = '__all__'
#Checks if the form is valid and if it is, saves the form to create the new user then redirects to the same page
def form_valid(request,form):
if form.is_valid():
new_user = form.save()
return redirect("homepage:widgetuser_add")
#Uses the built-in context function to create a selection of department objects for the form
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["departments"] = Department.objects.all()
return context
>>>>>>> dumandan/homepage
......@@ -34,3 +34,21 @@ a {
text-decoration: none;
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
......@@ -47,3 +47,17 @@ img {
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);
}
......@@ -9,10 +9,17 @@
<header> Welcome to the Widget! </header>
<p>
<wu> Widget Users: </wu>
<!-- Creates an ordered list of all users-->
<ol type = '1'>
{% for user in user_list %}
<<<<<<< HEAD
<a href = "{% url 'homepage:details' user.id_num %}">
=======
<a href = "{% url 'homepage:widgetuser_details' user.id_num %}">
>>>>>>> dumandan/homepage
<li>{{user.last_name}}, {{user.first_name}} {{user.middle_name}} </br> </a> </li> </p>
{% endfor %}
</ol>
<!-- Creates a button that redirects the user to the add user form -->
<button onclick="window.location.href='{% url 'homepage:widgetuser_add'%}'" id="add_user_button"> Add Widget User </button>
{% endblock %}
\ No newline at end of file
......@@ -2,20 +2,21 @@
{% load static %}
{% 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 %}
<wid>{{user.last_name}}, {{user.first_name}} {{user.middle_name}}</wid>
<header></header>
<!-- Loads an image from the static folder (Profile Picture of the User)-->
<img src="{% static 'homepage/img/profile-picture.jpg' %}" alt="Profile Picture">
<infohead>User Details</br></infohead>
<infohead> User Details </br> </infohead>
<info>
ID number: {{user.id_num}} </br>
Email address: {{user.email}} </br>
Department name: {{user.department}} </br>
Home unit: {{user.department.home_unit}} </br>
</info>
<!-- Button for redirecting to homepage -->
<button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button>
{% 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="">
<!-- Required for posting -->
{% csrf_token %}
<!-- Renders the form as a paragraph -->
{{form.as_p}}
<!-- Creates a submit button for the new user and another button to redirect back to homepage -->
<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