Ignore:
Timestamp:
16 Dec 2011, 07:13:28 (13 years ago)
Author:
Henrik Bettermann
Message:

Seat up a global utility class to ease customization. Transform send_mail function into a utility method.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7335 r7358  
    5050    ILocalRolesAssignable, DuplicationError, IConfigurationContainer,
    5151    ISessionConfiguration, ISessionConfigurationAdd,
    52     IPasswordValidator, IContactForm)
     52    IPasswordValidator, IContactForm, ISIRPUtils)
    5353from waeup.sirp.permissions import get_users_with_local_roles, get_all_roles
    5454from waeup.sirp.students.catalog import search as searchstudents
     
    5858from waeup.sirp.widgets.restwidget import ReSTDisplayWidget
    5959from waeup.sirp.authentication import get_principal_role_manager
    60 from waeup.sirp.utils.helpers import get_user_account, send_mail
     60from waeup.sirp.utils.helpers import get_user_account
    6161from waeup.sirp.browser.layout import jsaction, JSAction
    6262
     
    228228        email_to = self.config.email_admin
    229229        subject = self.config.email_subject
    230         success = send_mail(fullname,username,usertype,self.config.name,
    231                   body,email_from,email_to,subject)
     230        sirp_utils = getUtility(ISIRPUtils)
     231        success = sirp_utils.sendMail(fullname,username,usertype,
     232                  self.config.name,body,email_from,email_to,subject)
    232233        if success:
    233234            self.flash('Your message has been sent.')
     
    252253        subject = self.config.email_subject
    253254        usertype = u'Anonymous'
    254         success = send_mail(fullname,username,usertype,self.config.name,
    255                   body,email_from,email_to,subject)
     255        sirp_utils = getUtility(ISIRPUtils)
     256        success = sirp_utils.sendMail(fullname,username,usertype,
     257                  self.config.name,body,email_from,email_to,subject)
    256258        if success:
    257259            self.flash('Your message has been sent.')
     
    476478        email_to = self.context.email
    477479        subject = self.config.email_subject
    478         success = send_mail(fullname,username,usertype,self.config.name,
    479                   body,email_from,email_to,subject)
     480        sirp_utils = getUtility(ISIRPUtils)
     481        success = sirp_utils.sendMail(fullname,username,usertype,
     482                  self.config.name,body,email_from,email_to,subject)
    480483        if success:
    481484            self.flash('Your message has been sent.')
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7323 r7358  
    140140        return value
    141141
     142class ISIRPUtils(Interface):
     143    """A collection of methods which are subject to customization.
     144    """
     145    def sendMail(fullname,username,usertype,portal,body,email_from,email_to,subject):
     146        """Send an email with data provided by forms.
     147        """
     148
    142149class ISIRPObject(Interface):
    143150    """A SIRP object.
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7357 r7358  
    4040from waeup.sirp.browser.layout import jsaction, JSAction
    4141from waeup.sirp.interfaces import (
    42     ISIRPObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm)
     42    ISIRPObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm,
     43    ISIRPUtils)
    4344from waeup.sirp.widgets.datewidget import (
    4445    FriendlyDateWidget, FriendlyDateDisplayWidget,
     
    6061from waeup.sirp.applicants.interfaces import IApplicantBaseData
    6162from waeup.sirp.hostels.hostel import NOT_OCCUPIED
    62 from waeup.sirp.utils.helpers import send_mail
    6363
    6464def write_log_message(view, message):
     
    393393        subject = data['subject']
    394394        email_to = self.context.email
    395         success = send_mail(fullname,username,usertype,self.config.name,
     395        sirp_utils = getUtility(ISIRPUtils)
     396        success = sirp_utils.sendMail(fullname,username,usertype,self.config.name,
    396397                  body,email_from,email_to,subject)
    397398        if success:
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7319 r7358  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
    18 """General helper functions for the student section.
     18"""General helper functions and utilities for the student section.
    1919"""
    2020import grok
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r7321 r7358  
    480480    account = authenticator.getAccount(principal_id)
    481481    return account
    482 
    483 def send_mail(fullname,username,usertype,portal,body,email_from,email_to,subject):
    484     """Send an email with data provided by forms.
    485     """
    486     config = grok.getSite()['configuration']
    487     text = """Fullname: %s
    488 User Id: %s
    489 User Type: %s
    490 Portal: %s
    491 
    492 %s
    493 """
    494     msg = MIMEText(text % (fullname,username,usertype,portal,body))
    495     msg['From'] = '%s <%s>' % (fullname,email_from)
    496     msg['To'] = email_to
    497     msg['Subject'] = subject
    498     server = smtplib.SMTP(config.smtp_server)
    499     if config.smtp_requires_login:
    500         server.login(config.smtp_username,config.smtp_password)
    501     try:
    502         server.sendmail(email_from,email_to,msg.as_string())
    503     except:
    504         return False
    505     server.quit()
    506     return True
Note: See TracChangeset for help on using the changeset viewer.