Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_casanatics
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
John Aidan Vincent M. Ng
midterm_casanatics
Commits
d749b779
Commit
d749b779
authored
May 12, 2023
by
justin
Browse files
Options
Browse Files
Download
Plain Diff
staging: merged forums
parents
0ebf8de9
f9a34572
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
132 additions
and
29 deletions
+132
-29
0003_alter_reply_forum_post.py
...asanatics/forum/migrations/0003_alter_reply_forum_post.py
+19
-0
0003_alter_reply_forum_post.cpython-310.pyc
...s/__pycache__/0003_alter_reply_forum_post.cpython-310.pyc
+0
-0
models.py
widget_casanatics/forum/models.py
+6
-1
forum.html
widget_casanatics/forum/templates/forum/forum.html
+23
-0
forumpost-add.html
widget_casanatics/forum/templates/forum/forumpost-add.html
+19
-0
forumpost-details.html
...t_casanatics/forum/templates/forum/forumpost-details.html
+25
-0
forumpost-edit.html
widget_casanatics/forum/templates/forum/forumpost-edit.html
+17
-0
urls.py
widget_casanatics/forum/urls.py
+4
-0
views.py
widget_casanatics/forum/views.py
+19
-28
No files found.
widget_casanatics/forum/migrations/0003_alter_reply_forum_post.py
0 → 100644
View file @
d749b779
# Generated by Django 3.2 on 2023-05-08 08:54
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'forum'
,
'0002_rename_forum_reply_forum_post'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'reply'
,
name
=
'forum_post'
,
field
=
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'replies'
,
to
=
'forum.forumpost'
),
),
]
widget_casanatics/forum/migrations/__pycache__/0003_alter_reply_forum_post.cpython-310.pyc
0 → 100644
View file @
d749b779
File added
widget_casanatics/forum/models.py
View file @
d749b779
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
class
ForumPost
(
models
.
Model
):
...
...
@@ -11,9 +12,13 @@ class ForumPost(models.Model):
def
__str__
(
self
):
return
self
.
title
def
get_absolute_url
(
self
):
return
reverse
(
'forum:forumpostdetails'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reply
(
models
.
Model
):
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
)
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
,
related_name
=
"replies"
)
body
=
models
.
CharField
(
max_length
=
1000
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
pub_datetime
=
models
.
DateTimeField
(
"Published Date and Time"
,
auto_now_add
=
True
)
...
...
widget_casanatics/forum/templates/forum/forum.html
0 → 100644
View file @
d749b779
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Forum {% endblock %}
{% block content %}
<h1>
Welcome to Widget's Forum!
</h1>
<h2>
Forum posts:
</h2>
<ul>
{% for post in forumpost %}
<li><a
href=
"{{ post.get_absolute_url }}"
>
{{ post.title }} by {{ post.author.first_name }} {{ post.author.last_name }}
</a></li>
{% endfor %}
</ul>
<form
action=
"./forumpost/add"
>
<button
type=
"Submit"
>
New Post
</button>
</form>
<a
href=
"../dashboard/"
>
Dashboard
</a>
<br>
<a
href=
"../announcements/"
>
Announcements
</a>
<br>
<a
href=
"../assignments/"
>
Assignments
</a>
<br>
<a
href=
"../calendar/"
>
Calendar
</a>
<br>
{% endblock %}
widget_casanatics/forum/templates/forum/forumpost-add.html
0 → 100644
View file @
d749b779
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Post {% endblock %}
{% block content %}
<h1>
Add a new post:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{% for field in form%}
<b>
{{ field.label }}:
</b>
{{ field }}
<br>
<br>
{% endfor %}
<button
type=
"submit"
>
Save New Post
</button>
</form>
{% endblock %}
widget_casanatics/forum/templates/forum/forumpost-details.html
0 → 100644
View file @
d749b779
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<h2>
{{ object.author.first_name }} {{ object.author.last_name }}
</h2>
<h3>
{{ object.pub_datetime|date:"m/d/Y, h:i A" }}
</h3>
<p>
{{ object.body }}
</p>
<br>
Post Replies:
<ul>
{% for reply in object.replies.all %}
<li>
<p>
by {{ reply.author.first_name }} {{ reply.author.last_name }}
</p>
<p>
{{ reply.pub_datetime|date:"m/d/Y, h:i A" }}
</p>
<p>
{{ reply.body }}
</p>
</li>
{% endfor %}
</ul>
<form
action=
"../edit"
>
<button
type=
"Submit"
>
Edit Post
</button>
</form>
{% endblock %}
widget_casanatics/forum/templates/forum/forumpost-edit.html
0 → 100644
View file @
d749b779
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Post {% endblock %}
{% block content %}
<h1>
Edit Post:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{% for field in form%}
<b>
{{ field.label }}:
</b>
{{ field }}
<br><br>
{% endfor %}
<button
type=
"submit"
>
Save Changes to Post
</button>
</form>
{% endblock %}
widget_casanatics/forum/urls.py
View file @
d749b779
...
...
@@ -4,6 +4,10 @@ from . import views
urlpatterns
=
[
path
(
""
,
views
.
forum
,
name
=
"index"
),
path
(
"forumpost/<int:pk>/details/"
,
views
.
ForumDetailView
.
as_view
(),
name
=
"forumpostdetails"
),
path
(
"forumpost/add/"
,
views
.
ForumCreateView
.
as_view
(),
name
=
"forumpostadd"
),
path
(
"forumpost/<int:pk>/edit/"
,
views
.
ForumUpdateView
.
as_view
(),
name
=
"forumpostedit"
),
]
...
...
widget_casanatics/forum/views.py
View file @
d749b779
from
django.http
import
HttpResponse
from
.models
import
ForumPost
from
django.utils
import
timezone
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.shortcuts
import
render
def
forum
(
request
):
context
=
{
"forumpost"
:
ForumPost
.
objects
.
all
()
.
order_by
(
'pub_datetime'
),
}
return
render
(
request
,
'forum/forum.html'
,
context
)
# fetch forum posts and replies
forum
=
ForumPost
.
objects
.
all
()
class
ForumDetailView
(
DetailView
):
model
=
ForumPost
template_name
=
'forum/forumpost-details.html'
forum_view
=
"Widget's Forum <br> <br> Forum Posts:<br>"
for
post
in
forum
:
post_replies
=
post
.
reply_set
.
all
()
localdatetime
=
timezone
.
localtime
(
post
.
pub_datetime
)
forum_view
+=
"""
{} by {} posted {}: <br>
{} <br>
"""
.
format
(
post
.
title
,
post
.
author
,
localdatetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
),
post
.
body
,
)
class
ForumCreateView
(
CreateView
):
model
=
ForumPost
template_name
=
'forum/forumpost-add.html'
fields
=
[
'title'
,
'body'
,
'author'
]
for
reply
in
post_replies
:
localdatetime
=
timezone
.
localtime
(
reply
.
pub_datetime
)
if
reply
.
forum_post
==
post
:
forum_view
+=
"""
Reply by {} posted {}: <br>
{} <br>
"""
.
format
(
reply
.
author
,
localdatetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
),
reply
.
body
,
)
forum_view
+=
"<br>"
return
HttpResponse
(
forum_view
)
class
ForumUpdateView
(
UpdateView
):
model
=
ForumPost
template_name
=
'forum/forumpost-edit.html'
fields
=
[
'title'
,
'body'
,
'author'
]
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