Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_vincentdjango
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
1
Merge Requests
1
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
Almira Redoble
midterm_vincentdjango
Commits
d56aa856
Commit
d56aa856
authored
Mar 05, 2023
by
shibadisaster
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added view for forum posts
parent
cda4fa9e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
2 deletions
+40
-2
views.cpython-39.pyc
...django/announcementBoard/__pycache__/views.cpython-39.pyc
+0
-0
views.py
widget_vincentdjango/announcementBoard/views.py
+1
-1
models.py
widget_vincentdjango/forum/models.py
+6
-0
views.py
widget_vincentdjango/forum/views.py
+33
-1
No files found.
widget_vincentdjango/announcementBoard/__pycache__/views.cpython-39.pyc
View file @
d56aa856
No preview for this file type
widget_vincentdjango/announcementBoard/views.py
View file @
d56aa856
widget_vincentdjango/forum/models.py
View file @
d56aa856
...
@@ -16,6 +16,9 @@ class ForumPost(models.Model):
...
@@ -16,6 +16,9 @@ class ForumPost(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
def
format_pub_datetime
(
self
):
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
class
Reply
(
models
.
Model
):
class
Reply
(
models
.
Model
):
post
=
models
.
ForeignKey
(
post
=
models
.
ForeignKey
(
ForumPost
,
ForumPost
,
...
@@ -35,3 +38,6 @@ class Reply(models.Model):
...
@@ -35,3 +38,6 @@ class Reply(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
body
return
self
.
body
def
format_pub_datetime
(
self
):
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
widget_vincentdjango/forum/views.py
View file @
d56aa856
# appname/views.py
# appname/views.py
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
ForumPost
,
Reply
from
dashboard.models
import
WidgetUser
def
index
(
request
):
def
index
(
request
):
return
HttpResponse
(
'Hello World! This came from the forum view'
)
head
=
"<h1 style='border-bottom:4px solid lightgray;
\
padding-bottom:30px;
\
font-size:450
%
;'>
\
Widget Forum
\
</h1>"
body
=
"<h2>Forum Posts:</h2>"
for
post
in
ForumPost
.
objects
.
all
():
body
+=
"<div style='border: 2px solid gray; border-radius:5px; padding:20px 30px;'>
\
<b>{}</b> by {} {} posted {}:
\
<br>
\
{}"
.
format
(
post
.
title
,
post
.
author
.
first_name
,
post
.
author
.
last_name
,
post
.
format_pub_datetime
(),
post
.
body
)
for
reply
in
Reply
.
objects
.
all
():
if
reply
.
post
==
post
:
body
+=
"<p style='border: 1px dashed gray; border-radius:5px; padding:20px 30px;'>
\
Reply by {} {} posted {}:
\
<br>
\
{}"
.
format
(
reply
.
author
.
first_name
,
reply
.
author
.
last_name
,
reply
.
format_pub_datetime
(),
reply
.
body
)
body
+=
"</div>"
body
+=
"<p> </p>"
return_string
=
"<html>
\
<body style = 'font-family:helvetica;
\
padding:30px;'>
\
{}{}
\
</body></html>"
.
format
(
head
,
body
)
return
HttpResponse
(
return_string
)
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