django-wiki / django-nyt

Notification system for Django with batteries included: Email digests, user settings, JSON API
Apache License 2.0
144 stars 47 forks source link

Fix bug with __str__ in python 3 #28

Closed hiasen closed 7 years ago

hiasen commented 7 years ago

The str methods of Settings and Subscription returned bytes when running in python 3 and caused errors because the str function expects (unicode) strings in python 3.

This pull request fixes the bug. I made sure It also works for non-ascii translation strings (russian) in python 2 as mentioned in b1e0b23cd7b4e4e.

The commit also fixes problems in python 2 when the username of a user has non-ascii characters.

This is the code I used to test the bug and bugfix, using the test-project.

# -*- coding: utf-8 -*-
import django.utils.translation
django.utils.translation.activate('ru')

from django.contrib.auth.models import User
u = User.objects.first()
u.username = 'Øystein'
u.save()

from django_nyt.models import Settings, Subscription, Notification
print(Settings.objects.all())
print(Subscription.objects.all())
print(Notification.objects.all())
benjaoming commented 7 years ago

Thank you for fixing this @hiasen :) And wow, Coveralls is still processing this since Oct 26 2016 :)