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
7ee9735c
Commit
7ee9735c
authored
May 10, 2023
by
Tanya Yotoko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created branch forumv2, initialized templates, edited views.py, urls.py and models.py
parent
cd772cb6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
30 deletions
+50
-30
models.py
widget_nicsbabes/forum/models.py
+6
-1
forum.html
widget_nicsbabes/forum/templates/forum/forum.html
+5
-0
forumpost-add.html
widget_nicsbabes/forum/templates/forum/forumpost-add.html
+5
-0
forumpost-details.html
...et_nicsbabes/forum/templates/forum/forumpost-details.html
+5
-0
forumpost-edit.html
widget_nicsbabes/forum/templates/forum/forumpost-edit.html
+5
-0
urls.py
widget_nicsbabes/forum/urls.py
+8
-4
views.py
widget_nicsbabes/forum/views.py
+16
-25
No files found.
widget_nicsbabes/forum/models.py
View file @
7ee9735c
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
from
django.utils
import
timezone
class
ForumPost
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
,
default
=
""
)
body
=
models
.
TextField
(
default
=
""
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
pub_datetime
=
models
.
DateTimeField
()
pub_datetime
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
title
)
def
get_absolute_url
(
self
):
return
reverse
(
"forum:forumpost-details"
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reply
(
models
.
Model
):
body
=
models
.
TextField
(
default
=
""
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
...
...
widget_nicsbabes/forum/templates/forum/forum.html
0 → 100644
View file @
7ee9735c
{% extends 'base.html' %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-add.html
0 → 100644
View file @
7ee9735c
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block content %}
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-details.html
0 → 100644
View file @
7ee9735c
{% extends 'base.html' %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/templates/forum/forumpost-edit.html
0 → 100644
View file @
7ee9735c
{% extends 'base.html' %}
{% block title %}Edit Post{% endblock %}
{% block content %}
{% endblock %}
\ No newline at end of file
widget_nicsbabes/forum/urls.py
View file @
7ee9735c
from
django.urls
import
path
from
.views
import
index
from
.views
import
(
forum
,
ForumPostDetailView
,
ForumPostCreateView
,
ForumPostUpdateView
)
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"
widget_nicsbabes/forum/views.py
View file @
7ee9735c
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
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
forum
(
request
):
return
render
(
request
,
'forum/forum.html'
,
{
'forum'
:
ForumPost
.
objects
.
order_by
(
'-pub_datetime'
)
})
def
index
(
request
):
class
ForumPostDetailView
(
DetailView
):
model
=
ForumPost
template_name
=
"forum/forumpost-details.html"
return_string
=
'<body>'
for
post
in
ForumPost
.
objects
.
all
():
class
ForumPostCreateView
(
CreateView
):
model
=
ForumPost
fields
=
[
'title'
,
'body'
,
'author'
]
template_name
=
'forum/forumpost-add.html'
post_heading
=
'{} by {} {} posted {}:<br>'
.
format
(
post
.
title
,
post
.
author
.
first_name
,
post
.
author
.
last_name
,
post
.
pub_datetime
.
strftime
(
"
%
m/
%
d/
%
Y,
%
I:
%
M
%
p"
)
)
post_body
=
'{}<br>'
.
format
(
post
.
body
)
post_replies
=
''
class
ForumPostUpdateView
(
UpdateView
):
model
=
ForumPost
fields
=
[
'title'
,
'body'
,
'author'
]
template_name
=
'forum/forumpost-edit.html'
for
reply
in
Reply
.
objects
.
filter
(
forum_post
=
post
):
post_replies
+=
'Reply by {} {} posted {}:<br>'
.
format
(
reply
.
author
.
first_name
,
reply
.
author
.
last_name
,
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