Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_princessgabi
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
Ysabella Panghulan
midterm_princessgabi
Commits
8aa8eb3c
Commit
8aa8eb3c
authored
May 09, 2023
by
Julia Anishka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated views, url and created template for announcement details
parent
37a62fde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
announcement-details.html
...ard/templates/announcementboard/announcement-details.html
+19
-0
urls.py
widget_princessgabi/announcementboard/urls.py
+5
-3
views.py
widget_princessgabi/announcementboard/views.py
+24
-1
No files found.
widget_princessgabi/announcementboard/templates/announcementboard/announcement-details.html
0 → 100644
View file @
8aa8eb3c
{% extends 'base.html' %}
{% block title %} {{ announcement.title }} {% endblock %}
{% block header %}
<h1>
{{ announcement.title }}
</h1>
{% endblock %}
{% block body %}
<h4>
by {{ announcement.author.first_name }} {{ announcement.author.last_name }}
</h4>
<h4>
{{ announcement.pub_datetime|date:'m/d/Y, H:i A'}}
</h4>
<h4>
{{ announcement.body }}
</h4>
<ul>
<li>
Like: {{ tallies.like|default:0 }}
</li>
<li>
Love: {{ tallies.love|default:0 }}
</li>
<li>
Angry: {{ tallies.angry|default:0 }}
</li>
</ul>
<a
href=
"{{ announcement.get_absolute_url }}edit"
>
Edit Announcement
</a>
{% endblock %}
\ No newline at end of file
widget_princessgabi/announcementboard/urls.py
View file @
8aa8eb3c
from
django.urls
import
path
from
django.urls
import
path
from
.
import
views
from
.
import
views
from
.views
import
(
Announcements
CreateView
,
AnnouncementsUpdateView
,
from
.views
import
(
Announcements
DetailView
,
AnnouncementsUpdateView
,
AnnouncementsCreateView
)
)
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
views
.
announcement_view
,
name
=
'announcements'
),
path
(
''
,
views
.
announcement_view
,
name
=
'announcements'
),
path
(
'announcements/<int:pk>/details/'
,
AnnouncementsDetailView
.
as_view
(),
name
=
'announcement-details'
),
path
(
'announcements/add/'
,
AnnouncementsCreateView
.
as_view
(),
name
=
'announcement-add'
),
path
(
'announcements/add/'
,
AnnouncementsCreateView
.
as_view
(),
name
=
'announcement-add'
),
path
(
'announcements/<int:pk>/details/edit/'
,
AnnouncementsUpdateView
.
as_view
(),
name
=
'announcement-edit'
),
path
(
'announcements/<int:pk>/details/edit/'
,
AnnouncementsUpdateView
.
as_view
(),
name
=
'announcement-edit'
)
]
]
app_name
=
'announcementboard'
\ No newline at end of file
widget_princessgabi/announcementboard/views.py
View file @
8aa8eb3c
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Announcement
,
Reaction
from
.models
import
Announcement
,
Reaction
...
@@ -20,4 +21,26 @@ class AnnouncementsCreateView(CreateView):
...
@@ -20,4 +21,26 @@ class AnnouncementsCreateView(CreateView):
class
AnnouncementsUpdateView
(
UpdateView
):
class
AnnouncementsUpdateView
(
UpdateView
):
model
=
Announcement
model
=
Announcement
template_name
=
'announcementboard/announcement-edit.html'
template_name
=
'announcementboard/announcement-edit.html'
fields
=
'__all__'
fields
=
'__all__'
\ No newline at end of file
class
AnnouncementsDetailView
(
DetailView
):
model
=
Announcement
template_name
=
'announcementboard/announcement-details.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
reactions
=
Reaction
.
objects
.
filter
(
announcement
=
self
.
object
)
tallies
=
{
'like'
:
0
,
'love'
:
0
,
'angry'
:
0
}
for
reaction
in
reactions
:
if
reaction
.
name
==
'Like'
:
tallies
[
'like'
]
+=
reaction
.
tally
elif
reaction
.
name
==
'Love'
:
tallies
[
'love'
]
+=
reaction
.
tally
elif
reaction
.
name
==
'Angry'
:
tallies
[
'angry'
]
+=
reaction
.
tally
context
[
'tallies'
]
=
tallies
return
context
\ 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