Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Last active February 2, 2016 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/b21446eac86d0fdd854b to your computer and use it in GitHub Desktop.
Save sivabudh/b21446eac86d0fdd854b to your computer and use it in GitHub Desktop.
Good or bad code?
class CustomerPortal(LoginRequiredMixin, UserPassesTestMixin, DetailView):
model = Customer
template_name = 'bod/customer_portal.html'
def test_func(self):
user_pk = int(self.kwargs['pk'])
user = self.request.user
is_customer = user.groups.filter(name='Customer').exists()
return is_customer and user.pk == user_pk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment