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
b1973695
Commit
b1973695
authored
May 18, 2022
by
Bryan Carlo Guanlao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated announcement views
added listview and detailview along with templates
parent
fe23067f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
30 deletions
+60
-30
announcement_detail.html
...ncements/templates/announcements/announcement_detail.html
+35
-0
announcement_list.html
...ouncements/templates/announcements/announcement_list.html
+14
-0
urls.py
widget_Francoconuts/announcements/urls.py
+4
-2
views.py
widget_Francoconuts/announcements/views.py
+7
-28
tsukasa.png
widget_Francoconuts/static/announcements/tsukasa.png
+0
-0
No files found.
widget_Francoconuts/announcements/templates/announcements/announcement_detail.html
0 → 100644
View file @
b1973695
<h1>
{{object.announcement_title}}
</h1>
<h3>
by {{announcement.author.first_name}} {{announcement.author.last_name}} dated
{{announcement.pub_date|date:"d/m/Y"}}
</h3>
<body>
{{object.announcement_body}}
<br><br>
</body>
<body>
{% if object.reaction.all %}
Reactions:
{% for reaction in object.reaction.all %}
{% if reaction.reaction_name == "Like" %}
<li>
{{reaction}}: {{reaction.tally}}
</li>
{% endif %}
{% endfor %}
{% for reaction in object.reaction.all %}
{% if reaction.reaction_name == "Love" %}
<li>
{{reaction}}: {{reaction.tally}}
</li>
{% endif %}
{% endfor %}
{% for reaction in object.reaction.all %}
{% if reaction.reaction_name == "Angry" %}
<li>
{{reaction}}: {{reaction.tally}}
</li>
{% endif %}
{% endfor %}
{% endif %}
{% load static %}
<img
src=
"{% static 'announcements/tsukasa.png' %}"
alt=
"image"
>
</body>
\ No newline at end of file
widget_Francoconuts/announcements/templates/announcements/announcement_list.html
0 → 100644
View file @
b1973695
{% extends 'base.html' %}
{% block content %}
<h1>
Announcements
</h1>
<ul>
{% for announcement in object_list %}
<li>
<a
href=
"{% url 'announcements:announcement-detail' announcement.id %}"
>
{{announcement.announcement_title}} by
{{announcement.author.first_name}} {{announcement.author.last_name}} dated
{{announcement.pub_date|date:"d/m/Y"}}
</a>
</li>
{% endfor %}
</ul>
{% endblock content %}
\ No newline at end of file
widget_Francoconuts/announcements/urls.py
View file @
b1973695
from
django.urls
import
path
from
.views
import
announcements
from
.views
import
AnnouncementsDetailView
,
AnnouncementsListView
urlpatterns
=
[
path
(
''
,
announcements
,
name
=
'announcements'
),
path
(
''
,
AnnouncementsListView
.
as_view
(),
name
=
'announcement-list'
),
path
(
'<int:pk>/details/'
,
AnnouncementsDetailView
.
as_view
(),
name
=
'announcement-detail'
),
]
app_name
=
'announcements'
widget_Francoconuts/announcements/views.py
View file @
b1973695
from
django.shortcuts
import
render
from
django.http
import
Http404
,
HttpRequest
,
HttpResponse
from
.models
import
Announcement
,
Reaction
,
WidgetUser
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
def
get_reactions
(
a
):
reaction
=
''
like
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
a
)
love
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Love'
,
announcement
=
a
)
angry
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Angry'
,
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
a
in
angry
:
reaction
+=
'{}: '
.
format
(
a
)
+
'{}'
.
format
(
a
.
tally
)
+
'<br>'
class
AnnouncementsListView
(
ListView
):
model
=
Announcement
ordering
=
[
"-pub_date"
]
return
reaction
def
announcements
(
request
):
text
=
'<h1>ANNOUNCEMENTS:</h1>'
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
)
class
AnnouncementsDetailView
(
DetailView
):
model
=
Announcement
widget_Francoconuts/static/announcements/tsukasa.png
0 → 100644
View file @
b1973695
41.2 KB
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