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
0ebf8de9
Commit
0ebf8de9
authored
May 12, 2023
by
justin
Browse files
Options
Browse Files
Download
Plain Diff
staging: merged announcement board
parents
e88e23d6
2b522e43
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
29 deletions
+137
-29
models.py
widget_casanatics/announcement_board/models.py
+6
-1
announcement-add.html
..._board/templates/announcement_board/announcement-add.html
+21
-0
announcement-details.html
...rd/templates/announcement_board/announcement-details.html
+30
-0
announcement-edit.html
...board/templates/announcement_board/announcement-edit.html
+21
-0
announcements.html
...ent_board/templates/announcement_board/announcements.html
+30
-0
urls.py
widget_casanatics/announcement_board/urls.py
+10
-0
views.py
widget_casanatics/announcement_board/views.py
+19
-28
No files found.
widget_casanatics/announcement_board/models.py
View file @
0ebf8de9
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
class
Announcement
(
models
.
Model
):
...
...
@@ -14,12 +15,16 @@ class Announcement(models.Model):
def
__str__
(
self
):
return
self
.
title
# get corresponding detail page
def
get_absolute_url
(
self
):
return
(
reverse
(
'announcement_board:announcementdetail'
,
kwargs
=
{
'pk'
:
self
.
pk
}))
class
Reaction
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
tally
=
models
.
IntegerField
(
default
=
0
)
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
)
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
,
related_name
=
'reactlist'
)
def
__str__
(
self
):
return
self
.
name
widget_casanatics/announcement_board/templates/announcement_board/announcement-add.html
0 → 100644
View file @
0ebf8de9
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Announcement {% endblock %}
{% block content %}
<h1>
Add a new announcement:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{# iterate through fields in the form #}
{% for field in form%}
<b>
{{ field.label }}:
</b>
{{ field }}
<br><br>
{% endfor %}
<button
type=
"submit"
>
Add Announcement
</button>
</form>
{% endblock %}
\ No newline at end of file
widget_casanatics/announcement_board/templates/announcement_board/announcement-details.html
0 → 100644
View file @
0ebf8de9
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
{# announcement title #}
<h1>
{{ object.title }}
</h1>
{# announcement author using displayName method in model #}
<h2>
by {{ object.author.displayName }}
</h2>
{# format datetime with tags #}
<h3>
{{ object.pub_datetime|date:"m/d/Y, h:i A" }}
</h3>
{# announcement body #}
<p>
{{ object.body }}
</p>
<br>
{# iterate through reactions, show name: tally #}
Reactions:
<ul>
{% for reaction in object.reactlist.all %}
<li>
<b>
{{ reaction.name}}:
</b>
{{ reaction.tally }}
</li>
{% endfor %}
</ul>
<form
action=
"../edit"
>
<button
type=
"Submit"
>
Edit Announcement
</button>
</form>
{% endblock %}
\ No newline at end of file
widget_casanatics/announcement_board/templates/announcement_board/announcement-edit.html
0 → 100644
View file @
0ebf8de9
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<h1>
Edit announcement:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{# iterate through fields #}
{% for field in form%}
<b>
{{ field.label }}:
</b>
{{ field }}
<br><br>
{% endfor %}
<button
type=
"submit"
>
Save Changes to Announcement
</button>
</form>
{% endblock %}
\ No newline at end of file
widget_casanatics/announcement_board/templates/announcement_board/announcements.html
0 → 100644
View file @
0ebf8de9
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block content %}
<h1>
Welcome to Widget's Announcement Board!
</h1>
<h2>
Announcements:
</h2>
{# iterate through announcement_list from context, use get url function to link to detail page #}
<ul>
{% for announcement in announcement_list %}
<li><a
href=
"{{ announcement.get_absolute_url }}"
>
{{ announcement.title }} by {{ announcement.author.displayName }}
</a></li>
{% endfor %}
</ul>
<br>
<form
action=
"./add"
>
<button
type=
"Submit"
>
New Announcement
</button>
</form>
<br>
<a
href=
"../dashboard/"
>
Dashboard
</a>
<br>
<a
href=
"../forum/"
>
Forum
</a>
<br>
<a
href=
"../assignments/"
>
Assignments
</a>
<br>
<a
href=
"../calendar/"
>
Calendar
</a>
<br>
{% endblock %}
\ No newline at end of file
widget_casanatics/announcement_board/urls.py
View file @
0ebf8de9
...
...
@@ -2,7 +2,17 @@ from django.urls import path
from
.
import
views
urlpatterns
=
[
# main page listing announcements
path
(
""
,
views
.
announcements
,
name
=
"announcements"
),
# detail page for each announcement
path
(
"<int:pk>/details/"
,
views
.
AnnouncementDetailView
.
as_view
(),
name
=
"announcementdetail"
),
# create page
path
(
"add/"
,
views
.
AnnouncementCreateView
.
as_view
(),
name
=
"announcementadd"
),
# edit page for each announcement
path
(
"<int:pk>/edit/"
,
views
.
AnnouncementUpdateView
.
as_view
(),
name
=
"announcementupdate"
),
]
...
...
widget_casanatics/announcement_board/views.py
View file @
0ebf8de9
...
...
@@ -2,38 +2,29 @@ from django.http import HttpResponse
from
.models
import
Announcement
,
Reaction
from
datetime
import
datetime
from
django.utils
import
timezone
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.shortcuts
import
render
def
announcements
(
request
):
# retrieve all announcement entries in a list
announcementList
=
Announcement
.
objects
.
all
()
# build response string
response
=
"Widget's Announcement Board <br><br>"
+
"Announcements:"
for
announcement
in
announcementList
:
# timezone conversion and string formatting for date-time
localdatetime
=
timezone
.
localtime
(
announcement
.
pub_datetime
)
datetime
=
localdatetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
# list of reactions for announcement
reactions
=
announcement
.
reaction_set
.
all
()
# use context to pass announcements sorted by pubdate
context
=
{
"announcement_list"
:
Announcement
.
objects
.
all
()
.
order_by
(
'-pub_datetime'
),
}
# response proper
response
=
(
response
+
"<br>"
+
announcement
.
title
+
" by "
+
announcement
.
author
.
displayName
()
+
" published "
+
datetime
+
": <br>"
)
return
render
(
request
,
'announcement_board/announcements.html'
,
context
)
response
=
response
+
announcement
.
body
+
"<br>"
class
AnnouncementDetailView
(
DetailView
):
model
=
Announcement
template_name
=
'announcement_board/announcement-details.html'
# for each reaction, add line with reaction and tally
for
reaction
in
reactions
:
response
=
response
+
reaction
.
name
+
": "
+
str
(
reaction
.
tally
)
+
"<br>"
class
AnnouncementCreateView
(
CreateView
):
model
=
Announcement
template_name
=
'announcement_board/announcement-add.html'
fields
=
[
'title'
,
'body'
,
'author'
]
return
HttpResponse
(
response
)
class
AnnouncementUpdateView
(
UpdateView
):
model
=
Announcement
template_name
=
'announcement_board/announcement-edit.html'
fields
=
[
'title'
,
'body'
,
'author'
]
\ 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