Commits

Anonymous committed c7b2078

updated 'def __repr__(self)' in examples to make it work with utf-8 characters

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)

Comments (0)

Files changed (4)

docs/main/Auth/Customization.rst

             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):
             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):

docs/main/SQLAlchemy.rst

           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

docs/main/explorequickstart.rst

         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
 .. 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
                           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
 

docs/main/movie_tutorial.rst

         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)