~doctormo/dexter-rolodex/data-agnostic-cleanup

« back to all changes in this revision

Viewing changes to bin/dexter-server

  • Committer: Martin Owens
  • Date: 2011-01-06 20:07:36 UTC
  • Revision ID: doctormo@gmail.com-20110106200736-t8nf3m5041ec6nqx
Code cleanup, creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
            models.create_tables(self.store)
69
69
            models.update_tables(self.store)
70
70
 
 
71
    def clean_up(self, data):
 
72
        """Cleans up dbus data and replaces 'None'"""
 
73
        if isinstance(data, list):
 
74
            for i in range(len(data)):
 
75
                data[i] = self.clean_up(data[i])
 
76
        elif isinstance(data, dict):
 
77
            for key in data.keys():
 
78
                data[key] = self.clean_up(data[key])
 
79
        elif isinstance(data, basestring):
 
80
            if data.lower().strip() == "none" or not data.strip():
 
81
                return None
 
82
        return data
 
83
 
71
84
    #service methods
72
85
    @dbus.service.method('org.elementary.dexterserver', in_signature='ssssssa(ss)a(ss)aa{ss}a(ss)as', out_signature='i')
73
 
    def CreateContact(self, first_name, middle_name, last_name,
74
 
                      organization, birthday, photo_path, emails,
75
 
                      phones, addresses, imnicks, notes):
76
 
        if first_name == "None":
77
 
            first_name = None
78
 
        if middle_name == "None":
79
 
            middle_name = None
80
 
        if last_name == "None":
81
 
            last_name = None
82
 
        if organization == "None":
83
 
            organization = None
84
 
        if birthday == "None":
85
 
            birthday = None
86
 
        if photo_path == "None":
87
 
            photo_path = None
88
 
        for address in addresses:
89
 
            if address["street"] == "None":
90
 
                address["street"] = None
91
 
            if address["city"] == "None":
92
 
                address["city"] = None
93
 
            if address["state"] == "None":
94
 
                address["state"] = None
95
 
            if address["zip"] == "None":
96
 
                address["zip"] = None
97
 
            if address["type"] == "None":
98
 
                address["type"] = None
99
 
        for note in notes:
100
 
            if note.strip() == u"None" or not note.strip():
101
 
                note = None
102
 
        new_id = utilities.create_new_contact(first_name, middle_name, last_name,
103
 
                      organization, birthday, photo_path, emails,
104
 
                      phones, addresses, imnicks, notes, self.store)
105
 
        self.ContactAdded(self.convert_to_small_dict(self.store.find(models.Contact, models.Contact.id == new_id).one()))
 
86
    def CreateContact(self, *args):
 
87
        # Arguments: first_name, middle_name, last_name,
 
88
        #            organization, birthday, photo_path, emails,
 
89
        #            phones, addresses, imnicks, notes
 
90
        self.clean_up(args)
 
91
        args.append(self.store)
 
92
        new_id = utilities.create_new_contact(*args)
 
93
        model = self.store.find(models.Contact, models.Contact.id == new_id)
 
94
        self.ContactAdded(self.convert_to_small_dict(model.one()))
106
95
        return new_id
107
96
 
108
97
    @dbus.service.method('org.elementary.dexterserver')