Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_mgabolanimav
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
Mavrick Jordan Lee
midterm_mgabolanimav
Commits
9eb03f98
Commit
9eb03f98
authored
May 14, 2023
by
Mavrick Jordan Lee
Browse files
Options
Browse Files
Download
Plain Diff
Merged forumv2 to dashboardv2 and announcementsv2.
parents
96536f33
f9e6a556
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
16 deletions
+115
-16
models.py
widget_mgabolanimav/forum/models.py
+12
-0
forum.html
widget_mgabolanimav/forum/templates/forum/forum.html
+19
-0
forumpost-add.html
widget_mgabolanimav/forum/templates/forum/forumpost-add.html
+10
-0
forumpost-details.html
...mgabolanimav/forum/templates/forum/forumpost-details.html
+24
-0
forumpost-edit.html
...et_mgabolanimav/forum/templates/forum/forumpost-edit.html
+10
-0
urls.py
widget_mgabolanimav/forum/urls.py
+8
-3
views.py
widget_mgabolanimav/forum/views.py
+32
-13
No files found.
widget_mgabolanimav/forum/models.py
View file @
9eb03f98
from
django.db
import
models
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
from
django.utils
import
timezone
# Create your models here.
# Create your models here.
...
@@ -12,6 +14,16 @@ class ForumPost(models.Model):
...
@@ -12,6 +14,16 @@ class ForumPost(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
pk
:
self
.
pub_datetime
=
timezone
.
now
()
return
super
()
.
save
(
*
args
,
**
kwargs
)
def
get_absolute_url
(
self
):
return
reverse
(
'forum:forumpost-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reply
(
models
.
Model
):
class
Reply
(
models
.
Model
):
body
=
models
.
TextField
(
default
=
""
,
null
=
True
,)
body
=
models
.
TextField
(
default
=
""
,
null
=
True
,)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
default
=
""
,
null
=
True
,)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
default
=
""
,
null
=
True
,)
...
...
widget_mgabolanimav/forum/templates/forum/forum.html
0 → 100644
View file @
9eb03f98
{% extends 'base.html' %}
{% block title %} Widget's Forum {% endblock %}
{% block content %}
<h1>
Welcome to Widget's Forum!
</h1>
<h3>
Forum Posts:
</h3>
{% for forum in forums %}
<a
href=
"{% url 'forum:forumpost-details' forum.id %}"
>
{{ forum.title }}
by {{ forum.author.first_name }} {{ forum.author.last_name }}
</a>
<br>
{% endfor %}
<br>
<a
href=
"{% url 'forum:forumpost-add' %}"
>
<button>
New Post
</button>
</a>
<br><br>
<a
href=
""
>
Dashboard
</a>
<br>
<a
href=
""
>
Announcements
</a>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/forum/templates/forum/forumpost-add.html
0 → 100644
View file @
9eb03f98
{% extends 'base.html' %}
{% block title %} Add Post {% endblock %}
{% block content %}
<h1>
Add a new post
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"Submit"
value=
"Add Post"
>
</form>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/forum/templates/forum/forumpost-details.html
0 → 100644
View file @
9eb03f98
{% extends 'base.html' %}
{% block title %}{{ forumpost.title }}{% endblock %}
{% block content %}
<h1>
{{ forumpost.title }}
<br>
by {{ forumpost.author.first_name }}
{{ forumpost.author.last_name }}
</h1>
{{ forumpost.pub_datetime }}
<br>
{{ forumpost.body }}
<br>
<br>
Post Replies:
<br>
{% for reply in replies %}
<br>
by {{ reply.author.first_name }}
{{ reply.author.last_name }}
{{ reply.pub_datetime }}
<br>
{{ reply.body }}
<br>
{% endfor %}
<br>
<a
href=
"{% url 'forum:forumpost-edit' object.id %}"
>
<button>
Edit Post
</button>
</a>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/forum/templates/forum/forumpost-edit.html
0 → 100644
View file @
9eb03f98
{% extends 'base.html' %}
{% block title %} Edit Post {% endblock %}
{% block content %}
<h1>
Edit post:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"Submit"
value=
"Save Changes"
>
</form>
{% endblock %}
\ No newline at end of file
widget_mgabolanimav/forum/urls.py
View file @
9eb03f98
from
django.urls
import
path
from
django.urls
import
path
from
.
import
views
from
.
views
import
Forum
,
ForumDetailViews
,
ForumCreateView
,
ForumEditView
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
views
.
forum
,
name
=
"forum"
),
path
(
''
,
Forum
,
name
=
"forum"
),
path
(
'<int:pk>/details/'
,
ForumDetailViews
.
as_view
(),
name
=
"forumpost-details"
),
path
(
'add/'
,
ForumCreateView
.
as_view
(),
name
=
"forumpost-add"
),
path
(
'<int:pk>/edit/'
,
ForumEditView
.
as_view
(),
name
=
"forumpost-edit"
),
]
]
app_name
=
'forum'
\ No newline at end of file
widget_mgabolanimav/forum/views.py
View file @
9eb03f98
from
.models
import
ForumPost
,
Reply
from
.models
import
ForumPost
,
Reply
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.shortcuts
import
render
# Create your views here.
# Create your views here.
def
forum
(
request
):
def
Forum
(
request
):
posts
=
ForumPost
.
objects
.
all
()
forums
=
ForumPost
.
objects
.
order_by
(
"-pub_datetime"
)
replies
=
Reply
.
objects
.
all
()
context
=
{
response
=
"Widget's Forums <br> <br>"
+
"Forum Posts: <br>"
"forums"
:
forums
,
for
post
in
posts
:
}
post_name
=
post
.
author
.
first_name
+
" "
+
post
.
author
.
last_name
response
+=
"<br>"
+
post
.
title
+
" by "
+
post_name
+
" posted "
+
post
.
pub_datetime
.
strftime
(
"
%
a,
%
b
%
d,
%
Y
%
I:
%
M
%
p"
)
+
": <br>"
+
post
.
body
+
"<br>"
return
render
(
request
,
'forum/forum.html'
,
context
)
for
reply
in
replies
:
if
(
post
.
title
==
reply
.
forum_post
.
title
):
reply_name
=
reply
.
author
.
first_name
+
" "
+
reply
.
author
.
last_name
class
ForumDetailViews
(
DetailView
):
response
+=
"Reply by "
+
reply_name
+
" posted "
+
reply
.
pub_datetime
.
strftime
(
"
%
a,
%
b
%
d,
%
Y
%
I:
%
M
%
p"
)
+
": <br>"
+
reply
.
body
+
"<br>"
model
=
ForumPost
template_name
=
'forum/forumpost-details.html'
return
HttpResponse
(
response
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'replies'
]
=
Reply
.
objects
.
filter
(
forum_post
=
self
.
object
)
return
context
class
ForumCreateView
(
CreateView
):
model
=
ForumPost
fields
=
'title'
,
'body'
,
'author'
template_name
=
'forum/forumpost-add.html'
class
ForumEditView
(
UpdateView
):
model
=
ForumPost
fields
=
'title'
,
'body'
,
'author'
template_name
=
'forum/forumpost-edit.html'
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