Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_father when can i be on my own i have the hello world to see
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
father when can i be on my own i have the hello world to see
widget_father when can i be on my own i have the hello world to see
Commits
5d13d77d
Commit
5d13d77d
authored
May 19, 2022
by
Emilio Gentolia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed function to class view for announcements
parent
ad41407b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
views.py
announcement_board/views.py
+15
-25
No files found.
announcement_board/views.py
View file @
5d13d77d
from
django.http
import
HttpResponse
from
.models
import
Announcement
,
Reaction
from
django.shortcuts
import
render
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
.models
import
Announcement
# View for announcements page.
def
index
(
request
):
return
HttpResponse
(
display_announcementboard
(
Announcement
.
objects
.
all
(),
Reaction
.
objects
.
all
()))
def
display_announcementboard
(
announcement_data
,
reaction_data
):
display_output
=
"ANNOUNCEMENTS: <br>"
for
object
in
announcement_data
:
announcement_title
=
object
.
announcement_title
first_name
=
object
.
author
.
first_name
last_name
=
object
.
author
.
last_name
pub_date
=
str
(
object
.
pub_date
)
announcement_body
=
object
.
announcement_body
like_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Like"
)
.
first
()
.
tally
love_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Love"
)
.
first
()
.
tally
angry_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Angry"
)
.
first
()
.
tally
display_output
+=
f
'''
{announcement_title} by {first_name} {last_name} dated {pub_date}:<br>
{announcement_body}<br>
Like: {like_count}<br>
Love: {love_count}<br>
Angry: {angry_count}<br>
<br>
'''
return
display_output
class
AnnouncementView
(
View
):
def
get
(
self
,
request
):
objects_set
=
{
"all_announcements"
:
[
obj
for
obj
in
Announcement
.
objects
.
all
()
.
order_by
(
'last_name'
)]
}
return
render
(
request
,
'homepage/index.html'
,
objects_set
)
class
AnnouncementDetailView
(
DetailView
):
model
=
Announcement
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