Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_jupert
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joseph Izon
widget_jupert
Commits
61e5d9da
Commit
61e5d9da
authored
May 27, 2022
by
Ronan Phillippe B. Artuz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new announcement view and change index view to obv
parent
0a9fa98c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
31 deletions
+45
-31
views.py
widget_jupert/forum/views.py
+45
-31
No files found.
widget_jupert/forum/views.py
View file @
61e5d9da
from
urllib
import
response
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
forum.models
import
Post
from
forum.models
import
Reply
from
.forms
import
PostForm
# Create your views here.
def
index
(
request
):
post_list
=
Post
.
objects
.
order_by
(
"pub_date"
)
context
=
{
"post_list"
:
post_list
}
return
render
(
request
,
"forum/index.html"
,
context
)
class
IndexView
(
View
):
def
get
(
self
,
request
):
post_list
=
Post
.
objects
.
order_by
(
"pub_date"
)
context
=
{
"post_list"
:
post_list
}
return
render
(
request
,
"forum/index.html"
,
context
)
def
details
(
request
,
post_id
):
reply_list
=
Reply
.
objects
.
order_by
(
"pub_date"
)
#error handling
#error handling
try
:
posts
=
Post
.
objects
.
get
(
pk
=
post_id
)
except
Post
.
DoesNotExist
:
raise
Http404
(
"Post does not exist."
)
return
render
(
request
,
"forum/details.html"
,
{
"posts"
:
posts
,
'reply_list'
:
reply_list
})
"""post_objects = Post.objects.all()
reply_objects = Reply.objects.all()
response = "FORUM POSTS:"
for post in post_objects:
response = (response + f"<br> {post.post_title} by "
+ f"{post.author.first_name} {post.author.last_name} "
+ f"dated {post.pub_date.date()}:<br> {post.post_body} <br>")
for reply in reply_objects:
if(reply.post.post_title==post.post_title):
response = (response + "Reply by "
+ f"{reply.author.first_name} {reply.author.last_name} "
+ f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>")
return HttpResponse(response)"""
\ No newline at end of file
def
add
(
request
):
if
request
.
method
==
"POST"
:
post_form
=
PostForm
(
request
.
POST
,
request
.
FILES
)
if
post_form
.
is_valid
():
post_form
.
save
()
return
redirect
(
"forum:add"
)
else
:
post_form
=
PostForm
()
return
render
(
request
,
"forum/add.html"
,
{
"post_form"
:
post_form
})
"""post_objects = Post.objects.all()
reply_objects = Reply.objects.all()
response = "FORUM POSTS:"
for post in post_objects:
response = (response + f"<br> {post.post_title} by "
+ f"{post.author.first_name} {post.author.last_name} "
+ f"dated {post.pub_date.date()}:<br> {post.post_body} <br>")
for reply in reply_objects:
if(reply.post.post_title==post.post_title):
response = (response + "Reply by "
+ f"{reply.author.first_name} {reply.author.last_name} "
+ f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>")
return HttpResponse(response)"""
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment