Changeset 3

Show
Ignore:
Timestamp:
12/10/06 03:49:38 (2 years ago)
Author:
amcgregor
Message:

Removed ControllerMessage? and deprecated KIDMessage.

Location:
trunk/turbomail
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/turbomail/__init__.py

    r2 r3  
    281281                 - The plain and rich properties of the Message class can now 
    282282                   be callables, executed at delivery-time. 
     283                 - Removed ControllerMessage in favor of using the above. 
     284                 - Deprecated use of KIDMessage in favor of the above. 
    283285 
    284286@var _queue: After TurboGears startup within an application which has 
  • trunk/turbomail/message.py

    r2 r3  
    394394                @type variables: dict 
    395395                """ 
     396 
     397                log.warn("Use of KIDMessage is deprecated and will be removed in version 2.1.") 
    396398                 
    397399                self._template = template 
     
    416418                 
    417419                return super(KIDMessage, self)._process() 
    418  
    419 class ControllerMessage(Message): 
    420         """A message that accepts a callable and arguments. 
    421  
    422         Example usage:: 
    423  
    424                 import turbomail 
    425                 message = turbomail.ControllerMessage( 
    426                                 "from@host.com", 
    427                                 "to@host.com", 
    428                                 "Subject", 
    429                                 controller.method, 
    430                                 dict() 
    431                         ) 
    432  
    433         Feel free to set a message.plain content as the controller only 
    434         returns HTML.  If you wish to hand-produce content, use the 
    435         Message class. 
    436          
    437         This class can likely be improved to automatically generate the 
    438         plain text content from processing the HTML, calling two methods, 
    439         or calling a single method with special arguments.  Needs 
    440         discussion. 
    441         """ 
    442  
    443         def __init__(self, sender, recipient, subject, method, variables={}, **kw): 
    444                 """Store the additonal template and variable information. 
    445  
    446                 @param method: Any callable that returns HTML; usually an 
    447                                exposed controller method. 
    448                 @type method: callable 
    449  
    450                 @param variables: A dictionary containing named variables to 
    451                                   pass to the method. 
    452                 @type variables: dict 
    453                 """ 
    454  
    455                 self._method = method 
    456                 self._variables = variables 
    457  
    458                 super(ControllerMessage, self).__init__(sender, recipient, subject, **kw) 
    459  
    460         def _process(self): 
    461                 """Automatically generate the rich text content.""" 
    462  
    463                 data = dict(sender=self.sender, recipient=self.recipient, subject=self.subject) 
    464  
    465                 for (i, j) in self._variables.iteritems(): 
    466                         if callable(j): data[i] = j() 
    467                         else: data[i] = j 
    468  
    469                 self.rich = self._method(**data) 
    470  
    471                 return super(ControllerMessage, self)._process()