Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_appappandaway
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
Ian Rafael T. Aragoza
midterm_appappandaway
Commits
cf47e2da
Commit
cf47e2da
authored
May 15, 2023
by
iyamiks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated models, urls, and views
parent
1a47773a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
33 deletions
+58
-33
models.py
widget_appappandaway/announcementboard/models.py
+35
-3
urls.py
widget_appappandaway/announcementboard/urls.py
+5
-3
views.py
widget_appappandaway/announcementboard/views.py
+18
-27
No files found.
widget_appappandaway/announcementboard/models.py
View file @
cf47e2da
...
...
@@ -2,6 +2,8 @@ from django.db import models
from
django.urls
import
reverse
from
django.utils
import
timezone
from
dashboard.models
import
WidgetUser
...
...
@@ -12,10 +14,40 @@ class Announcement(models.Model):
pub_datetime
=
models
.
DateTimeField
(
verbose_name
=
"Posted On"
,
auto_now_add
=
True
)
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
title
)
return
'{} by {} {} on {}'
.
format
(
self
.
title
,
self
.
author
.
first_name
,
self
.
author
.
last_name
,
self
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y
%
I:
%
M
%
p"
),
self
.
body
)
def
getLikeReacts
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Like"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
getLoveReacts
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Love"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
getAngryReacts
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Angry"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
getFormattedDateTime
(
self
):
return
'{}'
.
format
(
self
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y
%
I:
%
M
%
p"
))
def
get_absolute_url
(
self
):
return
reverse
(
'announcement_detail'
,
args
=
[
str
(
self
.
title
)])
return
reverse
(
'announcements:announcement-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reaction
(
models
.
Model
):
...
...
widget_appappandaway/announcementboard/urls.py
View file @
cf47e2da
from
django.shortcuts
import
render
from
django.urls
import
path
from
.views
import
index
from
.views
import
announcements
,
AnnouncementDetailView
,
AnnouncementCreateView
,
AnnouncementUpdateView
# Create your views here.
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
announcements
,
name
=
'announcements'
),
path
(
'<int:pk>/details/'
,
AnnouncementDetailView
.
as_view
(),
name
=
'announcement-details'
),
path
(
'add/'
,
AnnouncementCreateView
.
as_view
(),
name
=
'announcement-add'
),
path
(
'<int:pk>/edit/'
,
AnnouncementUpdateView
.
as_view
(),
name
=
'announcement-edit'
),
]
app_name
=
"announcementboard"
widget_appappandaway/announcementboard/views.py
View file @
cf47e2da
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Announcement
,
Reaction
from
.models
import
Announcement
# Create your views here.
def
index
(
request
):
output
=
"<h1><b> Widget's Announcement Board </b></h1><h3>Announcements:</h3>"
for
announcement
in
Announcement
.
objects
.
order_by
(
'-pub_datetime'
):
output
+=
'<b>{}</b> by {} {} published {}:<br> {} <br>'
.
format
(
announcement
.
title
,
announcement
.
author
.
first_name
,
announcement
.
author
.
last_name
,
announcement
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y
%
I:
%
M
%
p"
),
announcement
.
body
)
reactList
=
announcement
.
reacts
.
all
()
sortedReactList
=
sortReacts
(
reactList
)
for
react
in
sortedReactList
:
output
+=
'{}: {} <br>'
.
format
(
react
.
name
,
react
.
tally
)
# Create your views here.
def
announcements
(
request
):
return
render
(
request
,
'announcementboard/announcements.html'
,
{
'announcements'
:
Announcement
.
objects
.
order_by
(
'-pub_datetime'
)})
output
+=
'<br>'
class
AnnouncementDetailView
(
DetailView
):
model
=
Announcement
template_name
=
'announcementboard/announcement-details.html'
return
HttpResponse
(
output
)
class
AnnouncementCreateView
(
CreateView
):
model
=
Announcement
fields
=
'title'
,
'body'
,
'author'
template_name
=
'announcementboard/announcement-add.html'
class
AnnouncementUpdateView
(
UpdateView
):
model
=
Announcement
fields
=
'title'
,
'body'
,
'author'
template_name
=
'announcementboard/announcement-edit.html'
# Sorts reactions in the following order: Like, Love, Angry
def
sortReacts
(
list
):
sortedReactList
=
[
''
]
*
3
for
react
in
list
:
if
react
.
name
==
"Like"
:
sortedReactList
[
0
]
=
react
elif
react
.
name
==
"Love"
:
sortedReactList
[
1
]
=
react
elif
react
.
name
==
"Angry"
:
sortedReactList
[
2
]
=
react
return
sortedReactList
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