Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_nicsbabes
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
Nics De Vega
midterm_nicsbabes
Commits
50c5d084
Commit
50c5d084
authored
May 11, 2023
by
Nics De Vega
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'forumv2'
parents
a124dc97
78a4466b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
150 additions
and
36 deletions
+150
-36
0002_alter_forumpost_pub_datetime_alter_reply_forum_post.py
...02_alter_forumpost_pub_datetime_alter_reply_forum_post.py
+25
-0
models.py
widget_nicsbabes/forum/models.py
+7
-2
forum.html
widget_nicsbabes/forum/templates/forum/forum.html
+32
-0
forumpost-add.html
widget_nicsbabes/forum/templates/forum/forumpost-add.html
+16
-0
forumpost-details.html
...et_nicsbabes/forum/templates/forum/forumpost-details.html
+29
-0
forumpost-edit.html
widget_nicsbabes/forum/templates/forum/forumpost-edit.html
+16
-0
urls.py
widget_nicsbabes/forum/urls.py
+5
-3
views.py
widget_nicsbabes/forum/views.py
+20
-31
No files found.
widget_nicsbabes/forum/migrations/0002_alter_forumpost_pub_datetime_alter_reply_forum_post.py
0 → 100644
View file @
50c5d084
# Generated by Django 4.1.7 on 2023-05-10 11:51
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
django.utils.timezone
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'forum'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'forumpost'
,
name
=
'pub_datetime'
,
field
=
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
),
),
migrations
.
AlterField
(
model_name
=
'reply'
,
name
=
'forum_post'
,
field
=
models
.
ForeignKey
(
default
=
''
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'forum_reply'
,
to
=
'forum.forumpost'
),
),
]
widget_nicsbabes/forum/models.py
View file @
50c5d084
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
class
ForumPost
(
models
.
Model
):
class
ForumPost
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
,
default
=
""
)
title
=
models
.
CharField
(
max_length
=
255
,
default
=
""
)
body
=
models
.
TextField
(
default
=
""
)
body
=
models
.
TextField
(
default
=
""
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
pub_datetime
=
models
.
DateTimeField
()
pub_datetime
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
title
)
return
'{}'
.
format
(
self
.
title
)
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
=
""
)
body
=
models
.
TextField
(
default
=
""
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
pub_datetime
=
models
.
DateTimeField
()
pub_datetime
=
models
.
DateTimeField
()
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
,
default
=
""
)
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
,
default
=
""
,
related_name
=
'forum_reply'
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
body
)
return
'{}'
.
format
(
self
.
body
)
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forum.html
0 → 100644
View file @
50c5d084
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<h1>
Welcome to Widget's Forum!
</h1>
<h2>
Forum Posts:
</h2>
<h3>
{% for object in forum %}
<a
href=
"{{ object.get_absolute_url }}"
>
{{object.title}} by {{object.author.first_name}} {{object.author.last_name}}
</a>
<br>
{% endfor %}
</h3>
<br>
<form
action=
"forumposts/add"
>
<input
type=
"submit"
value=
"Add Post"
>
</form>
<h3>
<a
href=
"../dashboard/"
>
Dashboard
</a>
<br>
<a
href=
"../announcements/"
>
Announcements
</a>
<br>
<a
href=
"../assignments/"
>
Assignments
</a>
<br>
<a
href=
"../calendar/"
>
Calendar
</a>
</h3>
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-add.html
0 → 100644
View file @
50c5d084
{% extends 'base.html' %}
{% load static %}
{% 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=
"Save New Post"
>
</form>
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-details.html
0 → 100644
View file @
50c5d084
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
<h1>
{{object.title}}
</h1>
<h3>
by {{object.author.first_name}} {{object.author.last_name}}
</h3>
<h3>
{{object.pub_datetime|date:'m/d/Y, h:i A'}}
</h3>
<h3>
{{object.body}}
</h3>
<br>
<h2>
POST REPLIES:
</h2>
{% for reply in object.forum_reply.all %}
<h3>
by {{reply.author.first_name}} {{reply.author.last_name}}
</h3>
<h3>
{{reply.pub_datetime|date:'m/d/Y, h:i A'}}
</h3>
<h3>
{{reply.body}}
</h3>
<br>
{% endfor %}
<form
action=
"../edit/"
>
<input
type=
"submit"
value=
"Edit Post"
>
</form>
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-edit.html
0 → 100644
View file @
50c5d084
{% extends 'base.html' %}
{% load static %}
{% 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 to Post"
>
</form>
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/urls.py
View file @
50c5d084
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
(
forum
,
ForumPostDetailView
,
ForumPostCreateView
,
ForumPostUpdateView
)
from
.views
import
index
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
forum
,
name
=
'forum'
),
path
(
'forumposts/<int:pk>/details/'
,
ForumPostDetailView
.
as_view
(),
name
=
'forumpost-details'
),
path
(
'forumposts/add/'
,
ForumPostCreateView
.
as_view
(),
name
=
'forumpost-add'
),
path
(
'forumposts/<int:pk>/edit/'
,
ForumPostUpdateView
.
as_view
(),
name
=
'forumpost-edit'
),
]
]
app_name
=
"forum"
app_name
=
"forum"
\ No newline at end of file
widget_nicsbabes/forum/views.py
View file @
50c5d084
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
ForumPost
,
Reply
from
.models
import
ForumPost
,
Reply
from
dashboard.models
import
WidgetUser
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
def
index
(
request
):
def
forum
(
request
):
return
render
(
request
,
'forum/forum.html'
,
{
'forum'
:
ForumPost
.
objects
.
order_by
(
'-pub_datetime'
)
return_string
=
'<body>'
})
for
post
in
ForumPost
.
objects
.
all
():
class
ForumPostDetailView
(
DetailView
):
post_heading
=
'{} by {} {} posted {}:<br>'
.
format
(
model
=
ForumPost
post
.
title
,
template_name
=
"forum/forumpost-details.html"
post
.
author
.
first_name
,
post
.
author
.
last_name
,
class
ForumPostCreateView
(
CreateView
):
post
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
model
=
ForumPost
)
fields
=
[
'title'
,
'body'
,
'author'
]
post_body
=
'{}<br>'
.
format
(
post
.
body
)
template_name
=
'forum/forumpost-add.html'
post_replies
=
''
class
ForumPostUpdateView
(
UpdateView
):
for
reply
in
Reply
.
objects
.
filter
(
forum_post
=
post
):
model
=
ForumPost
post_replies
+=
'Reply by {} {} posted {}:<br>'
.
format
(
fields
=
[
'title'
,
'body'
,
'author'
]
reply
.
author
.
first_name
,
template_name
=
'forum/forumpost-edit.html'
reply
.
author
.
last_name
,
\ No newline at end of file
reply
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
)
post_replies
+=
'{}<br>'
.
format
(
reply
.
body
)
return_string
+=
post_heading
+
post_body
+
post_replies
+
'<br>'
html_string
=
'<html>{}</html>'
.
format
(
return_string
)
return
HttpResponse
(
'Widget’s Forum<br><br>Forum Posts:<br>'
+
html_string
)
\ 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