]> git.parisson.com Git - teleforma.git/commitdiff
fix empty user list 0.5.1
authoryomguy <yomguy@parisson.com>
Mon, 11 Jun 2012 09:24:43 +0000 (11:24 +0200)
committeryomguy <yomguy@parisson.com>
Mon, 11 Jun 2012 09:24:43 +0000 (11:24 +0200)
teleforma/models.py

index 0fc110fcdd263043508a25c0f673bc5caea9c115..a328237b667402f8613847e0e697a283acb4261a 100755 (executable)
@@ -526,12 +526,18 @@ class NamePaginator(object):
         chunks = {}
 
         for obj in self.object_list:
-            if on: obj_str = getattr(obj, on).encode('utf8')
-            else: obj_str = obj.encode('utf8')
+            if on:
+                obj_str = getattr(obj, on).encode('utf8')
+            else:
+                obj_str = obj.encode('utf8')
 
-            letter = str.upper(obj_str[0])
+            if len(obj_str):
+                letter = str.upper(obj_str[0])
+            else:
+                letter = ''
 
-            if letter not in chunks: chunks[letter] = []
+            if letter not in chunks:
+                chunks[letter] = []
 
             chunks[letter].append(obj)
 
@@ -605,8 +611,10 @@ class NamePage(object):
         return self.paginator.pages.index(self) + 1
 
     def add(self, new_list, letter=None):
-        if len(new_list) > 0: self.object_list = self.object_list + new_list
-        if letter: self.letters.append(letter)
+        if len(new_list) > 0:
+            self.object_list = self.object_list + new_list
+        if letter:
+            self.letters.append(letter)
 
     def __repr__(self):
         if self.start_letter == self.end_letter: