Skip to content

Commit

Permalink
updated 'def __repr__(self)' in examples to make it work with utf-8 c…
Browse files Browse the repository at this point in the history
…haracters

When using Unicode Columns with non-ascii characters, we now should not get
UnicodeEncodeError: 'ascii' codec can't encode character ..... in position .... ordinal not in range(128)

--HG--
branch : 2.1
  • Loading branch information
David Pravec committed Mar 27, 2010
1 parent ef76c8c commit 1ca48ef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docs/main/Auth/Customization.rst
Expand Up @@ -172,7 +172,7 @@ quickstart, you should follow the instructions described in this section:
users = relation('User', secondary=user_group_table, backref='groups')
def __repr__(self):
return '<Group: name=%s>' % self.group_name
return (u'<Group: name=%s>' % self.group_name).encode('utf-8')
class User(DeclarativeBase):
Expand All @@ -194,8 +194,8 @@ quickstart, you should follow the instructions described in this section:
created = Column(DateTime, default=datetime.now)
def __repr__(self):
return '<User: email="%s", display name="%s">' % (
self.email_address, self.display_name)
return (u'<User: email="%s", display name="%s">' % (
self.email_address, self.display_name)).encode('utf-8')
@property
def permissions(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/main/SQLAlchemy.rst
Expand Up @@ -161,7 +161,7 @@ oriented way of manipulating your data::
self.description = description

def __repr__(self):
return "<Movie('%s','%s', '%s')>" % (self.title, self.year, self.description)
return (u"<Movie('%s','%s', '%s')>" % (self.title, self.year, self.description)).encode('utf-8')


If you don't define the __init__ method. You will need to update the
Expand Down
8 changes: 4 additions & 4 deletions docs/main/explorequickstart.rst
Expand Up @@ -497,7 +497,7 @@ And then the Group definition::
users = relation('User', secondary=user_group_table, backref='groups')

def __repr__(self):
return '<Group: name=%s>' % self.group_name
return (u'<Group: name=%s>' % self.group_name).encode('utf-8')

def __unicode__(self):
return self.group_name
Expand Down Expand Up @@ -547,8 +547,8 @@ more easily.
.. code-block:: python
def __repr__(self):
return '<User: email="%s", display name="%s">' % (
self.email_address, self.display_name)
return (u'<User: email="%s", display name="%s">' % (
self.email_address, self.display_name)).encode('utf-8')
def __unicode__(self):
return self.display_name or self.user_name
Expand Down Expand Up @@ -672,7 +672,7 @@ simple to understand. And that brings us to the end of our file::
backref='permissions')

def __repr__(self):
return '<Permission: name=%s>' % self.permission_name
return (u'<Permission: name=%s>' % self.permission_name).encode('utf-8')
def __unicode__(self):
return self.permission_name

Expand Down
4 changes: 2 additions & 2 deletions docs/main/movie_tutorial.rst
Expand Up @@ -80,9 +80,9 @@ We'll create a new file "movie.py" in our "model" directory with this content::
genre = relation('Genre',foreign_keys=genre_id )
reviewed = Column(Boolean, nullable=False, default=False )
def __repr__(self):
return "<Movie('%s','%s', '%s')>" % (
return (u"<Movie('%s','%s', '%s')>" % (
self.title, self.year, self.description
)
)).encode('utf-8')
class Genre(DeclarativeBase):
__tablename__ = 'genre'
id = Column(Integer,primary_key=True)
Expand Down

0 comments on commit 1ca48ef

Please sign in to comment.