Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_Francoconuts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Chester Tan
widget_Francoconuts
Commits
cc5eb49e
Commit
cc5eb49e
authored
May 22, 2022
by
Mario Franco C. Deuna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated views.py and urls.py to CBV and created templates.
parent
6e684a91
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
32 deletions
+178
-32
0003_alter_reaction_announcement_and_more.py
...s/migrations/0003_alter_reaction_announcement_and_more.py
+24
-0
forms.py
widget_Francoconuts/assignments/forms.py
+1
-1
forum_detail.html
widget_Francoconuts/forum/templates/Forum/forum_detail.html
+35
-0
post_list.html
widget_Francoconuts/forum/templates/Forum/post_list.html
+29
-0
urls.py
widget_Francoconuts/forum/urls.py
+5
-2
views.py
widget_Francoconuts/forum/views.py
+84
-29
No files found.
widget_Francoconuts/announcements/migrations/0003_alter_reaction_announcement_and_more.py
0 → 100644
View file @
cc5eb49e
# Generated by Django 4.0.3 on 2022-05-22 14:39
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcements'
,
'0002_rename_announcement_name_reaction_announcement'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'reaction'
,
name
=
'announcement'
,
field
=
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'reaction'
,
to
=
'announcements.announcement'
),
),
migrations
.
AlterField
(
model_name
=
'reaction'
,
name
=
'reaction_name'
,
field
=
models
.
CharField
(
choices
=
[(
'Like'
,
'Like'
),
(
'Love'
,
'Love'
),
(
'Angry'
,
'Angry'
)],
default
=
'Like'
,
max_length
=
10
),
),
]
widget_Francoconuts/assignments/forms.py
View file @
cc5eb49e
...
...
@@ -4,4 +4,4 @@ from .views import Assignment
class
AssignmentForm
(
ModelForm
):
class
Meta
:
model
=
Assignment
fields
=
'__all__'
\ No newline at end of file
fields
=
'__all__'
widget_Francoconuts/forum/templates/Forum/forum_detail.html
0 → 100644
View file @
cc5eb49e
<h1>
{{post.post_title}}
</h1>
<h4>
{{post.post_author.first_name}} {{post.post_author.last_name}}, {{post.pub_date.day}}/{{post.pub_date.month}}/{{post.pub_date.year}}
</h4>
<h3>
{{post.post_body}}
</h3>
<img
src=
{{post.post_imageUrl}}
>
<ul>
{% for reply in reply_list %}
{% if reply.reply_post.post_title == post.post_title %}
<li>
<u>
Reply by {{reply.reply_author.first_name}} {{reply.reply_author.last_name}} dated {{reply.pub_date.day}}/{{reply.pub_date.month}}/{{reply.pub_date.year}}:
</u>
<br>
{{reply.reply_body}}
</li>
<br>
{% endif %}
{% endfor %}
</ul>
widget_Francoconuts/forum/templates/Forum/post_list.html
0 → 100644
View file @
cc5eb49e
{% extends 'base.html' %}
{% block content %}
<h1>
Welcome to the Widget's Forum!
</h1>
{% if object_list %}
<ul>
{% for post in object_list %}
<h3>
<li>
<a
href =
"{% url 'forum:forum-detail' post.id %}"
>
{{post.post_title}}
</a>
<br>
by {{post.post_author.first_name}} {{post.post_author.last_name}} dated {{post.pub_date.day}}/{{post.pub_date.month}}/{{post.pub_date.year}}
</li>
</h3>
{% endfor %}
</ul>
{% else %}
<p>
No posts available.
</p>
{% endif %}
{% endblock content %}
widget_Francoconuts/forum/urls.py
View file @
cc5eb49e
from
django.urls
import
path
from
.views
import
forum
from
.views
import
ForumListView
,
ForumDetailView
urlpatterns
=
[
path
(
''
,
forum
,
name
=
'forum'
),
path
(
''
,
ForumListView
.
as_view
(),
name
=
'post-list'
),
path
(
'<int:pk>/details/'
,
ForumDetailView
.
as_view
(),
name
=
'forum-detail'
),
]
app_name
=
'forum'
widget_Francoconuts/forum/views.py
View file @
cc5eb49e
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
Http
404
,
HttpRequest
,
Http
Response
from
.models
import
Post
,
Reply
from
homepage.models
import
WidgetUser
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
CreateView
from
.forms
import
PostForm
def
get_reply
():
text
=
''
for
reply
in
Reply
.
objects
.
all
():
text
+=
(
'Reply by {} {} '
.
format
(
reply
.
author
.
first_name
,
reply
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
reply
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
reply
.
reply_body
)
)
return
text
def
forum
(
request
):
text
=
'<h1>FORUM POSTS:</h1>'
for
post
in
Post
.
objects
.
all
():
text
+=
(
'{} '
.
format
(
post
.
post_title
)
+
'by {} {} '
.
format
(
post
.
author
.
first_name
,
post
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
post
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
post
.
post_body
)
+
get_reply
()
+
'<br>'
)
return
HttpResponse
(
text
)
#def get_reply():
#
# text=''
# for reply in Reply.objects.all():
# text += (
# 'Reply by {} {} '.format(reply.author.first_name,
# reply.author.last_name)
# + 'dated {}').format(reply.pub_date.strftime('%x')
# + ':<br>'
# + '{}<br>'.format(reply.reply_body)
# )
# return text
#
#def forum(request):
#
# text = '<h1>FORUM POSTS:</h1>'
#
# for post in Post.objects.all():
# text += (
# '{} '.format(post.post_title)
# + 'by {} {} '.format(post.author.first_name,
# post.author.last_name)
# + 'dated {}').format(post.pub_date.strftime('%x')
# + ':<br>'
# + '{}<br>'.format(post.post_body)
# + get_reply()
# + '<br>'
# )
#
# return HttpResponse(text)
class
ForumListView
(
ListView
):
model
=
Post
ordering
=
[
"-pub_date"
]
def
index
(
request
):
Replies
=
Reply
.
objects
.
all
()
post_list
=
Post
.
objects
.
order_by
(
"-pub_date"
)
context
=
{
'Post'
:
Posts
,
'Reply'
:
Replies
,
'post_list'
:
post_list
}
return
render
(
request
,
"Forum/forum_detail.html"
,
context
)
class
ForumDetailView
(
DetailView
):
model
=
Post
def
posts
(
request
,
post_id
):
reply_list
=
Reply
.
objects
.
order_by
(
"-pub_date"
)
try
:
post
=
Post
.
objects
.
get
(
pk
=
post_id
)
except
Post
.
DoesNotExist
:
raise
Http404
(
"post doesnt exist"
)
return
render
(
request
,
"Forum/forum_list.html"
,{
"post"
:
post
,
'reply_list'
:
reply_list
})
def
PostCreate
(
request
):
form
=
PostForm
()
context
=
{
'form'
:
form
,
}
if
request
.
method
==
'POST'
:
form
=
PostForm
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'/posts'
)
return
render
(
request
,
'Forum/post_add.html'
,
context
)
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