Changed HttpResponse format for views of each app

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