Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_Francoconuts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Chester Tan
widget_Francoconuts
Commits
0108d3cb
Commit
0108d3cb
authored
Apr 03, 2022
by
Bryan Carlo Guanlao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated Announcement view
Announcement view now displays announcements and its reactions
parent
73953eaa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
models.py
widget_Francoconuts/announcements/models.py
+2
-2
views.py
widget_Francoconuts/announcements/views.py
+31
-2
No files found.
widget_Francoconuts/announcements/models.py
View file @
0108d3cb
...
@@ -29,5 +29,5 @@ class Reaction(models.Model):
...
@@ -29,5 +29,5 @@ class Reaction(models.Model):
)
)
tally
=
models
.
IntegerField
()
tally
=
models
.
IntegerField
()
def
_
str
_
(
self
):
def
_
_str_
_
(
self
):
return
'{}
: {}'
.
format
(
self
.
reaction_name
,
self
.
tally
)
return
'{}
'
.
format
(
self
.
reaction_name
)
widget_Francoconuts/announcements/views.py
View file @
0108d3cb
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
Http404
,
HttpRequest
,
HttpResponse
from
.models
import
Announcement
,
Reaction
,
WidgetUser
def
get_reactions
(
a
):
reaction
=
''
like
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
a
)
love
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Love'
,
announcement
=
a
)
hate
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Hate'
,
announcement
=
a
)
for
l
in
like
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
l
in
love
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
h
in
hate
:
reaction
+=
'{}: '
.
format
(
h
)
+
'{}'
.
format
(
h
.
tally
)
+
'<br>'
return
reaction
def
announcements
(
request
):
def
announcements
(
request
):
return
HttpResponse
(
"This is the Announcement Board!"
)
text
=
'ANNOUNCEMENTS:<br>'
for
announcement
in
Announcement
.
objects
.
all
():
text
+=
(
'{} '
.
format
(
announcement
)
+
'by {} {} '
.
format
(
announcement
.
author
.
first_name
,
announcement
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
announcement
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
announcement
.
announcement_body
)
+
get_reactions
(
announcement
)
+
'<br>'
)
return
HttpResponse
(
text
)
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