Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_aguandhischipmunks
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
Adrian Lance Damalerio
midterm_aguandhischipmunks
Commits
c034e6a2
Commit
c034e6a2
authored
May 15, 2023
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/forumv2'
parents
6c40e867
f194822d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
149 additions
and
38 deletions
+149
-38
forms.py
widget_aguandhischipmunks/forum/forms.py
+8
-0
models.py
widget_aguandhischipmunks/forum/models.py
+4
-0
forum.html
widget_aguandhischipmunks/forum/templates/forum.html
+31
-0
forumpost-add.html
widget_aguandhischipmunks/forum/templates/forumpost-add.html
+24
-0
forumpost-details.html
...aguandhischipmunks/forum/templates/forumpost-details.html
+28
-0
forumpost-edit.html
...et_aguandhischipmunks/forum/templates/forumpost-edit.html
+12
-0
urls.py
widget_aguandhischipmunks/forum/urls.py
+7
-2
views.py
widget_aguandhischipmunks/forum/views.py
+33
-23
settings.py
..._aguandhischipmunks/widget_aguandhischipmunks/settings.py
+2
-13
No files found.
widget_aguandhischipmunks/forum/forms.py
0 → 100644
View file @
c034e6a2
from
django
import
forms
from
.models
import
ForumPost
class
AddForumPostForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
ForumPost
fields
=
'__all__'
# template to be used by default is called ForumPost_form.html
\ No newline at end of file
widget_aguandhischipmunks/forum/models.py
View file @
c034e6a2
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
# Forum Post
# title; body; author; pub_datetime;
...
...
@@ -11,6 +12,9 @@ class ForumPost(models.Model):
def
__str__
(
self
):
return
self
.
title
def
get_absolute_url
(
self
):
return
reverse
(
'forum:forumpost_details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
# Reply
# body; author; pub_datetime; forum_post;
...
...
widget_aguandhischipmunks/forum/templates/forum.html
0 → 100644
View file @
c034e6a2
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Forum {% endblock %}
{% block content %}
<h1>
Welcome to Widget's Forum!
</h1>
<body>
Forum posts:
{% for post in forumposts %}
<li>
<a
href=
"{{ post.get_absolute_url }}"
>
{{ post.title }} by {{ post.author.last_name }}, {{ post.author.first_name }}
</a>
</li>
{% endfor %}
</body>
<br>
<form
action=
"forumposts/add"
>
<button
type=
"submit"
>
New Post
</button>
</form>
<br>
<li><a
href=
"/dashboard"
>
Dashboard
</a>
<br></li>
<li><a
href=
"/announcements"
>
Announcements
</a>
<br></li>
<li><a
href=
"/assignments"
>
Assignments
</a>
<br></li>
<li><a
href=
"/calendar"
>
Calendar
</a>
<br></li>
{% endblock %}
widget_aguandhischipmunks/forum/templates/forumpost-add.html
0 → 100644
View file @
c034e6a2
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Post {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<p>
Add a new post:
</p>
<form
method =
"post"
>
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{field}}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Save New Post"
>
</form>
{% endblock %}
widget_aguandhischipmunks/forum/templates/forumpost-details.html
0 → 100644
View file @
c034e6a2
{% extends 'base.html'%}
{% block title %}
{{ object.title }}
{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<body>
by {{ object.author.first_name }} {{ object.author.last_name }}
<br>
{{ object.pub_datetime|date:"m/d/Y, h:i A" }}
<br>
{{ object.body }}
<br><br>
POST REPLIES:
<br>
{% for reply in replies %}
{% if reply.forum_post == object %}
by {{ reply.author.first_name }} {{ reply.author.last_name }}
<br>
{{ reply.pub_datetime|date:"m/d/Y, h:i A" }}
<br>
{{ reply.body }}
<br><br>
{% endif %}
{% endfor %}
</body>
<form
action=
"./edit"
>
<button
type=
"submit"
>
Edit Post
</button>
</form>
{% endblock %}
widget_aguandhischipmunks/forum/templates/forumpost-edit.html
0 → 100644
View file @
c034e6a2
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Post {% endblock %}
{% block content %}
<h1>
Edit Post:
</h1>
<form
method=
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
>
Save Changes to Post
</button>
</form>
{% endblock %}
widget_aguandhischipmunks/forum/urls.py
View file @
c034e6a2
...
...
@@ -3,5 +3,10 @@ from . import views
# url for forum
urlpatterns
=
[
path
(
""
,
views
.
forumIndex
,
name
=
"forumIndex"
),
]
\ No newline at end of file
path
(
''
,
views
.
forum_view
,
name
=
"forumposts"
),
path
(
'forumposts/add'
,
views
.
ForumPostCreateView
.
as_view
(),
name
=
"forumpost_add"
),
path
(
'forumposts/<int:pk>/details'
,
views
.
ForumPostDetailView
.
as_view
(),
name
=
'forumpost_details'
),
path
(
'forumposts/<int:pk>/edit'
,
views
.
ForumPostUpdateView
.
as_view
(),
name
=
'forumpost_edit'
),
]
app_name
=
"forum"
\ No newline at end of file
widget_aguandhischipmunks/forum/views.py
View file @
c034e6a2
from
django.http
import
HttpResponse
from
django.shortcuts
import
render
,
redirect
from
django.views.generic
import
DetailView
,
CreateView
,
UpdateView
,
ListView
from
.models
import
ForumPost
,
Reply
# forum view from .models
def
forumIndex
(
request
):
# fetch forum posts and replies
forum
=
ForumPost
.
objects
.
all
()
# dashboard view from .models
def
forum_view
(
request
):
forumposts
=
ForumPost
.
objects
.
all
()
replies
=
Reply
.
objects
.
all
()
forum_output
=
"Widget's Forum <br><br> Forum Posts:<br>"
for
post
in
forum
:
forum_output
=
(
forum_output
+
post
.
title
+
" by "
+
post
.
author
.
first_name
+
" "
+
post
.
author
.
last_name
+
" posted "
+
post
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y,
%
I:
%
M
%
p'
)
+
":<br>"
+
post
.
body
+
"<br>"
)
for
reply
in
replies
:
if
reply
.
forum_post
.
title
==
post
.
title
:
forum_output
=
(
forum_output
+
"Reply by "
+
reply
.
author
.
first_name
+
" "
+
reply
.
author
.
last_name
+
" posted "
+
reply
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y,
%
I:
%
M
%
p'
)
+
":<br>"
+
reply
.
body
+
"<br>"
)
forum_output
=
forum_output
+
"<br>"
return
HttpResponse
(
forum_output
)
return
render
(
request
,
'forum.html'
,
{
'forumposts'
:
forumposts
,
'replies'
:
replies
})
class
ForumPostDetailView
(
DetailView
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'replies'
]
=
Reply
.
objects
.
all
()
return
context
model
=
ForumPost
template_name
=
"forumpost-details.html"
class
ForumPostCreateView
(
CreateView
):
model
=
ForumPost
template_name
=
"forumpost-add.html"
fields
=
"__all__"
class
ForumPostUpdateView
(
UpdateView
):
model
=
ForumPost
template_name
=
"forumpost-edit.html"
fields
=
"__all__"
widget_aguandhischipmunks/widget_aguandhischipmunks/settings.py
View file @
c034e6a2
...
...
@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
from
pathlib
import
Path
import
os
import
os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR
=
Path
(
__file__
)
.
resolve
()
.
parent
.
parent
...
...
@@ -22,7 +23,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
from
decouple
import
config
SECRET_KEY
=
config
(
"SECRET_KEY"
)
SECRET_KEY
=
"django-insecure-z@+iegqn)^k4^=
%
rnr-$3*2+gy&7s1=
%
m$&
%
h!w_k
%
m*h+nl=&"
# SECURITY WARNING: don't run with debug turned on in production!
...
...
@@ -62,17 +63,6 @@ STATIC_URL = '/static/'
STATICFILES_DIRS
=
[
BASE_DIR
/
"static"
]
TEMPLATES
=
[
{
<<<<<<<
HEAD
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)],
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'context_processors'
:
[
'django.template.context_processors.debug'
,
'django.template.context_processors.request'
,
'django.contrib.auth.context_processors.auth'
,
'django.contrib.messages.context_processors.messages'
,
=======
"BACKEND"
:
"django.template.backends.django.DjangoTemplates"
,
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)],
"APP_DIRS"
:
True
,
...
...
@@ -82,7 +72,6 @@ TEMPLATES = [
"django.template.context_processors.request"
,
"django.contrib.auth.context_processors.auth"
,
"django.contrib.messages.context_processors.messages"
,
>>>>>>>
origin
/
calendarv2
],
},
},
...
...
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