Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_mgabolanimav
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
Mavrick Jordan Lee
midterm_mgabolanimav
Commits
96536f33
Commit
96536f33
authored
May 14, 2023
by
Mavrick Jordan Lee
Browse files
Options
Browse Files
Download
Plain Diff
Merged deashboardv2 and announcementsv2.
parents
3e3d6946
54970ec4
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
109 additions
and
36 deletions
+109
-36
0001_initial.cpython-310.pyc
...ments/migrations/__pycache__/0001_initial.cpython-310.pyc
+0
-0
0002_auto_20230305_1707.cpython-310.pyc
...tions/__pycache__/0002_auto_20230305_1707.cpython-310.pyc
+0
-0
0003_announcement_announcement_author.cpython-310.pyc
...e__/0003_announcement_announcement_author.cpython-310.pyc
+0
-0
__init__.cpython-310.pyc
...uncements/migrations/__pycache__/__init__.cpython-310.pyc
+0
-0
models.py
widget_mgabolanimav/announcements/models.py
+16
-5
announcement-add.html
...nouncements/templates/announcements/announcement-add.html
+10
-0
announcement-details.html
...cements/templates/announcements/announcement-details.html
+19
-0
announcement-edit.html
...ouncements/templates/announcements/announcement-edit.html
+10
-0
announcements.html
.../announcements/templates/announcements/announcements.html
+21
-0
urls.py
widget_mgabolanimav/announcements/urls.py
+7
-3
views.py
widget_mgabolanimav/announcements/views.py
+26
-28
No files found.
widget_mgabolanimav/announcements/migrations/__pycache__/0001_initial.cpython-310.pyc
View file @
96536f33
No preview for this file type
widget_mgabolanimav/announcements/migrations/__pycache__/0002_auto_20230305_1707.cpython-310.pyc
View file @
96536f33
No preview for this file type
widget_mgabolanimav/announcements/migrations/__pycache__/0003_announcement_announcement_author.cpython-310.pyc
View file @
96536f33
No preview for this file type
widget_mgabolanimav/announcements/migrations/__pycache__/__init__.cpython-310.pyc
View file @
96536f33
No preview for this file type
widget_mgabolanimav/announcements/models.py
View file @
96536f33
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
from
django.utils
import
timezone
# Create your models here.
# please insert foreign key from dashboard application on announcement_author
class
Announcement
(
models
.
Model
):
announcement_title
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
null
=
True
,
)
announcement_body
=
models
.
CharField
(
max_length
=
250
,
unique
=
True
,
null
=
True
,
)
announcement_author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
announcement_title
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
,
null
=
True
,
verbose_name
=
"Title"
)
announcement_body
=
models
.
TextField
(
max_length
=
250
,
unique
=
True
,
null
=
True
,
verbose_name
=
"Body"
)
announcement_author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
,
verbose_name
=
"Author"
)
announcement_pub_datetime
=
models
.
DateTimeField
(
null
=
True
,
)
def
__str__
(
self
):
return
self
.
announcement_title
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
pk
:
self
.
announcement_pub_datetime
=
timezone
.
now
()
return
super
()
.
save
(
*
args
,
**
kwargs
)
def
get_absolute_url
(
self
):
return
reverse
(
'announcements:announcement-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
reaction_choices
=
(
(
'Like'
,
'Like'
),
...
...
@@ -22,10 +33,10 @@ reaction_choices = (
class
Reaction
(
models
.
Model
):
reaction_name
=
models
.
CharField
(
max_length
=
50
,
blank
=
True
,
choices
=
reaction_choices
,
null
=
True
,)
reaction_name
=
models
.
CharField
(
max_length
=
50
,
blank
=
True
,
choices
=
reaction_choices
,
null
=
True
,
)
reaction_tally
=
models
.
IntegerField
(
null
=
True
,
default
=
0
,
)
reaction_announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
,
null
=
True
,
)
def
__str__
(
self
):
return
self
.
reaction_name
widget_mgabolanimav/announcements/templates/announcements/announcement-add.html
0 → 100644
View file @
96536f33
{% extends 'base.html' %}
{% block title %} Add Announcement {% endblock %}
{% block content %}
<h1>
Add a new announcement
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"Submit"
value=
"Add Announcement"
>
</form>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/announcements/templates/announcements/announcement-details.html
0 → 100644
View file @
96536f33
{% extends 'base.html' %}
{% block title %}{{ announcement.announcement_title }}{% endblock %}
{% block content %}
<h1>
{{ announcement.announcement_title }}
<br>
by {{ announcement.announcement_author.first_name }}
{{ announcement.announcement_author.last_name }}
</h1>
{{ announcement.announcement_pub_datetime }}
<br>
{{ announcement.announcement_body }}
<br>
{% for reaction in reactions %}
<p>
{{ reaction.reaction_name }}: {{ reaction.reaction_tally }}
</p>
{% endfor %}
<br>
<a
href=
"{% url 'announcements:announcement-edit' pk=announcement.pk %}"
>
<button>
Edit Announcement
</button>
</a>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/announcements/templates/announcements/announcement-edit.html
0 → 100644
View file @
96536f33
{% extends 'base.html' %}
{% block title %} Edit Announcement {% endblock %}
{% block content %}
<h1>
Edit announcement:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"Submit"
value=
"Save Changes"
>
</form>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/announcements/templates/announcements/announcements.html
0 → 100644
View file @
96536f33
{% extends 'base.html' %}
{% block title %} Widget's Announcement Board {% endblock %}
{% block content %}
<h1>
Welcome to Widget's Announcement Board!
</h1>
<h3>
Announcements:
</h3>
{% for announcement in announcements %}
<a
href=
"{% url 'announcements:announcement-details' announcement.id %}"
>
{{ announcement.announcement_title }}
by {{ announcement.announcement_author.first_name }} {{ announcement.announcement_author.last_name }}
</a>
<br>
{% endfor %}
<br>
<a
href=
"{% url 'announcements:announcement-add' %}"
>
<button>
New Announcement
</button>
</a>
<br><br>
<a
href=
""
>
Dashboard
</a>
<br>
<a
href=
""
>
Forum
</a>
{% endblock %}
widget_mgabolanimav/announcements/urls.py
View file @
96536f33
from
django.urls
import
path
from
.
import
views
from
.views
import
Announcements
,
AnnouncementsDetailsView
,
AnnouncementsCreateView
,
AnnouncementsEditView
urlpatterns
=
[
path
(
''
,
views
.
announcements
,
name
=
"announcements"
)
path
(
''
,
Announcements
,
name
=
"announcements"
),
path
(
'<int:pk>/details/'
,
AnnouncementsDetailsView
.
as_view
(),
name
=
"announcement-details"
),
path
(
'add/'
,
AnnouncementsCreateView
.
as_view
(),
name
=
"announcement-add"
),
path
(
'<int:pk>/edit/'
,
AnnouncementsEditView
.
as_view
(),
name
=
"announcement-edit"
),
]
app_name
=
'announcements'
\ No newline at end of file
widget_mgabolanimav/announcements/views.py
View file @
96536f33
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Announcement
,
Reaction
# Create your views here.
def
Announcements
(
request
):
announcements
=
Announcement
.
objects
.
order_by
(
"-announcement_pub_datetime"
)
context
=
{
"announcements"
:
announcements
,
}
return
render
(
request
,
'announcements/announcements.html'
,
context
)
def
announcements
(
request
):
announcement
=
Announcement
.
objects
.
all
()
response
=
"<h3>Widget's Announcement Board</h3>"
for
every
in
announcement
:
datetime
=
every
.
announcement_pub_datetime
.
strftime
(
"
%
a,
%
b
%
d,
%
Y
%
I:
%
M
%
p"
)
response
+=
"<p>{}"
.
format
(
every
.
announcement_title
)
+
\
" By {}"
.
format
(
every
.
announcement_author
.
first_name
)
+
\
" {}"
.
format
(
every
.
announcement_author
.
last_name
)
+
\
" published {}"
.
format
(
datetime
)
+
\
"<br>{}"
.
format
(
every
.
announcement_body
)
class
AnnouncementsDetailsView
(
DetailView
):
model
=
Announcement
template_name
=
'announcements/announcement-details.html'
\
like_on_post
=
0
love_on_post
=
0
angry_on_post
=
0
reactions
=
Reaction
.
objects
.
filter
(
reaction_announcement
=
every
)
for
every
in
reactions
:
if
every
.
reaction_name
==
"Like"
:
like_on_post
=
every
.
reaction_tally
elif
every
.
reaction_name
==
"Love"
:
love_on_post
=
every
.
reaction_tally
elif
every
.
reaction_name
==
"Angry"
:
angry_on_post
=
every
.
reaction_tally
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'reactions'
]
=
Reaction
.
objects
.
filter
(
reaction_announcement
=
self
.
object
)
return
context
response
+=
"<br>like: {}"
.
format
(
like_on_post
)
+
\
"<br>love: {}"
.
format
(
love_on_post
)
+
\
"<br>angry: {}<br>"
.
format
(
angry_on_post
)
return
HttpResponse
(
response
)
class
AnnouncementsCreateView
(
CreateView
):
model
=
Announcement
fields
=
'announcement_title'
,
'announcement_body'
,
'announcement_author'
template_name
=
'announcements/announcement-add.html'
class
AnnouncementsEditView
(
UpdateView
):
model
=
Announcement
fields
=
'announcement_title'
,
'announcement_body'
,
'announcement_author'
template_name
=
'announcements/announcement-edit.html'
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