richardbarran / django-photologue

A customizable plug-in photo gallery management application for the Django web framework.
BSD 3-Clause "New" or "Revised" License
676 stars 238 forks source link

How to use @login_reqired decorator to the "class GalleryArchiveIndexView" #163

Closed JackTheMico closed 8 years ago

JackTheMico commented 8 years ago

Hello! First of all , thank you for making such wonderfull App.

Here is my problem: usually , the code in view.py is like this below

@login_required
def logout(request):
    staticClass.value = None
    auth.logout(request)
    blogs = Blog.objects.all()
    tags = Tag.objects.all()
    return render(request,'sblog/blog_list.html',{"blogs":blogs,"tags":tags})

It is a method.
But in photologue's view.py its like :

class GalleryDateDetailView(GalleryDateView, DateDetailView):
    pass

class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView):
    pass

class GalleryDayArchiveView(GalleryDateView, DayArchiveView):
    pass

class GalleryMonthArchiveView(GalleryDateView, MonthArchiveView):

They're all "class" !!! 囧rz Here comes the question , How can I use "@login_required" to such class ? I have no idea , please help me out .

nim65s commented 8 years ago

Hi,

For classes, you can't use decorators, but you can use mixins, like this one for required login: https://docs.djangoproject.com/fr/1.10/topics/auth/default/#the-loginrequired-mixin

JackTheMico commented 8 years ago

Thanks ! It will solve my problem properly , I'm going to close this issue.