Commit 521cdd5e authored by Charles Lim's avatar Charles Lim

Switched from HTML Template back to Httpresponse

parent 777b3744
<html>
<head>
<title>Homepage</title>
</head>
WIDGET USERS: <br>
{% for user in all_widgetusers %}
{{user.last_name}}, {{user.first_name}} {{user.middle_name}}: {{user.id_num}},
{{user.department.dept_name}}, {{user.department.home_unit}} </br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import homepage_view
from .views import index
urlpatterns = [ urlpatterns = [
path('', homepage_view, name='homepage_view'), path('', index, name='index'),
] ]
app_name = "homepage" app_name = "homepage"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from .models import WidgetUser
from forum.views import display_forumposts
from .models import WidgetUser, Department
from django.http import HttpResponse
def index(request):
return HttpResponse(display_homepage(WidgetUser.objects.all(), Department.objects.all()))
# View for HomePage # View for HomePage
def homepage_view(request): def display_homepage(widgetuser_data, department_data):
objects_set = { display_output = "WIDGET USERS: <br>"
"all_widgetusers": [obj for obj in WidgetUser.objects.all()]
} for object in widgetuser_data:
print(objects_set["all_widgetusers"][0].__dict__) first_name = object.first_name
return render(request, "homepage_template.html", objects_set) middle_name = object.middle_name
last_name = object.last_name
id_num = object.id_num
department_object = Department.objects.filter(id=object.department_id).first()
if (department_object != None):
dept_name = department_object.dept_name
home_unit = department_object.home_unit
else:
dept_name = "NONE"
home_unit = "NONE"
display_output += f'''
{last_name}, {first_name} {middle_name}: {id_num}, {dept_name}, {home_unit}<br>
'''
return display_output
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