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 ...@@ -9,6 +9,9 @@ from django.views.generic.list import MultipleObjectMixin
from forum.forms import DiscussionForm, DiscussionCommentForm from forum.forms import DiscussionForm, DiscussionCommentForm
from forum.models import Discussion, DiscussionComment from forum.models import Discussion, DiscussionComment
URL_FORUM_HOME_PAGE = '/forum'
URL_LOGIN_PAGE = '/login'
class ForumHomePage(ListView): class ForumHomePage(ListView):
paginate_by = 10 paginate_by = 10
...@@ -18,9 +21,9 @@ class ForumHomePage(ListView): ...@@ -18,9 +21,9 @@ class ForumHomePage(ListView):
class ForumCreateDiscussion(LoginRequiredMixin, CreateView): class ForumCreateDiscussion(LoginRequiredMixin, CreateView):
form_class = DiscussionForm form_class = DiscussionForm
success_url = '/forum' success_url = URL_FORUM_HOME_PAGE
template_name = 'forum/forum_discussion_create.html' template_name = 'forum/forum_discussion_create.html'
login_url = '/login' login_url = URL_LOGIN_PAGE
def form_valid(self, form): def form_valid(self, form):
form.instance.user = self.request.user form.instance.user = self.request.user
...@@ -35,20 +38,20 @@ class ForumDeleteDiscussion(LoginRequiredMixin, DeleteView): ...@@ -35,20 +38,20 @@ class ForumDeleteDiscussion(LoginRequiredMixin, DeleteView):
model = Discussion model = Discussion
success_url = reverse_lazy('forum_home') success_url = reverse_lazy('forum_home')
template_name = 'forum/forum_discussion_delete.html' template_name = 'forum/forum_discussion_delete.html'
login_url = '/login' login_url = URL_LOGIN_PAGE
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
discussion = self.get_object() discussion = self.get_object()
if discussion.user == request.user: if discussion.user == request.user:
discussion.delete() discussion.delete()
return redirect('/forum') return redirect(URL_FORUM_HOME_PAGE)
class ForumDiscussionDetail(FormMixin, DetailView, MultipleObjectMixin): class ForumDiscussionDetail(FormMixin, DetailView, MultipleObjectMixin):
model = Discussion model = Discussion
template_name = 'forum/forum_discussion_detail.html' template_name = 'forum/forum_discussion_detail.html'
form_class = DiscussionCommentForm form_class = DiscussionCommentForm
success_url = '/forum' success_url = URL_FORUM_HOME_PAGE
paginate_by = 20 paginate_by = 20
def get_success_url(self): def get_success_url(self):
...@@ -82,7 +85,7 @@ class ForumDiscussionDetail(FormMixin, DetailView, MultipleObjectMixin): ...@@ -82,7 +85,7 @@ class ForumDiscussionDetail(FormMixin, DetailView, MultipleObjectMixin):
class ForumDiscussionCommentDelete(LoginRequiredMixin, DeleteView): class ForumDiscussionCommentDelete(LoginRequiredMixin, DeleteView):
model = DiscussionComment model = DiscussionComment
template_name = 'forum/forum_discussion_delete.html' template_name = 'forum/forum_discussion_delete.html'
login_url = '/login' login_url = URL_LOGIN_PAGE
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
discussion_comment = self.get_object() discussion_comment = self.get_object()
......
Supports Markdown
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