Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
5a5a3ba9
Commit
5a5a3ba9
authored
Oct 09, 2020
by
Azhar Rais
Browse files
[REFACTOR] Refactor duplicate literal
parent
31b4486b
Pipeline
#58018
passed with stages
in 17 minutes and 19 seconds
Changes
2
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
forum/tests.py
View file @
5a5a3ba9
This diff is collapsed.
Click to expand it.
forum/views.py
View file @
5a5a3ba9
...
...
@@ -9,6 +9,9 @@ from django.views.generic.list import MultipleObjectMixin
from
forum.forms
import
DiscussionForm
,
DiscussionCommentForm
from
forum.models
import
Discussion
,
DiscussionComment
URL_FORUM_HOME_PAGE
=
'/forum'
URL_LOGIN_PAGE
=
'/login'
class
ForumHomePage
(
ListView
):
paginate_by
=
10
...
...
@@ -18,9 +21,9 @@ class ForumHomePage(ListView):
class
ForumCreateDiscussion
(
LoginRequiredMixin
,
CreateView
):
form_class
=
DiscussionForm
success_url
=
'/forum'
success_url
=
URL_FORUM_HOME_PAGE
template_name
=
'forum/forum_discussion_create.html'
login_url
=
'/login'
login_url
=
URL_LOGIN_PAGE
def
form_valid
(
self
,
form
):
form
.
instance
.
user
=
self
.
request
.
user
...
...
@@ -35,20 +38,20 @@ class ForumDeleteDiscussion(LoginRequiredMixin, DeleteView):
model
=
Discussion
success_url
=
reverse_lazy
(
'forum_home'
)
template_name
=
'forum/forum_discussion_delete.html'
login_url
=
'/login'
login_url
=
URL_LOGIN_PAGE
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
discussion
=
self
.
get_object
()
if
discussion
.
user
==
request
.
user
:
discussion
.
delete
()
return
redirect
(
'/forum'
)
return
redirect
(
URL_FORUM_HOME_PAGE
)
class
ForumDiscussionDetail
(
FormMixin
,
DetailView
,
MultipleObjectMixin
):
model
=
Discussion
template_name
=
'forum/forum_discussion_detail.html'
form_class
=
DiscussionCommentForm
success_url
=
'/forum'
success_url
=
URL_FORUM_HOME_PAGE
paginate_by
=
20
def
get_success_url
(
self
):
...
...
@@ -82,7 +85,7 @@ class ForumDiscussionDetail(FormMixin, DetailView, MultipleObjectMixin):
class
ForumDiscussionCommentDelete
(
LoginRequiredMixin
,
DeleteView
):
model
=
DiscussionComment
template_name
=
'forum/forum_discussion_delete.html'
login_url
=
'/login'
login_url
=
URL_LOGIN_PAGE
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
discussion_comment
=
self
.
get_object
()
...
...
Write
Preview
Supports
Markdown
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