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
e521c58b
Commit
e521c58b
authored
May 12, 2023
by
Ysabella Panghulan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'announcementsv2'
parents
fcc9f836
92b62429
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
21 deletions
+128
-21
models.py
widget_princessgabi/announcementboard/models.py
+5
-1
announcement-add.html
...ntboard/templates/announcementboard/announcement-add.html
+13
-0
announcement-details.html
...ard/templates/announcementboard/announcement-details.html
+18
-0
announcement-edit.html
...tboard/templates/announcementboard/announcement-edit.html
+14
-0
announcements.html
...ementboard/templates/announcementboard/announcements.html
+28
-0
urls.py
widget_princessgabi/announcementboard/urls.py
+8
-1
views.py
widget_princessgabi/announcementboard/views.py
+42
-19
No files found.
widget_princessgabi/announcementboard/models.py
View file @
e521c58b
from
django.db
import
models
from
django.urls
import
reverse
from
dashboard.models
import
WidgetUser
...
...
@@ -6,10 +7,13 @@ class Announcement(models.Model):
title
=
models
.
CharField
(
max_length
=
50
)
body
=
models
.
TextField
(
max_length
=
700
,
null
=
True
,
blank
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
pub_datetime
=
models
.
DateTimeField
(
'publication date and time'
)
pub_datetime
=
models
.
DateTimeField
(
'publication date and time'
,
auto_now_add
=
True
)
def
__str__
(
self
):
return
self
.
title
def
get_absolute_url
(
self
):
return
reverse
(
'announcementboard:announcement-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reaction
(
models
.
Model
):
class
Choices
(
models
.
TextChoices
):
...
...
widget_princessgabi/announcementboard/templates/announcementboard/announcement-add.html
0 → 100644
View file @
e521c58b
{% extends 'base.html' %}
{% block title %} Add Announcement {% endblock %}
{% block header %}
<h1>
Add a new announcement:
</h1>
{% endblock %}
{% block body %}
<form
method=
'POST'
>
{% csrf_token %}
{{ form }}
<input
type=
"Submit"
value=
"Add Announcement"
>
</form>
{% endblock %}
\ No newline at end of file
widget_princessgabi/announcementboard/templates/announcementboard/announcement-details.html
0 → 100644
View file @
e521c58b
{% 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=
"{% url 'announcementboard:announcement-edit' announcement.id %}"
>
Edit Announcement
</a>
{% endblock %}
\ No newline at end of file
widget_princessgabi/announcementboard/templates/announcementboard/announcement-edit.html
0 → 100644
View file @
e521c58b
{% extends 'base.html' %}
{% block title %} Edit Announcement {% endblock %}
{% block header %}
<h1>
Edit announcement:
</h1>
{% endblock %}
{% block body %}
<form
method=
'POST'
>
{% csrf_token %}
{{ form }}
<input
type=
"Submit"
value=
"Save Changes to Announcement"
>
</form>
{% endblock %}
widget_princessgabi/announcementboard/templates/announcementboard/announcements.html
0 → 100644
View file @
e521c58b
{% extends 'base.html' %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block header %}
<h1>
Welcome to Widget's Announcement Board!
</h1>
{% endblock %}
{% block content %}
<h2>
Announcements:
</h2><br>
<div>
<ul>
{% for announcement in announcements %}
<li>
<a
href=
"{{ announcement.get_absolute_url }}"
>
{{ announcement.title }} by {{ announcement.author.first_name }} {{ announcement.author.last_name }}
</a>
</li>
{% endfor %}
</ul>
</div>
<div>
<a
href=
"/announcements/add/"
>
New Announcement
</a>
</div>
<a
href=
"/dashboard/"
>
Dashboard
</a>
<a
href=
"/forum/"
>
Forum
</a>
<a
href=
"/assignments/"
>
Assignments
</a>
<a
href=
"/calendar/"
>
Calendar
</a>
{% endblock %}
\ No newline at end of file
widget_princessgabi/announcementboard/urls.py
View file @
e521c58b
from
django.urls
import
path
from
.
import
views
from
.views
import
(
AnnouncementsDetailView
,
AnnouncementsUpdateView
,
AnnouncementsCreateView
)
urlpatterns
=
[
path
(
''
,
views
.
index
,
name
=
'index'
),
path
(
''
,
views
.
announcement_view
,
name
=
'announcements'
),
path
(
'<int:pk>/details/'
,
AnnouncementsDetailView
.
as_view
(),
name
=
'announcement-details'
),
path
(
'add/'
,
AnnouncementsCreateView
.
as_view
(),
name
=
'announcement-add'
),
path
(
'<int:pk>/edit/'
,
AnnouncementsUpdateView
.
as_view
(),
name
=
'announcement-edit'
),
]
app_name
=
'announcementboard'
\ No newline at end of file
widget_princessgabi/announcementboard/views.py
View file @
e521c58b
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Announcement
,
Reaction
def
index
(
request
):
all_announcements
=
Announcement
.
objects
.
all
()
all_reactions
=
Reaction
.
objects
.
all
()
welcomeMessage
=
'Widget
\'
s Announcement Board<br><br>Announcements:<br>'
response
=
''
for
announcement
in
all_announcements
:
reactions
=
''
reactions_list
=
{
'Like'
:
0
,
'Love'
:
0
,
'Angry'
:
0
}
for
reaction
in
all_reactions
:
if
reaction
.
announcement
.
title
==
announcement
.
title
:
reactions_list
[
reaction
.
name
]
=
reaction
.
tally
keys
=
list
(
reactions_list
.
keys
())
for
key
in
keys
:
reactions
+=
key
+
': '
+
str
(
reactions_list
[
key
])
+
'<br>'
datetime
=
announcement
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y,
%
I:
%
M
%
p'
)
author
=
announcement
.
author
.
first_name
+
' '
+
announcement
.
author
.
last_name
response
+=
announcement
.
title
+
' by '
+
author
+
' published '
+
datetime
response
+=
':'
+
'<br>'
+
announcement
.
body
+
'<br>'
+
reactions
+
'<br>'
return
HttpResponse
(
welcomeMessage
+
response
)
def
announcement_view
(
request
):
announcements
=
Announcement
.
objects
.
order_by
(
'-pub_datetime'
)
context
=
{
'announcements'
:
announcements
}
return
render
(
request
,
'announcementboard/announcements.html'
,
context
)
class
AnnouncementsCreateView
(
CreateView
):
model
=
Announcement
template_name
=
'announcementboard/announcement-add.html'
fields
=
'__all__'
class
AnnouncementsUpdateView
(
UpdateView
):
model
=
Announcement
template_name
=
'announcementboard/announcement-edit.html'
fields
=
'__all__'
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