Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_group17
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
Vaughn Nephi Fajardo
widget_group17
Commits
f5660e23
Commit
f5660e23
authored
May 04, 2022
by
Miguel Luis D. Bandelaria
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: added template for post listing.
parent
831c6c45
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
59 deletions
+69
-59
views.cpython-39.pyc
widget_group_17/forum/__pycache__/views.cpython-39.pyc
+0
-0
index.html
widget_group_17/forum/templates/forum/index.html
+9
-0
views.py
widget_group_17/forum/views.py
+60
-59
No files found.
widget_group_17/forum/__pycache__/views.cpython-39.pyc
View file @
f5660e23
No preview for this file type
widget_group_17/forum/templates/forum/index.html
0 → 100644
View file @
f5660e23
{% if posts_list %}
<ul>
{% for post in posts_list %}
<li><a
href=
"/posts/{{ post.id }}"
>
{{ posts.post_title }}
</a></li>
{% endfor %}
</ul>
{% else %}
<p>
No articles are available.
</p>
{% endif %}
\ No newline at end of file
widget_group_17/forum/views.py
View file @
f5660e23
...
...
@@ -5,78 +5,79 @@ from .models import Post, Reply
# Create your views here.
def
index
(
request
):
posts_list
=
Post
.
objects
.
order_by
(
"pub_date"
)
output
=
", "
.
join
([
p
.
post_title
for
p
in
posts_list
])
return
HttpResponse
(
output
)
output
=
"<br>"
.
join
([
p
.
post_title
for
p
in
posts_list
])
view
=
"Welcome to Widget's Forum! <br>"
+
output
return
HttpResponse
(
view
)
# return HttpResponse("Welcome to Widget's forum!")
def
welcome
(
request
):
forum_view
=
"FORUM POSTS: "
# posts = Post.objects.all()
# replies = Reply.objects.all()
#
def welcome(request):
#
forum_view = "FORUM POSTS: "
#
# posts = Post.objects.all()
#
# replies = Reply.objects.all()
forum_view
=
forum_view
+
"<br> {} by {} {} dated {}: <br> {}"
.
\
format
(
Post
.
objects
.
get
(
author_id
=
1
),
Post
.
objects
.
get
(
author_id
=
1
)
.
author
.
first_name
,
Post
.
objects
.
get
(
author_id
=
1
)
.
author
.
last_name
,
Post
.
objects
.
get
(
author_id
=
1
)
.
pub_date
,
Post
.
objects
.
get
(
author_id
=
1
)
.
post_body
)
#
forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
#
format(
#
Post.objects.get(author_id=1),
#
Post.objects.get(author_id=1).author.first_name,
#
Post.objects.get(author_id=1).author.last_name,
#
Post.objects.get(author_id=1).pub_date,
#
Post.objects.get(author_id=1).post_body
#
)
replies_to_first
=
Reply
.
objects
.
filter
(
associated_post_id
=
2
)
#
replies_to_first = Reply.objects.filter(associated_post_id=2)
for
reply_to_first
in
replies_to_first
:
forum_view
=
forum_view
+
'<br> Reply by {} {} dated {}: <br> {}'
.
\
format
(
reply_to_first
.
author
.
first_name
,
reply_to_first
.
author
.
last_name
,
reply_to_first
.
pub_date
,
reply_to_first
.
reply_body
)
#
for reply_to_first in replies_to_first:
#
forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
#
format(
#
reply_to_first.author.first_name,
#
reply_to_first.author.last_name,
#
reply_to_first.pub_date,
#
reply_to_first.reply_body
#
)
forum_view
=
forum_view
+
"<br>"
#
forum_view = forum_view + "<br>"
forum_view
=
forum_view
+
"<br> {} by {} {} dated {}: <br> {}"
.
\
format
(
Post
.
objects
.
get
(
author_id
=
2
),
Post
.
objects
.
get
(
author_id
=
2
)
.
author
.
first_name
,
Post
.
objects
.
get
(
author_id
=
2
)
.
author
.
last_name
,
Post
.
objects
.
get
(
author_id
=
2
)
.
pub_date
,
Post
.
objects
.
get
(
author_id
=
2
)
.
post_body
)
#
forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
#
format(
#
Post.objects.get(author_id=2),
#
Post.objects.get(author_id=2).author.first_name,
#
Post.objects.get(author_id=2).author.last_name,
#
Post.objects.get(author_id=2).pub_date,
#
Post.objects.get(author_id=2).post_body
#
)
replies_to_second
=
Reply
.
objects
.
filter
(
associated_post_id
=
3
)
#
replies_to_second = Reply.objects.filter(associated_post_id=3)
for
reply_to_second
in
replies_to_second
:
forum_view
=
forum_view
+
'<br> Reply by {} {} dated {}: <br> {}'
.
\
format
(
reply_to_second
.
author
.
first_name
,
reply_to_second
.
author
.
last_name
,
reply_to_second
.
pub_date
,
reply_to_second
.
reply_body
)
#
for reply_to_second in replies_to_second:
#
forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
#
format(
#
reply_to_second.author.first_name,
#
reply_to_second.author.last_name,
#
reply_to_second.pub_date,
#
reply_to_second.reply_body
#
)
forum_view
=
forum_view
+
"<br>"
#
forum_view = forum_view + "<br>"
forum_view
=
forum_view
+
"<br> {} by {} {} dated {}: <br> {}"
.
\
format
(
Post
.
objects
.
get
(
id
=
4
),
Post
.
objects
.
get
(
id
=
4
)
.
author
.
first_name
,
Post
.
objects
.
get
(
id
=
4
)
.
author
.
last_name
,
Post
.
objects
.
get
(
id
=
4
)
.
pub_date
,
Post
.
objects
.
get
(
id
=
4
)
.
post_body
)
#
forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
#
format(
#
Post.objects.get(id=4),
#
Post.objects.get(id=4).author.first_name,
#
Post.objects.get(id=4).author.last_name,
#
Post.objects.get(id=4).pub_date,
#
Post.objects.get(id=4).post_body
#
)
replies_to_third
=
Reply
.
objects
.
filter
(
associated_post_id
=
4
)
#
replies_to_third = Reply.objects.filter(associated_post_id=4)
for
reply_to_third
in
replies_to_third
:
forum_view
=
forum_view
+
'<br> Reply by {} {} dated {}: <br> {}'
.
\
format
(
reply_to_third
.
author
.
first_name
,
reply_to_third
.
author
.
last_name
,
reply_to_third
.
pub_date
,
reply_to_third
.
reply_body
)
#
for reply_to_third in replies_to_third:
#
forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
#
format(
#
reply_to_third.author.first_name,
#
reply_to_third.author.last_name,
#
reply_to_third.pub_date,
#
reply_to_third.reply_body
#
)
# for post in posts:
# forum_view += "<br> {} by {} {} dated {}: <br> {}".\
...
...
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