Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_Alipins
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
Angelico Ruiz T. Teaño
widget_Alipins
Commits
978ef983
Commit
978ef983
authored
Apr 03, 2022
by
Carlo Joseph Echon
🐟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed views in announcements to display all Announcements and Reactions
parent
18c5d09d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
views.py
widget_alipins/announcements/views.py
+24
-2
No files found.
widget_alipins/announcements/views.py
View file @
978ef983
from
django.http
import
HttpResponse
from
.models
import
Announcement
,
Reaction
# Create your views here.
def
index
(
request
):
return
HttpResponse
(
"This is the Announcement Board!"
)
\ No newline at end of file
return
HttpResponse
(
display_announcementboard
(
Announcement
.
objects
.
all
()))
def
display_announcementboard
(
announcement_data
):
display_output
=
"ANNOUNCEMENTS: <br>"
for
object
in
announcement_data
:
display_output
+=
'''
{title} by {first_name} {last_name} dated {date}:<br>
{body}<br>
Like: {like_tally}<br>
Love: {love_tally}<br>
Angry: {angry_tally}<br>
<br>
'''
.
format
(
title
=
object
.
announcement_title
,
first_name
=
object
.
author
.
first_name
,
last_name
=
object
.
author
.
last_name
,
date
=
str
(
object
.
pub_date
),
body
=
object
.
announcement_body
,
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
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