Commit 8d5dab61 authored by Andre Matthew Dumandan's avatar Andre Matthew Dumandan 😴

Added comments for Homepage files

parent ea1be691
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
......@@ -4,8 +4,8 @@ from django.http import HttpResponse
from .models import WidgetUser,Department
from django.views.generic.edit import CreateView
from django.views.generic import View
# Create your views here.
#Converted from Function-based view
class HomepageView(View):
def get(self,request):
user_list = WidgetUser.objects.order_by("last_name")
......@@ -14,20 +14,21 @@ class HomepageView(View):
def details(request,user_id):
user = WidgetUser.objects.get(id_num=user_id)
template = loader.get_template("homepage/widgetuser_details.html")
context = {
"user" : user,
}
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()
......
......@@ -9,11 +9,13 @@
<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 %}
<a href = "{% url 'homepage:widgetuser_details' user.id_num %}">
<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
......@@ -7,16 +7,16 @@
{% 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
......@@ -8,8 +8,11 @@
{% 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