Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_casanatics
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
John Aidan Vincent M. Ng
midterm_casanatics
Commits
36825a81
Commit
36825a81
authored
Mar 04, 2023
by
justin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed view (formatting datetime and casting str to reaction.tally)
parent
f38b8c23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
views.py
widget_casanatics/announcement_board/views.py
+17
-6
No files found.
widget_casanatics/announcement_board/views.py
View file @
36825a81
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
Announcement
,
Reaction
from
.models
import
Announcement
,
Reaction
from
datetime
import
datetime
# Create your views here.
def
announcements
(
request
):
def
announcements
(
request
):
# retrieve all announcement entries in a list
# retrieve all announcement entries in a list
announcementList
=
Announcement
.
objects
.
all
()
announcementList
=
Announcement
.
objects
.
all
()
# build response string
# build response string
response
=
"Widget's Announcement Board <br>"
+
"Announcements:"
response
=
"Widget's Announcement Board <br>
<br>
"
+
"Announcements:"
for
announcement
in
announcementList
:
for
announcement
in
announcementList
:
# string formatting for date-time
# string formatting for date-time
datetime
=
announcement
.
pub_datetime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
datetime
=
announcement
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
# list of reactions for announcement
# list of reactions for announcement
reactions
=
announcement
.
reaction_set
.
all
()
reactions
=
announcement
.
reaction_set
.
all
()
# response proper
# response proper
response
=
response
+
"<br>"
+
announcement
.
name
+
" by "
+
announcement
.
author
+
" published "
+
datetime
+
": <br>"
response
=
(
response
+
"<br>"
+
announcement
.
title
+
" by "
+
announcement
.
author
.
displayName
()
+
" published "
+
datetime
+
": <br>"
)
response
=
response
+
announcement
.
body
+
"<br>"
response
=
response
+
announcement
.
body
+
"<br>"
# for each reaction, add line with reaction and tally
# for each reaction, add line with reaction and tally
for
reaction
in
reactions
:
for
reaction
in
reactions
:
response
=
response
+
reaction
.
name
+
": "
+
reaction
.
tally
+
"<br>"
response
=
response
+
reaction
.
name
+
": "
+
str
(
reaction
.
tally
)
+
"<br>"
return
HttpResponse
(
response
)
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