Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
midterm_OhMyBash
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
Nheo Samson
midterm_OhMyBash
Commits
b357a962
Commit
b357a962
authored
May 14, 2023
by
nheoxoz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'announcementsv2'
parents
3e0eca39
d7110c12
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
235 additions
and
39 deletions
+235
-39
0007_alter_announcement_body_and_more.py
...ments/migrations/0007_alter_announcement_body_and_more.py
+29
-0
0008_alter_reaction_tally.py
...ash/announcements/migrations/0008_alter_reaction_tally.py
+18
-0
0007_alter_announcement_body_and_more.cpython-310.pyc
...e__/0007_alter_announcement_body_and_more.cpython-310.pyc
+0
-0
0008_alter_reaction_tally.cpython-310.pyc
...ons/__pycache__/0008_alter_reaction_tally.cpython-310.pyc
+0
-0
models.py
widget_OhMyBash/announcements/models.py
+45
-8
announcement-add.html
...nouncements/templates/announcements/announcement-add.html
+17
-0
announcement-details.html
...cements/templates/announcements/announcement-details.html
+27
-0
announcement-edit.html
...ouncements/templates/announcements/announcement-edit.html
+17
-0
announcements.html
.../announcements/templates/announcements/announcements.html
+38
-0
urls.py
widget_OhMyBash/announcements/urls.py
+16
-1
views.py
widget_OhMyBash/announcements/views.py
+27
-29
settings.py
widget_OhMyBash/widget_OhMyBash/settings.py
+1
-1
No files found.
widget_OhMyBash/announcements/migrations/0007_alter_announcement_body_and_more.py
0 → 100644
View file @
b357a962
# Generated by Django 4.1.7 on 2023-05-12 04:52
from
django.db
import
migrations
,
models
import
django.utils.timezone
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcements'
,
'0006_remove_announcement_first_name_and_more'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'body'
,
field
=
models
.
TextField
(
default
=
''
),
),
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'pub_datetime'
,
field
=
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
),
),
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'title'
,
field
=
models
.
CharField
(
default
=
''
,
max_length
=
100
),
),
]
widget_OhMyBash/announcements/migrations/0008_alter_reaction_tally.py
0 → 100644
View file @
b357a962
# Generated by Django 4.1.7 on 2023-05-12 06:23
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcements'
,
'0007_alter_announcement_body_and_more'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'reaction'
,
name
=
'tally'
,
field
=
models
.
IntegerField
(
default
=
0
),
),
]
widget_OhMyBash/announcements/migrations/__pycache__/0007_alter_announcement_body_and_more.cpython-310.pyc
0 → 100644
View file @
b357a962
File added
widget_OhMyBash/announcements/migrations/__pycache__/0008_alter_reaction_tally.cpython-310.pyc
0 → 100644
View file @
b357a962
File added
widget_OhMyBash/announcements/models.py
View file @
b357a962
from
django.db
import
models
from
django.db
import
models
from
django.urls
import
reverse
from
django.utils
import
timezone
class
Announcement
(
models
.
Model
):
class
Announcement
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
title
=
models
.
CharField
(
max_length
=
100
,
default
=
""
)
body
=
models
.
TextField
()
body
=
models
.
TextField
(
default
=
""
)
author
=
models
.
ForeignKey
(
author
=
models
.
ForeignKey
(
'dashboard.WidgetUser'
,
'dashboard.WidgetUser'
,
on_delete
=
models
.
CASCADE
,
on_delete
=
models
.
CASCADE
,
related_name
=
'announcements_author'
related_name
=
'announcements_author'
)
)
pub_datetime
=
models
.
DateTimeField
()
pub_datetime
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'
''{} by {} published {}
\n
{}''
'
.
format
(
return
'
{} by {} {} published {}, {}: {}
'
.
format
(
self
.
title
,
self
.
title
,
self
.
author
,
self
.
author
.
first_name
,
self
.
pub_datetime
,
self
.
author
.
last_name
,
self
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y"
),
self
.
pub_datetime
.
strftime
(
"
%
H:
%
M
%
p"
),
self
.
body
,
self
.
body
,
)
)
def
format_date
(
self
):
return
'{}'
.
format
(
self
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y"
))
def
format_time
(
self
):
return
'{}'
.
format
(
self
.
pub_datetime
.
strftime
(
"
%
H:
%
M
%
p"
))
def
getLike
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Like"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
getLove
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Love"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
getAngry
(
self
):
try
:
return
'{}'
.
format
(
Reaction
.
objects
.
get
(
name
=
"Angry"
,
announcement
=
self
)
.
tally
)
except
:
return
'0'
def
get_absolute_url
(
self
):
return
reverse
(
'announcements:announcement-details'
,
kwargs
=
{
'pk'
:
self
.
pk
},
)
class
Reaction
(
models
.
Model
):
class
Reaction
(
models
.
Model
):
...
@@ -36,8 +73,8 @@ class Reaction(models.Model):
...
@@ -36,8 +73,8 @@ class Reaction(models.Model):
choices
=
REACTION_CHOICES
,
choices
=
REACTION_CHOICES
,
default
=
REACTION_LIKE
,
default
=
REACTION_LIKE
,
)
)
tally
=
models
.
IntegerField
()
tally
=
models
.
IntegerField
(
default
=
0
)
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
)
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
'{} reactions for {}'
.
format
(
self
.
name
,
self
.
announcement
)
widget_OhMyBash/announcements/templates/announcements/announcement-add.html
0 → 100644
View file @
b357a962
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Announcement:% {% endblock %}
{% block heading %}
<h1>
Add a new announcement:
</h1>
{% endblock %}
{% block content %}
<form
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"submit"
value=
"Add Announcement"
>
</form>
<a
href=
"/announcements/"
>
<button
class=
"btn"
>
Back to Announcement Board
</button>
</a>
{% endblock %}
widget_OhMyBash/announcements/templates/announcements/announcement-details.html
0 → 100644
View file @
b357a962
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<p>
by {{ object.author.first_name }} {{ object.author.last_name }}
<br>
</p>
<p>
{{ object.format_date}}, {{ object.format_time }}
<br><br>
{{ object.body }}
<br>
Like: {{ object.getLike }}
<br>
Love: {{ object.getLove }}
<br>
Angry: {{ object.getAngry }}
</p>
<a
href=
"/announcements/{{object.pk}}/edit"
>
<button
class=
"btn"
>
Edit Announcement
</button>
</a><br>
<a
href=
"/announcements/"
>
<button
class=
"btn"
>
Back to Announcement Board
</button>
</a>
{% endblock %}
widget_OhMyBash/announcements/templates/announcements/announcement-edit.html
0 → 100644
View file @
b357a962
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block heading %}Edit announcement:{% endblock %}
{% block content %}
<form
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"submit"
value=
"Save Changes to Announcement"
>
</form>
<a
href=
"/announcements/"
>
<button
class=
"btn"
>
Back to Announcement Board
</button>
</a>
{% endblock %}
widget_OhMyBash/announcements/templates/announcements/announcements.html
0 → 100644
View file @
b357a962
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block heading %}Welcome to Widget's Announcement Board!{% endblock %}
{% block content %}
<p>
Announcements:
<br>
{% for a in announcements|slice:"::-1" %}
<a
href=
"{{ a.get_absolute_url }}"
>
{{a.title}} by {{ a.author.first_name }} {{ a.author.last_name }}
</a><br>
{% endfor %}
</p>
{% endblock %}
{% block footing %}
<p>
<a
href=
"/announcements/add"
>
<button
class=
"btn add"
>
New Announcement
</button>
</a>
</p>
<button
type=
"button"
class=
"btn"
>
<a
href=
"/dashboard/"
class=
"link"
>
Dashboard
</a>
</button><br>
<button
type=
"button"
class=
"btn"
>
<a
href=
"/forum/"
class=
"link"
>
Forum
</a>
</button><br>
<button
type=
"button"
class=
"btn"
>
<a
href=
"/assignments/"
class=
"link"
>
Assignments
</a>
</button><br>
<button
type=
"button"
class=
"btn"
>
<a
href=
"/widget_calendar/"
class=
"link"
>
Calendar
</a>
</button>
{% endblock %}
widget_OhMyBash/announcements/urls.py
View file @
b357a962
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
from
.views
import
(
index
,
AnnouncementsDetailView
,
AnnouncementsCreateView
,
AnnouncementsUpdateView
,
)
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
index
,
name
=
'index'
),
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
=
"announcements"
app_name
=
"announcements"
widget_OhMyBash/announcements/views.py
View file @
b357a962
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
from
.models
import
Announcement
,
Reaction
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Announcement
def
index
(
request
):
def
index
(
request
):
return_string
=
"<p>Widget's Announcement Board</p>Announcements:<br>"
announcements
=
Announcement
.
objects
.
all
()
for
a
in
Announcement
.
objects
.
all
():
return
render
(
return_string
+=
'''{} by {} {} published {}{}<br>'''
.
format
(
request
,
a
.
title
,
'announcements/announcements.html'
,
a
.
author
.
first_name
,
{
'announcements'
:
announcements
},
a
.
author
.
last_name
,
)
a
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y,
%
H:
%
M
%
p:'
),
a
.
body
,
)
class
AnnouncementsDetailView
(
DetailView
):
likeTally
=
0
model
=
Announcement
loveTally
=
0
template_name
=
'announcements/announcement-details.html'
angryTally
=
0
for
r
in
Reaction
.
objects
.
all
():
if
r
.
name
==
"LIKE"
and
r
.
announcement
==
a
:
class
AnnouncementsCreateView
(
CreateView
):
likeTally
+=
r
.
tally
model
=
Announcement
if
r
.
name
==
"LOVE"
and
r
.
announcement
==
a
:
fields
=
'title'
,
'body'
,
'author'
loveTally
+=
r
.
tally
template_name
=
'announcements/announcement-add.html'
if
r
.
name
==
"ANGRY"
and
r
.
announcement
==
a
:
angryTally
+=
r
.
tally
return_string
+=
'''Like: {}<br>Love: {}
class
AnnouncementsUpdateView
(
UpdateView
):
<br>Angry: {}<br><br>'''
.
format
(
model
=
Announcement
likeTally
,
fields
=
'title'
,
'body'
,
'author'
loveTally
,
template_name
=
'announcements/announcement-edit.html'
angryTally
,
)
html_string
=
'<html><body>{}</body></html>'
.
format
(
return_string
)
return
HttpResponse
(
html_string
)
widget_OhMyBash/widget_OhMyBash/settings.py
View file @
b357a962
...
@@ -124,7 +124,7 @@ USE_TZ = True
...
@@ -124,7 +124,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL
=
'
/
static/'
STATIC_URL
=
'static/'
STATICFILES_DIRS
=
[
os
.
path
.
join
(
BASE_DIR
,
'static'
)]
STATICFILES_DIRS
=
[
os
.
path
.
join
(
BASE_DIR
,
'static'
)]
# Default primary key field type
# Default primary key field type
...
...
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