Changed HttpResponse format for views of each app

parent e1c09fa9
from django.http import HttpResponse
from .models import Announcement, Reaction
# Create your views here.
def index(request):
return HttpResponse(display_announcementboard(Announcement.objects.all()))
def display_announcementboard(announcement_data):
display_output = "<u><b>ANNOUNCEMENTS</u></b>: <br>"
for object in announcement_data:
for object in Announcement.objects.all():
display_output += '''
<b>{title} by {first_name} {last_name}</b> dated {date}:<br>
{body}<br>
......@@ -22,6 +21,5 @@ def display_announcementboard(announcement_data):
like_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Like").first().tally,
love_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Love").first().tally,
angry_tally = Reaction.objects.filter(announcement_id=object.id).filter(reaction_name="Angry").first().tally)
return display_output
return HttpResponse(display_output)
from django.http import HttpResponse
from .models import Assignment
# Create your views here.
def index(request):
return HttpResponse(display_assignments(Assignment.objects.all()))
def display_assignments(data_set_assignment):
display_output = "<u><b>ASSIGNMENTS</u></b>: <br>"
for object in data_set_assignment:
for object in Assignment.objects.all():
display_output += '''
Assignment Name: <b>{name}</b><br>
Description: {description}<br>
......@@ -23,5 +19,5 @@ def display_assignments(data_set_assignment):
course_code = object.course.course_code,
course_title = object.course.course_title,
section = object.course.section)
return display_output
\ No newline at end of file
return HttpResponse(display_output)
......@@ -3,12 +3,9 @@ from .models import Post, Reply
# Create your views here.
def index(request):
return HttpResponse(display_forum(Post.objects.all()))
def display_forum(post_data):
display_output = "<u><b>FORUM POSTS</u></b>:<br>"
for post in post_data:
for post in Post.objects.all():
display_output += f"<b>{post.post_title} by {post.author.first_name} {post.author.last_name}</b> dated {str(post.pub_date)}:\
<br>{post.post_body}"
replies = Reply.objects.filter(post=post)
......@@ -17,5 +14,6 @@ def display_forum(post_data):
<br>{reply.reply_body}"
display_output += "<br><br>"
return display_output
return HttpResponse(display_output)
\ No newline at end of file
......@@ -3,12 +3,9 @@ from django.http import HttpResponse
from .models import WidgetUser
def index(request):
return HttpResponse(display_users(WidgetUser.objects.all()))
def display_users(data_list):
display_output = "<u><b>WIDGET USERS</u></b>: <br>"
for objects in data_list:
for objects in WidgetUser.objects.all():
display_output += '''
<b>{last_name}, {first_name} {middle_name}</b>: {id}, {email}, {dept}, {home}<br>
'''.format(last_name = objects.last_name,
......@@ -18,5 +15,5 @@ def display_users(data_list):
email = objects.email,
dept = objects.department.dept_name,
home = objects.department.home_unit)
return display_output
\ No newline at end of file
return HttpResponse(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