def _is_staff(request, *args, **kwargs): if not request.user.is_authenticated(): return login_required(view_func)(request, *args, **kwargs) elif is_staff(request, request.user): return view_func(request, *args, **kwargs) else: raise PermissionDenied
def get_staff_profile(request): user = request.user if is_staff(user): staff = Staff.objects.get(user=user) staff_profile = StaffProfile.objects.get(staff=staff) staff_serializer = StaffSerializer(staff) profile_serializer = StaffProfileSerializer(staff_profile) if profile_serializer.data['avatar']: return Response({ "staff": staff_serializer.data, "avatar": profile_serializer.data['avatar'] }) else: return Response({"staff": staff_serializer.data, "avatar": None}) else: return Response({"You don't have permissions for this action"})
def get_context_data(self, **ctx): if self.object.is_moderable_by(self.request.user): vote = Vote.objects.filter(talk=self.object, user=self.request.user).first() ctx.update(edit_perm=True, moderate_perm=True, vote=vote, form_url=reverse('talk-conversation', kwargs={'talk': self.object.slug})) else: ctx['edit_perm'] = self.object.is_editable_by(self.request.user) if is_staff(self.request, self.request.user): ctx.update(base_template='staff.html') else: ctx.update(base_template='base.html') return super().get_context_data(**ctx)
def staff(request): return is_staff(request, request.user)