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
ddcac344
Commit
ddcac344
authored
May 17, 2022
by
Emmanuel Linus T. Evangelista
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new Forum post form, convert to CBV, minor QoL changes
parent
e7a413b3
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
147 additions
and
2 deletions
+147
-2
forms.py
WidgetFEKK/Forum/forms.py
+7
-0
add.css
WidgetFEKK/Forum/static/Forum/add.css
+56
-0
index.css
WidgetFEKK/Forum/static/Forum/index.css
+20
-0
add.html
WidgetFEKK/Forum/templates/Forum/add.html
+34
-0
index.html
WidgetFEKK/Forum/templates/Forum/index.html
+15
-0
views.py
WidgetFEKK/Forum/views.py
+14
-2
urls.py
WidgetFEKK/WidgetFEKK/urls.py
+1
-0
No files found.
WidgetFEKK/Forum/forms.py
0 → 100644
View file @
ddcac344
from
django
import
forms
from
.models
import
Post
class
PostForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Post
fields
=
[
'post_title'
,
'post_body'
,
'author'
]
\ No newline at end of file
WidgetFEKK/Forum/static/Forum/add.css
0 → 100644
View file @
ddcac344
body
{
padding
:
64px
160px
;
}
#back
{
margin
:
0
0
32px
;
display
:
flex
;
align-items
:
center
;
}
#back
a
{
color
:
black
;
text-decoration
:
none
;
margin-left
:
8px
;
}
#back
a
:hover
{
text-decoration
:
underline
;
}
form
>
*
{
display
:
block
;
}
form
>
label
{
font-size
:
1rem
;
margin-bottom
:
4px
;
}
form
>
input
,
form
>
select
{
margin-bottom
:
24px
;
padding
:
8px
16px
;
border
:
1px
solid
black
;
border-radius
:
4px
;
font-size
:
1rem
;
}
#save-post-btn
{
color
:
white
;
font-size
:
16px
;
background-color
:
#187bcd
;
display
:
flex
;
align-items
:
center
;
margin-top
:
32px
;
padding
:
16px
32px
;
border
:
none
;
border-radius
:
4px
;
width
:
fit-content
;
cursor
:
pointer
;
}
\ No newline at end of file
WidgetFEKK/Forum/static/Forum/index.css
View file @
ddcac344
...
...
@@ -27,3 +27,23 @@ body {
.posts
>
li
a
:hover
{
text-decoration
:
underline
;
}
#add-post-btn
{
color
:
white
;
text-decoration
:
none
;
font-weight
:
normal
;
background-color
:
#187bcd
;
display
:
flex
;
align-items
:
center
;
margin-top
:
32px
;
padding
:
16px
32px
;
border-radius
:
4px
;
width
:
fit-content
;
}
#add-post-btn
>
svg
{
margin-right
:
16px
;
}
\ No newline at end of file
WidgetFEKK/Forum/templates/Forum/add.html
0 → 100644
View file @
ddcac344
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'Forum/styles.css' %}"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static 'Forum/add.css' %}"
>
{% endblock %}
{% block title %}Add Forum Post{% endblock %}
{% block content %}
<main>
<div
id=
"back"
>
<svg
xmlns=
"http://www.w3.org/2000/svg"
width=
"16"
height=
"16"
fill=
"currentColor"
viewBox=
"0 0 16 16"
>
<path
fill-rule=
"evenodd"
d=
"M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"
stroke=
"black"
/>
</svg>
<a
href=
"/forum"
>
Back to all posts
</a>
</div>
<h1>
New Forum Post
</h1>
<form
action=
"/posts/add/"
method=
"post"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
id=
"save-post-btn"
value=
"Save Post"
>
</form>
</main>
{% endblock %}
\ No newline at end of file
WidgetFEKK/Forum/templates/Forum/index.html
View file @
ddcac344
...
...
@@ -18,5 +18,20 @@
<li><a
href=
"/posts/{{ post.pk }}/details"
><strong>
{{ post.post_title }}
</strong>
by
<strong>
{{ post.author.first_name }} {{ post.author.last_name }}
</strong>
dated
<strong>
{{ post.pub_date|date:"d/m/Y" }}
</strong></a></li>
{% endfor %}
</ul>
<a
href=
"/posts/add"
id=
"add-post-btn"
>
<svg
xmlns=
"http://www.w3.org/2000/svg"
width=
"20"
height=
"20"
fill=
"currentColor"
class=
"bi bi-plus-square"
viewBox=
"0 0 16 16"
>
<path
d=
"M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"
stroke=
"white"
stroke-width=
"0.5"
/>
<path
d=
"M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"
stroke=
"white"
stroke-width=
"0.5"
/>
</svg>
New Forum Post
</a>
</main>
{% endblock %}
\ No newline at end of file
WidgetFEKK/Forum/views.py
View file @
ddcac344
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
.models
import
Post
,
Reply
from
.forms
import
PostForm
def
get_readable_time
(
timestamp
):
return
timestamp
.
strftime
(
"
%
m/
%
d/
%
Y"
)
...
...
@@ -14,3 +16,13 @@ def details(request, post_id):
except
Post
.
DoesNotExist
:
raise
Http404
(
'Post does not exist'
)
return
render
(
request
,
'Forum/details.html'
,
{
'post'
:
post
,
'replies_sorted'
:
post
.
reply_set
.
order_by
(
'-pub_date'
)})
class
AddForumPostView
(
View
):
def
get
(
self
,
request
):
return
render
(
request
,
'Forum/add.html'
,
{
'form'
:
PostForm
()})
def
post
(
self
,
request
):
form
=
PostForm
(
request
.
POST
)
if
form
.
is_valid
():
new_post
=
form
.
save
()
return
redirect
(
'/forum'
)
\ No newline at end of file
WidgetFEKK/WidgetFEKK/urls.py
View file @
ddcac344
...
...
@@ -23,6 +23,7 @@ from Homepage.views import UserPageView
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'forum/'
,
include
(
'Forum.urls'
,
namespace
=
'Forum'
)),
path
(
'posts/add/'
,
Forum_views
.
AddForumPostView
.
as_view
(),
name
=
'add_forum_post'
),
path
(
'posts/<int:post_id>/details/'
,
Forum_views
.
details
,
name
=
'post_details'
),
path
(
'homepage/'
,
include
(
'Homepage.urls'
,
namespace
=
"Homepage"
)),
path
(
'users/<int:user_id>/details'
,
UserPageView
.
as_view
(),
name
=
'user-details'
),
...
...
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