Scenario: In DRF I had to write following lines of code to check permission for the user
class RetrieveCampaignListView(APIView) :
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]
def get(self, request , *args, **kwargs):
if request.user.has_perm('campaign.view_campaign'):
try:
#some view code
except:
return Response({"status":False}, status=status.HTTP_404_NOT_FOUND)
else:
return Response({"status":"Sorry User is not permitted"})
But I want to shorten the
request.user.has_perm('campaign.view_camapign') and it's else condition
into something like this.
@check_permission('campaign.view_campaign')
Any Help Would be highly appericiated.