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

Added comments for Homepage files

parent ea1be691
from .forms import ModelForm from .forms import ModelForm
from .models import WidgetUser from .models import WidgetUser
#ModelForm allows for a easier creation of forms through simply identifying the model and fields
class WidgetUserForm(ModelForm): class WidgetUserForm(ModelForm):
class Meta: class Meta:
model = WidgetUser model = WidgetUser
#__all__ accepts input for all fields
fields = "__all__" fields = "__all__"
\ No newline at end of file
...@@ -4,8 +4,8 @@ from django.http import HttpResponse ...@@ -4,8 +4,8 @@ from django.http import HttpResponse
from .models import WidgetUser,Department from .models import WidgetUser,Department
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
from django.views.generic import View from django.views.generic import View
# Create your views here.
#Converted from Function-based view
class HomepageView(View): class HomepageView(View):
def get(self,request): def get(self,request):
user_list = WidgetUser.objects.order_by("last_name") user_list = WidgetUser.objects.order_by("last_name")
...@@ -14,20 +14,21 @@ class HomepageView(View): ...@@ -14,20 +14,21 @@ class HomepageView(View):
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/widgetuser_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))
#View for adding a new WidgetUser
class WidgetUserCreateView(CreateView): class WidgetUserCreateView(CreateView):
model = WidgetUser model = WidgetUser
fields = '__all__' 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): def form_valid(request,form):
if form.is_valid(): if form.is_valid():
new_user = form.save() new_user = form.save()
return redirect("homepage:widgetuser_add") 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): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["departments"] = Department.objects.all() context["departments"] = Department.objects.all()
......
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
<header> Welcome to the Widget! </header> <header> Welcome to the Widget! </header>
<p> <p>
<wu> Widget Users: </wu> <wu> Widget Users: </wu>
<!-- Creates an ordered list of all users-->
<ol type = '1'> <ol type = '1'>
{% for user in user_list %} {% for user in user_list %}
<a href = "{% url 'homepage:widgetuser_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>
<!-- 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> <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
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
{% 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>
<header></header> <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"> <img src="{% static 'homepage/img/profile-picture.jpg' %}" alt="Profile Picture">
<infohead> User Details </br> </infohead>
<infohead>User Details</br></infohead>
<info> <info>
ID number: {{user.id_num}} </br> ID number: {{user.id_num}} </br>
Email address: {{user.email}} </br> Email address: {{user.email}} </br>
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 for redirecting to homepage -->
<button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button> <button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -8,8 +8,11 @@ ...@@ -8,8 +8,11 @@
{% block content %} {% block content %}
<header> Add Widget User: </header> <header> Add Widget User: </header>
<form method = "POST" action=""> <form method = "POST" action="">
<!-- Required for posting -->
{% csrf_token %} {% csrf_token %}
<!-- Renders the form as a paragraph -->
{{form.as_p}} {{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> <input type="submit" value="Save New User" id="submit_button"> <button onclick="window.location.href='{% url 'homepage:homepage'%}'"> Return to Homepage </button>
</form> </form>
{% endblock %} {% 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