Commit a4e83b42 authored by Isaiah Flores's avatar Isaiah Flores

Update widget_group3/widget_group3/views.py

parent fe94ab32
from django.http import HttpResponse
from .models import WidgetUser, Post, Reply, Announcement, Assignment, Department from .models import WidgetUser, Post, Reply, Announcement, Assignment, Department
def homepage(request): def homepage(request):
widget_users = WidgetUser.objects.all() widget_users = WidgetUser.objects.all()
output = "WIDGET USERS:\n" + "\n".join([str(user) for user in widget_users]) departments = Department.objects.all()
output = "WIDGET USERS:\n" + "\n".join(
['{}: {}, {}, {}'.format(str(user.full_name),
str(user.id_num),
str(user.email),
str(user.department))
for user in widget_users]
)
return HttpResponse(output, content_type="text/plain") return HttpResponse(output, content_type="text/plain")
def assignments(request): def assignments(request):
...@@ -18,6 +25,7 @@ def forum(request): ...@@ -18,6 +25,7 @@ def forum(request):
output = "FORUM POSTS:<br>" + "<br>".join([str(x) for x in post]) + "<br>".join([str(z) for z in reply]) output = "FORUM POSTS:<br>" + "<br>".join([str(x) for x in post]) + "<br>".join([str(z) for z in reply])
return HttpResponse(output, content_type="text/plain") return HttpResponse(output, content_type="text/plain")
# If the above code doesn't work please use this one below
# def forum(request): # def forum(request):
# post = Post.objects.all() # post = Post.objects.all()
# reply = Reply.objects.all() # reply = Reply.objects.all()
...@@ -25,9 +33,33 @@ def forum(request): ...@@ -25,9 +33,33 @@ def forum(request):
# replies = "" # replies = ""
# for x in post: # for x in post:
# posts += '<br>{} by {} dated {}:<br> {}'.format(x.post_title, x.author.full_name(), x.pub_date, x.post_body) # posts += '<br>{} by {} dated {}:<br> {}'.format(str(x.post_title), str(x.author.full_name()), str(x.pub_date), str(x.post_body))
# for y in reply: # for y in reply:
# replies += '<br>Reply by {} dated {}:<br> {}'.format(y.author.full_name(), y.pub_date, y.reply_body) # replies += '<br>Reply by {} dated {}:<br> {}'.format(str(y.author.full_name()), str(y.pub_date), str(y.reply_body))
# output = "FORUM POSTS:" + posts + replies # output = "FORUM POSTS:" + posts + replies
# return HttpResponse(output, content_type="text/plain")
# If the above code doesn't work again please use this one instead
# def forum(request):
# forum_posts = Post.objects.all()
# forum_replies = Reply.objects.all()
# output1 = "FORUM POSTS:<br>" + "<br>".join(
# ['{} by {} dated {}:<br> {}'.format(str(post.post_title),
# str(post.author.full_name()),
# str(post.pub_date),
# str(post.post_body))
# for post in forum_posts]
# )
# output2 = "<br>".join(
# ['<br>Reply by {} dated {}:<br> {}'.format(str(reply.author.full_name()),
# str(reply.pub_date),
# str(reply.reply_body))
# for reply in forum_replies]
# )
# output = output1+output2
# return HttpResponse(output, content_type="text/plain") # return HttpResponse(output, content_type="text/plain")
\ 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