Changeset 2321

Show
Ignore:
Timestamp:
07/12/07 13:17:05 (1 year ago)
Author:
abaumann
Message:

change handling of the 'preferred' attribute to avoid creating
conflicts where possible

  • allow email addresses to be preferred, but only if no telephone
    number is preferred
  • don't arbitrarily select a preferred contact if there is none
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/moto-sync/motosync.py

    r2320 r2321  
    18151815        # create a list [(contacttype, contact, is_pref)] 
    18161816        contacts = [] 
    1817         seen_pref = False # have we already seen a preferred contact? 
     1817        pref_telephone = pref_email = 0 # number of preferred phone/email contacts 
    18181818        for elt in getElementsByTagNames(doc, set(['Telephone', 'EMail']), []): 
    18191819            content = getXMLField(elt, 'Content') 
     1820            is_pref = elt.hasAttribute('Preferred') and elt.getAttribute('Preferred') in ['1', 'true'] 
    18201821            if elt.tagName == 'Telephone': 
    18211822                # filter out any illegal characters from the phone number 
    18221823                content = filter(lambda c: c in TEL_NUM_DIGITS, content) 
     1824                pref_telephone += int(is_pref) 
    18231825                ical_types = elt.getAttribute('Location').split(';') 
    18241826                ical_types.extend(elt.getAttribute('Type').split(';')) 
    1825                 is_pref = elt.hasAttribute('Preferred') and elt.getAttribute('Preferred') in ['1', 'true'] 
    18261827                moto_type = MOTO_CONTACT_DEFAULT 
    18271828                for t in ical_types: 
     
    18311832                        break 
    18321833            else: # email 
    1833                 is_pref = False 
     1834                pref_email += int(is_pref) 
    18341835                moto_type = MOTO_CONTACT_EMAIL 
    1835             contacts.append((moto_type, content, is_pref and not seen_pref)) 
    1836             seen_pref = seen_pref or is_pref 
    1837  
    1838         # if none of the contacts were preffered, make one so 
    1839         if not seen_pref: 
    1840             # arbitrarily mark the first non-email contact as preferred 
    1841             for i in range(len(contacts)): 
    1842                 (moto_type, content, _) = contacts[i] 
    1843                 if moto_type != MOTO_CONTACT_EMAIL: 
    1844                     contacts[i] = (moto_type, content, True) 
    1845                     break 
    1846             else: 
    1847                 # no non-email contacts, so just make the first email preferred 
    1848                 (moto_type, content, _) = contacts[0] 
    1849                 contacts[0] = (moto_type, content, True) 
     1836            contacts.append((moto_type, content, is_pref)) 
    18501837 
    18511838        # process addresses, create a hash from contacttype to address 
     
    18681855        # addresses for which there is no phone number are dropped 
    18691856        for (moto_type, contact, is_pref) in contacts: 
     1857            # the phone will only handle one preferred contact; if both telephone 
     1858            # and email contacts are preferred, make the emails non-preferred 
     1859            if moto_type == MOTO_CONTACT_EMAIL and pref_telephone > 0: 
     1860                is_pref = False 
    18701861            if moto_type == MOTO_CONTACT_EMAIL: 
    18711862                addr = None