Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatatableStructure object has no attribute code #54

Closed
davidfischer-ch opened this issue Jul 23, 2014 · 8 comments
Closed

DatatableStructure object has no attribute code #54

davidfischer-ch opened this issue Jul 23, 2014 · 8 comments

Comments

@davidfischer-ch
Copy link

Simply use {{ datatable }} with Django 1.7+ Python 3.4 and you will get a nice error.

I guess that someone copy-pasted the class StrAndUnicode in utils.py from the project django_countries without actually testing it.

try:
    from django.utils.encoding import StrAndUnicode
except ImportError:
    from django.utils.encoding import python_2_unicode_compatible

    @python_2_unicode_compatible
    class StrAndUnicode:
        def __str__(self):
            return self.code
@danmac-uk
Copy link
Contributor

#45

I briefly tested the patch using one of the Django 1.7 betas and Python
2.7.6. Worked for me, so I decided to share it. I don't use Python 3
with Django, and can't see the error on your screen.

Cheers,

Dan.

On 23/07/14 15:58, David Fischer wrote:

Simply use |{{ datatable }}| with Django 1.7+ Python 3.4 and you will
get a nice error.

I guess that someone copy-pasted the class StrAndUnicode in utils.py
https://github.com/pivotal-energy-solutions/django-datatable-view/blob/master/datatableview/utils.py
from the project django_countries
https://bitbucket.org/mariocesar/django-countries/src/6ec34ad8418aa465aab4d24088afaa1bbb857ad4/django_countries/fields.py
without actually testing it.

|try:
from django.utils.encoding import StrAndUnicode
except ImportError:
from django.utils.encoding import python_2_unicode_compatible

 @python_2_unicode_compatible
 class StrAndUnicode:
     def __str__(self):
         return self.code

|
|


Reply to this email directly or view it on GitHub
#54.

@davidfischer-ch
Copy link
Author

Hello, I think it is quite obvious that the DatatableStructure does not have a "code" attribute.
I will make a pull request with my release that work for me. Please test it or explain me how to run tests,

Please add a tox.ini to this project to make it more easy to run tests + enable Travis CI hook.

@danmac-uk
Copy link
Contributor

Nice job :)

On 23/07/14 19:50, David Fischer wrote:

Hello, I think it is quite obvious that the DatatableStructure does
not have a "code" attribute.
I will make a pull request with my release that work for me. Please
test it or explain me how to run tests,

Please add a tox.ini to this project to make it more easy to run tests

  • enable Travis CI hook.


Reply to this email directly or view it on GitHub
#54 (comment).

@davidfischer-ch
Copy link
Author

You're welcome.

I am lucky to find a project like this one for helping me doing awesome tables :-)

@danmac-uk
Copy link
Contributor

I've only used it briefly so far, but yeah it's a really neat little tool :)

In addition to the previous issue with Django 1.7 that I stumbled
across, at least in my environment, I did have to hack around it with a
little Javascript to make it resize responsively along with the page. If
you're interested I would be happy to share that, although it's not
related directly to this project so I didn't create a pull request.

Cheers,

Dan.

On 23/07/14 20:07, David Fischer wrote:

You're welcome.

I am lucky to find a project like this one for helping me doing
awesome tables :-)


Reply to this email directly or view it on GitHub
#54 (comment).

@davidfischer-ch
Copy link
Author

You're awesome!

I discovered few minutes ago that the table isn't responsive but my website is (thanks to Bootstrap 3).

Eager to see your hack in action!

Thanks,

David

@danmac-uk
Copy link
Contributor

Haha thank you but I'm really not, still relatively new to Python and
Django compared to some :)

All I did was chuck this Javascript in below the table:


var update_size = function() {
$(DataTables_Table_0).css({ width:
$(DataTables_Table_0).parent().width() });
oTable.fnAdjustColumnSizing();
}

$(window).resize(function() {
clearTimeout(window.refresh_size);
window.refresh_size = setTimeout(function() { update_size(); }, 50);

});

I hope I'm safe in thinking it will be self-explanatory to you, but if
not feel free to let me know.

Hope this helps :)

Dan.

On 23/07/14 20:34, David Fischer wrote:

You're awesome!

I discovered few minutes ago that the table isn't responsive but my
website is (thanks to Bootstrap 3).

Eager to see your hack in action!

Thanks,

David


Reply to this email directly or view it on GitHub
#54 (comment).

@tiliv
Copy link
Contributor

tiliv commented Jul 23, 2014

Hey guys, sorry for the Django 1.7 issue. Looks like I confused the outcome of my testing of the code because 1.6 was the latest release and still included the (deprecated) StrAndUnicode import. Failure on my part to look at the pull request more closely than the passing tests!

I appreciate the pull request #55 to correct the issue. I've modified the strategy to avoid the StrAndUnicode base class, though. In the final commit d4bd4a0, I decided to just use the python_2_unicode_compatible utility directly (backported for earlier versions of Django), which is a graceful no-op function on python 3. I feel that this strategy makes Python 3 the first-class citizen in the code, which seems like the right thing to do!

Sorry again for the trouble!

For your convenience, you can run the provided tests using the included example project (it contains a manage.py and working settings.py):

$ cd django-datatable-view
$ datatableview/tests/example_project/manage.py test

You should know though that Django 1.7 changed some stuff about how apps are considered registered (something that is hacked in these tests to provide a separate set of test-only models), so the tests kind of blow up on the 1.7 release candidate right now. I need to sit down and work through that. Tests all pass on python 2 and python 3, if using Django 1.6 or earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants