Use mixin for required login instead of decorators

parent 039a603f
Pipeline #1745 passed with stages
in 2 minutes and 7 seconds
from django.contrib.auth.decorators import login_required
from django.conf.urls import url
from rp.views.articles import ArticleListFlux, ArticleEdit, ArticleDetailView, ArticleList
......@@ -22,32 +21,32 @@ urlpatterns = [
),
url(
r"^article/list/(?P<filter_view>\w+)",
login_required(ArticleListFlux.as_view()),
ArticleListFlux.as_view(),
name="article-list"
),
url(
r"^article/list",
login_required(ArticleListFlux.as_view()),
ArticleListFlux.as_view(),
name="article-list"
),
url(
r"^article/edit/(?P<pk>\d+)",
login_required(ArticleEdit.as_view()),
ArticleEdit.as_view(),
name="article-edit"
),
url(
r"^article/view/(?P<pk>\d+)",
login_required(ArticleDetailView.as_view()),
ArticleDetailView.as_view(),
name="article-view"
),
url(
r"^article/preview/(?P<pk>\d+)",
login_required(ArticleDetailView.as_view(preview=True)),
ArticleDetailView.as_view(preview=True),
name="article-preview"
),
url(
r"^user",
login_required(UserListView.as_view()),
UserListView.as_view(),
name="user-list"
)
]
......@@ -57,7 +57,7 @@ class ArticleList(ListView):
return context
class ArticleListFlux(UDList):
class ArticleListFlux(LoginRequiredMixin, UDList):
model = Article
paginate_by = 10
......@@ -78,7 +78,7 @@ class ArticleListFlux(UDList):
return context
class ArticleDetailView(DetailView):
class ArticleDetailView(LoginRequiredMixin, DetailView):
model = Article
preview = False
......
from django.contrib.auth.models import User
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.views.generic.list import ListView
class UserListView(PermissionRequiredMixin, ListView):
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = User
paginate_by = 20
template_name = 'rp/user_list.html'
......
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