morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
208 stars 64 forks source link

AssertionError: No exception message supplied #1

Closed keniobats closed 3 years ago

keniobats commented 3 years ago

Hello,

I've done everything from readme to build a basic setup but I get the following error:

AssertionError at /denuncia/report_search/ No exception message supplied

Request Method: GET http://localhost:8000/denuncia/report_search/ 3.0.7 AssertionError /Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py in dispatch, line 383 /Users/keniobats/.pyenv/versions/bigeye/bin/python 3.7.4 ['/Users/keniobats/Dev/bigeye', '/Users/keniobats/.pyenv/versions/3.7.4/lib/python37.zip', '/Users/keniobats/.pyenv/versions/3.7.4/lib/python3.7', '/Users/keniobats/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf', '/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/odf'

/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py in dispatch

                return JsonResponse({
                    'html': self.render_row_details(row_id, request),
                    'parent-row-id': row_id,
                })
            response = super(AjaxDatatableView, self).dispatch(request, *args, **kwargs)
        else:
            assert False
            #response = HttpResponse(self.render_table(request))
        return response
    def get_model_admin(self):
        from django.contrib import admin
        if self.model in admin.site._registry:
Variable Value
class <class 'ajax_datatable.views.AjaxDatatableView'>
args ()
kwargs {}
request <WSGIRequest: GET '/denuncia/report_search/'>
self <whistleblower.datatables_views.RegisterAjaxDatatableView object at 0x10f5c7f10>

I have been trying to get around this with no success so any help will be extremely appreciated! Django version: 3.0.7 Python version: 3.7.4

morlandi commented 3 years ago

Thank you @keniobats

For some reason, you're invoking the AjaxDatatableView-derived view directly; this should'n happen: that's why the assert complains.

You need two separate views:

First, an ordinary view which will render an HTML page containing:

- an empty <table id="mytable">
- a javascript code which links this HTML table with the AjaxDatatableView-derived view

Second, a AjaxDatatableView-derived view which will:

- render the initial table layout based on specified columns
- respond to datatables.net requests (as a consequence of the user interaction with the table)

The README is rather old, and didn't explain this clearly. I just revised it; please check again this section:

https://github.com/morlandi/django-ajax-datatable#basic-ajaxdatatableview

I also noticed that there is still a misleading attribute called "template_name" in AjaxDatatableView class; that should be removed: just forget about it ...

Finally, I just added a very minimal working Django project; you might find convenient to start from there:

https://github.com/morlandi/django-ajax-datatable/tree/master/example_minimal

keniobats commented 3 years ago

Hi Mario!

Thanks a lot for your response, your project saved me a lot of work!!!. I was setting up things in the wrong way, so thanks for the explanation.

Now everything works as intended except when I click on the row detail view but can't figure out where the error comes from:

Traceback (most recent call last): File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, *kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(args, kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, *kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py", line 388, in dispatch 'html': self.render_row_details(row_id, request), File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/ajax_datatable/views.py", line 406, in render_row_details obj = self.model.objects.get(pk=pk) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(args, **kwargs) File "/Users/keniobats/.pyenv/versions/bigeye/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get self.model._meta.object_name whistleblower.models.Report.DoesNotExist: Report matching query does not exist.

My column defs are this:

column_defs = [
        AjaxDatatableView.render_row_tools_column_def(),
        {
            'title': 'Usuario','name': 'user__last_name','foreign_field': 'user__last_name', 'max_length' : 15
        }, {
            'title': 'Fecha del hecho','name': 'incident_datetime',
        },{
            'title': 'Causa','name': 'casefile',
        }, {
            'title': 'Lugar del hecho','name': 'address', 'max_length' : 20,
        }, {
            'title': 'Localidad','name': 'locality', 'max_length' : 15,
        }, {
            'title': 'Delito', 'name': 'report_type__type_name', 'foreign_field': 'report_type__type_name',
        }, {
            'title': 'Procedimiento', 'name': 'procedure_type__procedure_name', 'foreign_field': 'procedure_type__procedure_name',
        }, {
            'title': 'Fiscalía', 'name': 'district__district', 'foreign_field': 'district__district',
        },
        {
            'title': 'Jurisdicción', 'name': 'jurisdiction__jurisdictions','foreign_field': 'jurisdiction__jurisdictions',
        },
        {
            'title': 'Descripción', 'name': 'incident_description', 'max_length' : 15
        },
    ]

Thanks a lot for your time and help again. I wish I could help you solve this but I'm not experienced enough (yet) to do it.

You rock man!

morlandi commented 3 years ago

Thank you @keniobats

To have detail row working, you need to add a (possibly hidden) column with Models's PK:

    column_defs = [
        AjaxDatatableView.render_row_tools_column_def(),
        {'name': 'pk', 'visible': False, },
        ...

so the code is able to identify the specific table record