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
f9e6a556
Commit
f9e6a556
authored
May 14, 2023
by
enricosuplico
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated forumV2
parent
f1e19060
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
131 additions
and
17 deletions
+131
-17
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
base.html
widget_mgabolanimav/templates/base.html
+14
-0
settings.py
widget_mgabolanimav/widget_mgabolanimav/settings.py
+2
-1
No files found.
widget_mgabolanimav/forum/models.py
View file @
f9e6a556
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 @
f9e6a556
{% 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 @
f9e6a556
{% 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 @
f9e6a556
{% 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 @
f9e6a556
{% 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 @
f9e6a556
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"
),
\ No newline at end of file
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 @
f9e6a556
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'
widget_mgabolanimav/templates/base.html
0 → 100644
View file @
f9e6a556
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<link
rel=
"stylesheet"
href=
"style.css"
>
<title>
{% block title %}{% endblock %}
</title>
{% block styles %}{% endblock %}
</head>
<body>
<div
id=
"content"
>
{% block content %}{% endblock%}
</div>
{% block scripts%}{% endblock%}
</body>
</html>
\ No newline at end of file
widget_mgabolanimav/widget_mgabolanimav/settings.py
View file @
f9e6a556
...
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
...
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
"""
"""
from
pathlib
import
Path
from
pathlib
import
Path
import
os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR
=
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
BASE_DIR
=
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
...
@@ -57,7 +58,7 @@ ROOT_URLCONF = 'widget_mgabolanimav.urls'
...
@@ -57,7 +58,7 @@ ROOT_URLCONF = 'widget_mgabolanimav.urls'
TEMPLATES
=
[
TEMPLATES
=
[
{
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)
],
'APP_DIRS'
:
True
,
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'context_processors'
:
[
'context_processors'
:
[
...
...
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