Expanded the sorting options since my csv files were last, first
authorepage <eopage@byu.net>
Thu, 19 Feb 2009 03:41:28 +0000 (03:41 +0000)
committerepage <eopage@byu.net>
Thu, 19 Feb 2009 03:41:28 +0000 (03:41 +0000)
git-svn-id: file:///svnroot/gc-dialer/trunk@195 c39d3808-3fe2-4d86-a59f-b7f623ee9f21

src/gc_dialer.py
src/views.py

index fada203..31b1887 100755 (executable)
@@ -193,7 +193,7 @@ class Dialcentral(object):
                        evo_backend.EvolutionAddressBook(),
                        file_backend.FilesystemAddressBookFactory(fsContactsPath),
                ]
-               mergedBook = views.MergedAddressBook(addressBooks, views.MergedAddressBook.basic_lastname_sorter)
+               mergedBook = views.MergedAddressBook(addressBooks, views.MergedAddressBook.advanced_lastname_sorter)
                self._contactsView.append(mergedBook)
                self._contactsView.extend(addressBooks)
                self._contactsView.open_addressbook(*self._contactsView.get_addressbooks().next()[0][0:2])
index ecad5d5..d4888f7 100644 (file)
@@ -217,10 +217,28 @@ class MergedAddressBook(object):
 
        @staticmethod
        def null_sorter(contacts):
+               """
+               Good for speed/low memory
+               """
                return contacts
 
        @staticmethod
+       def basic_firtname_sorter(contacts):
+               """
+               Expects names in "First Last" format
+               """
+               contactsWithKey = [
+                       (contactName.rsplit(" ", 1)[0], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
        def basic_lastname_sorter(contacts):
+               """
+               Expects names in "First Last" format
+               """
                contactsWithKey = [
                        (contactName.rsplit(" ", 1)[-1], (contactId, contactName))
                                for (contactId, contactName) in contacts
@@ -228,6 +246,62 @@ class MergedAddressBook(object):
                contactsWithKey.sort()
                return (contactData for (lastName, contactData) in contactsWithKey)
 
+       @staticmethod
+       def reversed_firtname_sorter(contacts):
+               """
+               Expects names in "Last, First" format
+               """
+               contactsWithKey = [
+                       (contactName.split(", ", 1)[-1], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def reversed_lastname_sorter(contacts):
+               """
+               Expects names in "Last, First" format
+               """
+               contactsWithKey = [
+                       (contactName.split(", ", 1)[0], (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @staticmethod
+       def guess_firstname(name):
+               if ", " in name:
+                       return name.split(", ", 1)[-1]
+               else:
+                       return name.rsplit(" ", 1)[0]
+
+       @staticmethod
+       def guess_lastname(name):
+               if ", " in name:
+                       return name.split(", ", 1)[0]
+               else:
+                       return name.rsplit(" ", 1)[-1]
+
+       @classmethod
+       def advanced_firtname_sorter(cls, contacts):
+               contactsWithKey = [
+                       (cls.guess_firstname(contactName), (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
+       @classmethod
+       def advanced_lastname_sorter(cls, contacts):
+               contactsWithKey = [
+                       (cls.guess_lastname(contactName), (contactId, contactName))
+                               for (contactId, contactName) in contacts
+               ]
+               contactsWithKey.sort()
+               return (contactData for (lastName, contactData) in contactsWithKey)
+
 
 class PhoneTypeSelector(object):