def membership_required(function=None):
 def decorator(request, *args, **kwargs):
  group = get_object_or_404(Group, slug=kwargs['slug'])
  if request.user.is_anonymous():
   return HttpResponseRedirect(reverse('django.contrib.auth.views.login'))
  if GroupMember.objects.is_member(group, request.user):
   return function(request, *args, **kwargs)
  else:
   return HttpResponseRedirect(reverse('groups:join', args=[group.slug]))
 return decorator

def membership_required ( function = None ) : def decorator ( request , * args , ** kwargs ) : group = get_object_or_404 ( Group , slug = kwargs [ 'slug' ] ) if request . user . is_anonymous ( ) : return HttpResponseRedirect ( reverse ( 'django.contrib.auth.views.login' ) ) if GroupMember . objects . is_member ( group , request . user ) : return function ( request , * args , ** kwargs ) else : return HttpResponseRedirect ( reverse ( 'groups:join' , args = [ group . slug ] ) ) return decorator
decorator for views that require user to be a member of a group .