Changeset 2:108a82defd3e in mailjam for postman/models.py
- Timestamp:
- May 15, 2012, 2:29:03 AM (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/models.py
r1 r2 3 3 import os 4 4 from tools import validate_email_address 5 from storage import JsonStorage 5 from storage import JsonStorage as Storage 6 6 import config 7 7 … … 38 38 self.members = members 39 39 self.config = config 40 self.storage = JsonStorage(os.path.join(config['storage'], 41 self.address)) 40 self._validate_config() # validate the config parameters 41 self.storage = Storage(os.path.join(self.config['storage'], 42 self.address)) 43 self.archive = Storage(os.path.join(self.config['archive'], 44 self.address)) 45 # try to load data from the storage 46 loaded = self.load() 47 # FIXME: if loaded is False, the storage does not exist, perhaps 48 # this would be a good place to create it for the first time 42 49 43 50 def __repr__(self): … … 50 57 if not 'storage' in self.config.keys(): 51 58 self.config['storage'] = os.path.join(config.storage_path, 52 self.address)59 'mailings/') 53 60 if not 'archive' in self.config.keys(): 54 self.config['archive'] = os.path.join(self.config['storage'], 55 'archive') 61 self.config['archive'] = config.archive_path 56 62 if not 'private' in self.config.keys(): 57 self.config['private'] = config.private 63 self.config['private'] = config.private_mailing 58 64 59 def _validate_member_object(self, member ):65 def _validate_member_object(self, member=None): 60 66 if not isinstance(member, Member): 61 67 raise TypeError(member, ' is not a valid Member instance') 62 68 return member 63 69 64 def _validate_member(self, member ):70 def _validate_member(self, member=None): 65 71 member = self._validate_member_object(member) 66 72 return member.address in self.members_addresses() 67 73 68 def _validate_member_by_address(self, address ):74 def _validate_member_by_address(self, address=None): 69 75 if not validate_email_address(address): 70 76 raise ValueError(address, ' is not a valid email address') … … 81 87 return True 82 88 83 def add_member_by_address(self, address ):89 def add_member_by_address(self, address=None): 84 90 if self._validate_member_by_address(address): 85 91 return False … … 88 94 return True 89 95 90 def delete_member(self, member ):96 def delete_member(self, member=None): 91 97 member = self._validate_member_object(member) 92 98 if not self._validate_member(member): … … 101 107 self.address = data.address 102 108 self.members = data.members 109 return True 110 return False 103 111 104 112 def save(self):
Note:
See TracChangeset
for help on using the changeset viewer.