Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_group17
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
Vaughn Nephi Fajardo
widget_group17
Commits
dbe52d97
Commit
dbe52d97
authored
May 23, 2022
by
Miguel Luis D. Bandelaria
Browse files
Options
Browse Files
Download
Plain Diff
feat: merged branch additions, added forms and implemented templates on forms
parents
ce767933
874353d9
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
106 deletions
+50
-106
forms.cpython-39.pyc
widget_group_17/forum/__pycache__/forms.cpython-39.pyc
+0
-0
urls.cpython-39.pyc
widget_group_17/forum/__pycache__/urls.cpython-39.pyc
+0
-0
views.cpython-39.pyc
widget_group_17/forum/__pycache__/views.cpython-39.pyc
+0
-0
forms.py
widget_group_17/forum/forms.py
+8
-0
index.html
widget_group_17/forum/templates/forum/index.html
+2
-0
post_add.html
widget_group_17/forum/templates/forum/post_add.html
+17
-0
urls.py
widget_group_17/forum/urls.py
+4
-3
views.py
widget_group_17/forum/views.py
+19
-103
No files found.
widget_group_17/forum/__pycache__/forms.cpython-39.pyc
0 → 100644
View file @
dbe52d97
File added
widget_group_17/forum/__pycache__/urls.cpython-39.pyc
View file @
dbe52d97
No preview for this file type
widget_group_17/forum/__pycache__/views.cpython-39.pyc
View file @
dbe52d97
No preview for this file type
widget_group_17/forum/forms.py
0 → 100644
View file @
dbe52d97
from
django.forms
import
ModelForm
from
homepage.models
import
WidgetUser
from
.models
import
Post
class
PostForm
(
ModelForm
):
class
Meta
:
model
=
Post
fields
=
[
"post_title"
,
"post_body"
,
"author"
]
\ No newline at end of file
widget_group_17/forum/templates/forum/index.html
View file @
dbe52d97
...
@@ -9,8 +9,10 @@
...
@@ -9,8 +9,10 @@
{% for post in posts_list %}
{% for post in posts_list %}
<li><a
href=
"{% url 'forum:detail' post.id %}"
>
{{ post.post_title }}
</a>
by {{ post.author.first_name }} {{ post.author.last_name}} dated {{ post.pub_date|date:"SHORT_DATE_FORMAT" }}
</li>
<li><a
href=
"{% url 'forum:detail' post.id %}"
>
{{ post.post_title }}
</a>
by {{ post.author.first_name }} {{ post.author.last_name}} dated {{ post.pub_date|date:"SHORT_DATE_FORMAT" }}
</li>
{% endfor %}
{% endfor %}
<button
onclick=
"location.href = '/forum/posts/add'"
>
New Forum Post
</button>
</ul>
</ul>
{% else %}
{% else %}
<p>
No posts are available.
</p>
<p>
No posts are available.
</p>
<button
onclick=
"location.href = '/forum/posts/add'"
>
New Forum Post
</button>
{% endif %}
{% endif %}
{% endblock %}
{% endblock %}
\ No newline at end of file
widget_group_17/forum/templates/forum/post_add.html
0 → 100644
View file @
dbe52d97
{% extends "base.html" %}
{% block page-title %}New Forum Post{% endblock %}
{% block content %}
<div
style =
"position: relative; left:80px; top:30px;"
>
<h1>
NEW FORUM POST
</h1>
</div>
<div
style =
"position: relative; left:80px; top:30px;"
>
<form
method=
"POST"
action =
"{% url 'forum:post_add' %}"
enctype=
"multipart/form-data"
>
{% csrf_token %}
{{ post_form.as_p }}
<button
class=
"button"
type=
"Save Post"
>
Save Post
</button>
<button
onclick=
"location.href = '/forum'"
>
Return to Forum Posts
</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
widget_group_17/forum/urls.py
View file @
dbe52d97
from
django.urls
import
path
from
django.urls
import
path
from
.
import
views
from
.
import
views
app_name
=
"forum"
app_name
=
'forum'
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
views
.
index
,
name
=
"index"
),
path
(
''
,
views
.
ForumView
.
as_view
()
,
name
=
"index"
),
path
(
'posts/<int:post_id>/details/'
,
views
.
detail
,
name
=
"detail"
),
path
(
'posts/<int:post_id>/details/'
,
views
.
detail
,
name
=
"detail"
),
# path('welcome', views.welcome, name='welcome')
path
(
'posts/add/'
,
views
.
add
,
name
=
"post_add"
),
path
(
'welcome'
,
views
.
welcome
,
name
=
'welcome'
)
]
]
\ No newline at end of file
widget_group_17/forum/views.py
View file @
dbe52d97
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.http
import
HttpResponse
,
Http404
from
django.http
import
HttpResponse
,
Http404
from
django.
template
import
loader
from
django.
views
import
View
from
.models
import
Post
,
Reply
from
.models
import
Post
,
Reply
from
.forms
import
PostForm
# Create your views here.
# Create your views here.
def
index
(
request
):
def
welcome
(
request
):
return
HttpResponse
(
'Welcome to Widget Forum!'
)
class
ForumView
(
View
):
def
get
(
self
,
request
):
posts_list
=
Post
.
objects
.
order_by
(
"pub_date"
)
posts_list
=
Post
.
objects
.
order_by
(
"pub_date"
)
template
=
loader
.
get_template
(
"forum/index.html"
)
return
render
(
request
,
"forum/index.html"
,
{
"posts_list"
:
posts_list
})
context
=
{
"posts_list"
:
posts_list
,
}
return
HttpResponse
(
template
.
render
(
context
,
request
))
# output = "<br>".join([p.post_title for p in posts_list])
# view = "Welcome to Widget's Forum! <br>"
# return HttpResponse(view)
# return HttpResponse("Welcome to Widget's forum!")
def
detail
(
request
,
post_id
):
def
detail
(
request
,
post_id
):
try
:
try
:
...
@@ -23,94 +20,13 @@ def detail(request, post_id):
...
@@ -23,94 +20,13 @@ def detail(request, post_id):
except
Post
.
DoesNotExist
:
except
Post
.
DoesNotExist
:
raise
Http404
(
"Post does not exist!"
)
raise
Http404
(
"Post does not exist!"
)
return
render
(
request
,
"forum/detail.html"
,
{
"post"
:
post
,
"reply"
:
reply
})
return
render
(
request
,
"forum/detail.html"
,
{
"post"
:
post
,
"reply"
:
reply
})
# return HttpResponse("These are the details for post # %s" % author_id)
# def welcome(request):
# forum_view = "FORUM POSTS: "
# # posts = Post.objects.all()
# # replies = Reply.objects.all()
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(author_id=1),
# Post.objects.get(author_id=1).author.first_name,
# Post.objects.get(author_id=1).author.last_name,
# Post.objects.get(author_id=1).pub_date,
# Post.objects.get(author_id=1).post_body
# )
# replies_to_first = Reply.objects.filter(associated_post_id=2)
# for reply_to_first in replies_to_first:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_first.author.first_name,
# reply_to_first.author.last_name,
# reply_to_first.pub_date,
# reply_to_first.reply_body
# )
# forum_view = forum_view + "<br>"
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(author_id=2),
# Post.objects.get(author_id=2).author.first_name,
# Post.objects.get(author_id=2).author.last_name,
# Post.objects.get(author_id=2).pub_date,
# Post.objects.get(author_id=2).post_body
# )
# replies_to_second = Reply.objects.filter(associated_post_id=3)
# for reply_to_second in replies_to_second:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_second.author.first_name,
# reply_to_second.author.last_name,
# reply_to_second.pub_date,
# reply_to_second.reply_body
# )
# forum_view = forum_view + "<br>"
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(id=4),
# Post.objects.get(id=4).author.first_name,
# Post.objects.get(id=4).author.last_name,
# Post.objects.get(id=4).pub_date,
# Post.objects.get(id=4).post_body
# )
# replies_to_third = Reply.objects.filter(associated_post_id=4)
# for reply_to_third in replies_to_third:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_third.author.first_name,
# reply_to_third.author.last_name,
# reply_to_third.pub_date,
# reply_to_third.reply_body
# )
# for post in posts:
# forum_view += "<br> {} by {} {} dated {}: <br> {}".\
# format(
# post.post_title,
# post.author.first_name,
# post.author.last_name,
# post.pub_date,
# post.post_body
# )
# for reply in replies:
# forum_view += '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply.author.first_name,
# reply.author.last_name,
# reply.pub_date,
# reply.reply_body
# )
return
HttpResponse
(
forum_view
)
def
add
(
request
):
if
request
.
method
==
"POST"
:
post_form
=
PostForm
(
request
.
POST
,
request
.
FILES
)
if
post_form
.
is_valid
():
post_form
.
save
()
return
redirect
(
"/forum"
)
else
:
post_form
=
PostForm
()
return
render
(
request
,
"forum/post_add.html"
,
{
"post_form"
:
post_form
})
\ No newline at end of file
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