1 from functools
import wraps
3 from django
.http
import HttpResponseRedirect
5 from mygpo
.publisher
.models
import PublishedPodcast
8 def require_publisher(protected_view
):
10 def wrapper(request
, *args
, **kwargs
):
12 if not request
.user
.is_authenticated
:
13 return HttpResponseRedirect('/login/')
15 if is_publisher(request
.user
):
16 return protected_view(request
, *args
, **kwargs
)
18 return HttpResponseRedirect('/')
23 def is_publisher(user
):
25 checks if the given user has publisher rights,
26 ie he is either set as the publisher of at least one podcast,
27 or he has the staff flag set
30 if not user
.is_authenticated
:
36 if PublishedPodcast
.objects
.filter(publisher
=user
).exists():