Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widgets_FEKK
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
Kyla Martin
widgets_FEKK
Commits
744e6f28
Commit
744e6f28
authored
May 22, 2022
by
Kyla Martin
❓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create page to add a new announcement
parent
4f7f5afc
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
135 additions
and
6 deletions
+135
-6
forms.py
WidgetFEKK/Announcements/forms.py
+11
-0
0003_announcement_announcement_image.py
...ements/migrations/0003_announcement_announcement_image.py
+18
-0
models.py
WidgetFEKK/Announcements/models.py
+6
-0
styles.css
WidgetFEKK/Announcements/static/Announcements/styles.css
+50
-0
add.html
WidgetFEKK/Announcements/templates/announcements/add.html
+25
-0
details.html
...etFEKK/Announcements/templates/announcements/details.html
+5
-1
index.html
WidgetFEKK/Announcements/templates/announcements/index.html
+3
-2
urls.py
WidgetFEKK/Announcements/urls.py
+1
-1
views.py
WidgetFEKK/Announcements/views.py
+15
-2
urls.py
WidgetFEKK/WidgetFEKK/urls.py
+1
-0
db.sqlite3
WidgetFEKK/db.sqlite3
+0
-0
No files found.
WidgetFEKK/Announcements/forms.py
0 → 100644
View file @
744e6f28
from
django
import
forms
from
django.forms
import
Textarea
from
.models
import
Announcement
class
AnnouncementForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Announcement
fields
=
[
'announcement_title'
,
'author'
,
'announcement_body'
,
'announcement_image'
]
widgets
=
{
'announcement_body'
:
Textarea
(
attrs
=
{
'cols'
:
50
,
'rows'
:
10
}),
}
\ No newline at end of file
WidgetFEKK/Announcements/migrations/0003_announcement_announcement_image.py
0 → 100644
View file @
744e6f28
# Generated by Django 4.0.3 on 2022-05-22 06:03
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'Announcements'
,
'0002_announcement_author_reaction'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'announcement'
,
name
=
'announcement_image'
,
field
=
models
.
ImageField
(
blank
=
True
,
null
=
True
,
upload_to
=
'announcements/images/pub_date'
),
),
]
WidgetFEKK/Announcements/models.py
View file @
744e6f28
import
os
from
django.db
import
models
from
Homepage.models
import
WidgetUser
def
image
(
request
,
filename
):
return
os
.
path
.
join
(
"uploads/"
,
filename
)
class
Announcement
(
models
.
Model
):
announcement_title
=
models
.
CharField
(
max_length
=
100
)
announcement_body
=
models
.
CharField
(
max_length
=
500
)
pub_date
=
models
.
DateTimeField
(
"Date published"
,
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
default
=
1
)
announcement_image
=
models
.
ImageField
(
upload_to
=
image
,
null
=
True
,
blank
=
True
)
def
__str__
(
self
):
return
self
.
announcement_title
...
...
WidgetFEKK/Announcements/static/Announcements/styles.css
View file @
744e6f28
...
...
@@ -30,6 +30,56 @@ h1{
border-radius
:
5px
;
}
.form
{
display
:
grid
;
grid-template-columns
:
150px
auto
150px
;
column-gap
:
0.5rem
;
row-gap
:
0.5rem
;
}
.form-items
{
display
:
grid
;
align-items
:
end
;
justify-content
:
space-evenly
;
}
.form-items
p
{
font-weight
:
bold
;
}
.form-items
>
p
:first-of-type
{
grid-column
:
1
;
grid-row
:
1
;
}
.form-items
>
p
:nth-of-type
(
2
)
{
grid-column
:
2
;
grid-row
:
1
;
}
.form-items
>
p
:nth-of-type
(
3
)
{
grid-column
:
1
;
grid-row
:
2
/
3
;
}
.form-items
>
p
:nth-of-type
(
4
)
{
grid-column
:
2
;
grid-row
:
2
;
}
.submit-button
{
background-color
:
gainsboro
;
padding
:
5px
;
width
:
fit-content
;
border-radius
:
5px
;
border-color
:
darkgray
;
text-align
:
center
;
}
.submit-button
:hover
{
color
:
red
;
}
li
{
color
:
black
;
}
...
...
WidgetFEKK/Announcements/templates/announcements/add.html
0 → 100644
View file @
744e6f28
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'Announcements/styles.css' %}"
>
{% endblock %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block content %}
<main>
<div
id=
"back"
><a
href=
"/announcements"
>
Back to all announcements
</a></div>
<h1>
New Announcement
</h1>
<form
method=
"post"
enctype=
"multipart/form-data"
>
<div
class=
"form-items"
>
{% csrf_token %}
{{ form.as_p }}
<input
class=
"submit-button"
type=
"submit"
value=
"Save Announcement"
>
</div>
</form>
</div>
</main>
{% endblock %}
\ No newline at end of file
WidgetFEKK/Announcements/templates/announcements/details.html
View file @
744e6f28
...
...
@@ -13,7 +13,11 @@
<article>
<div
id=
"back"
><a
href=
"/announcements"
>
Back to all announcements
</a></div>
<div
align=
"center"
><img
id=
"header"
src=
"{% static 'Announcements/header.png' %}"
alt=
"a header"
></div>
<h1
id=
"title"
>
{{ announcement.announcement_title}}
</h1>
{% if announcement.announcement_image %}
<div
align=
"center"
><img
id=
"announcement-image"
src=
"{{ MEDIA_DIR }}/uploads/{{ announcement.announcement_image }}"
></div>
{% endif %}
<h1
id=
"title"
>
{{ announcement.announcement_title}}
</h1>
<h4
id=
"subtitle"
>
by {{ announcement.author.first_name}} {{ announcement.author.last_name }}, {{ announcement.pub_date|date:"d/m/Y" }}
</h4>
<p
class=
"body"
>
{{ announcement.announcement_body }}
</p>
...
...
WidgetFEKK/Announcements/templates/announcements/index.html
View file @
744e6f28
...
...
@@ -9,13 +9,14 @@
{% block content %}
<main>
<h1>
Announcement Board
</h1>
<h3>
Important Announcements:
</h3>
<h1
id=
"title"
>
Announcement Board
</h1>
<h3
id=
"subtitle"
>
Important Announcements:
</h3>
<ul
class=
"announcements"
></ul>
{% for announcement in announcement_sorted %}
<li>
<a
href=
"/announcements/{{ announcement.pk }}/details"
><strong>
{{ announcement.announcement_title }}
</strong>
by
<strong>
{{ announcement.author.first_name }} {{ announcement.author.last_name }}
</strong>
dated
<strong>
{{ announcement.pub_date|date:"d/m/Y" }}
</strong></a>
</li>
{% endfor %}
</ul>
<p><a
href=
"/announcements/add"
><strong>
+ New Announcement
</strong></a></p>
</main>
{% endblock %}
\ No newline at end of file
WidgetFEKK/Announcements/urls.py
View file @
744e6f28
...
...
@@ -5,4 +5,4 @@ urlpatterns = [
path
(
''
,
views
.
index
,
name
=
'index'
)
]
app_name
=
'Announcements'
\ No newline at end of file
app_name
=
'Announcements'
\ No newline at end of file
WidgetFEKK/Announcements/views.py
View file @
744e6f28
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.http
import
Http404
,
HttpResponse
from
django.views
import
View
from
.forms
import
AnnouncementForm
from
.models
import
Announcement
,
Reaction
def
date_month_year
(
timestamp
):
...
...
@@ -13,4 +15,15 @@ def details(request, announcement_id):
announcement
=
Announcement
.
objects
.
get
(
pk
=
announcement_id
)
except
Announcement
.
DoesNotExist
:
raise
Http404
(
'Announcement does not exist'
)
return
render
(
request
,
'announcements/details.html'
,
{
'announcement'
:
announcement
,
'reaction_sorted'
:
announcement
.
reaction_set
.
order_by
(
'tally'
)})
\ No newline at end of file
return
render
(
request
,
'announcements/details.html'
,
{
'announcement'
:
announcement
,
'reaction_sorted'
:
announcement
.
reaction_set
.
order_by
(
'tally'
)})
class
AddAnnouncementView
(
View
):
def
get
(
self
,
request
):
return
render
(
request
,
'announcements/add.html'
,
{
'form'
:
AnnouncementForm
()})
def
post
(
self
,
request
):
form
=
AnnouncementForm
(
request
.
POST
,
request
.
FILES
)
if
form
.
is_valid
():
new_announcement
=
form
.
save
()
return
redirect
(
'/announcements'
)
\ No newline at end of file
WidgetFEKK/WidgetFEKK/urls.py
View file @
744e6f28
...
...
@@ -31,6 +31,7 @@ urlpatterns = [
path
(
'users/<int:user_id>/details'
,
UserPageView
.
as_view
(),
name
=
'user-details'
),
path
(
'announcements/'
,
include
(
'Announcements.urls'
,
namespace
=
"Announcements"
)),
path
(
'announcements/<int:announcement_id>/details'
,
Announcements_views
.
details
,
name
=
'announcement_details'
),
path
(
'announcements/add'
,
Announcements_views
.
AddAnnouncementView
.
as_view
(),
name
=
'add_announcement'
),
path
(
'assignments/'
,
include
(
'Assignments.urls'
,
namespace
=
"Assignments"
)),
path
(
'assignment/<int:pk>/details'
,
AssignmentDetailView
.
as_view
(),
name
=
'assignment-detail'
),
...
...
WidgetFEKK/db.sqlite3
deleted
100644 → 0
View file @
4f7f5afc
File deleted
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