Fakultas Ilmu Komputer UI

Commit 5a5a3ba9 authored by Azhar Rais's avatar Azhar Rais
Browse files

[REFACTOR] Refactor duplicate literal

parent 31b4486b
Pipeline #58018 passed with stages
in 17 minutes and 19 seconds
This diff is collapsed.
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment