Changeset 2:108a82defd3e in mailjam for postman/models.py


Ignore:
Timestamp:
May 15, 2012, 2:29:03 AM (13 years ago)
Author:
Francisco de Borja Lopez Rio <borja@…>
Branch:
default
Phase:
public
Message:

Fixed some bugs in the models and mta modules

Added tests for the mta module, including a dummy email that is used for
those tests.

Added an initial version of the Postman class (inside the daemon module). This
class will handle the main execution of the postman daemon, the manager
that will take care of mailing lists management.

Added the structure of folders needed to store json files associated with a given
postman instance.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postman/models.py

    r1 r2  
    33import os
    44from tools import validate_email_address
    5 from storage import JsonStorage
     5from storage import JsonStorage as Storage
    66import config
    77
     
    3838        self.members = members
    3939        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
    4249
    4350    def __repr__(self):
     
    5057        if not 'storage' in self.config.keys():
    5158            self.config['storage'] = os.path.join(config.storage_path,
    52                                                   self.address)
     59                                                  'mailings/')
    5360        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
    5662        if not 'private' in self.config.keys():
    57             self.config['private'] = config.private
     63            self.config['private'] = config.private_mailing
    5864       
    59     def _validate_member_object(self, member):
     65    def _validate_member_object(self, member=None):
    6066        if not isinstance(member, Member):
    6167            raise TypeError(member, ' is not a valid Member instance')
    6268        return member
    6369
    64     def _validate_member(self, member):
     70    def _validate_member(self, member=None):
    6571        member = self._validate_member_object(member)
    6672        return member.address in self.members_addresses()
    6773
    68     def _validate_member_by_address(self, address):
     74    def _validate_member_by_address(self, address=None):
    6975        if not validate_email_address(address):
    7076            raise ValueError(address, ' is not a valid email address')
     
    8187        return True
    8288
    83     def add_member_by_address(self, address):
     89    def add_member_by_address(self, address=None):
    8490        if self._validate_member_by_address(address):
    8591            return False
     
    8894        return True
    8995               
    90     def delete_member(self, member):
     96    def delete_member(self, member=None):
    9197        member = self._validate_member_object(member)
    9298        if not self._validate_member(member):
     
    101107            self.address = data.address
    102108            self.members = data.members
     109            return True
     110        return False
    103111   
    104112    def save(self):
Note: See TracChangeset for help on using the changeset viewer.