Authentication Header not present in DataTable View

Issue #22 invalid
Former user created an issue

I am using this library for datatables in django-rest. Everything is working fine expect request.user session in views. It seems to me django-datatable is not authenticating the user token and therefore request.user returns anonymous user. And the same is accessible even without sending user token in headers.

Here is my code :

class MyDataTableView(BaseDatatableView):
    """
    """
    model = MyModel
    columns = [***columns** ]
    order_columns = [***columns**]

    def get_initial_queryset(self):
        """
        initial queryset for 
        """
        self.request.user -----> returns antonymous user 

        queryset = self.model.objects
        return queryset

I checked for the Authentication header and its not there in request but I am sending the Authentication header like for other requests ->

response = requests.get(api, headers={'Authorization': token_header}, params=request.GET.dict(), verify=True) .

also token_header is present here

self.request.META['HTTP_AUTHORIZATION']

So if I can have request.user available in request , I can easily validate that user.

One more question - Can we user Django permission classes on Datatable Views ?

Comments (5)

  1. Maciej Wisniowski repo owner

    BaseDatatableView class is using Django's TemplateView as it's base so it is aware of any default Django authentication schemas and request.user does work within it.

    In the issue description you're referring to django-rest library that I'm not aware of, but in fact it seems that you're using DjangoRestFramework (please be clear about what you're using). If you're using DjangoRestFramework then, for Authorization header to work, you should be using rest_framework's APIView as base, not TemplateView. In either case it's not django_datatables_view work to handle authentication.

    I'd recommend having a look at: https://bitbucket.org/pigletto/django-datatables-view/src/6bf355f2aa516397c613a3ec9ea647cd8aecac8a/django_datatables_view/base_datatable_view.py?at=master&fileviewer=file-view-default#base_datatable_view.py-250

    As you can see there is a DatatableMixin class that you can use along with APIView. Just call self.get_context_data(kwargs) in your get method (like JSONResponseView** does): https://bitbucket.org/pigletto/django-datatables-view/src/6bf355f2aa516397c613a3ec9ea647cd8aecac8a/django_datatables_view/mixins.py?at=master&fileviewer=file-view-default#mixins.py-51

  2. Log in to comment