Ignore:
Timestamp:
7 Oct 2012, 21:52:45 (12 years ago)
Author:
Henrik Bettermann
Message:

Notify all ImportManagers? after csv file upload.

File:
1 edited

Legend:

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

    r9303 r9311  
    2525from urllib import urlencode
    2626from zope import schema
     27from zope.i18n import translate
    2728from zope.authentication.interfaces import (
    2829    IAuthentication, IUnauthenticatedPrincipal, ILogout)
     
    5657    IPasswordValidator, IContactForm, IKofaUtils, ICSVExporter,)
    5758from waeup.kofa.permissions import (
    58     get_users_with_local_roles, get_all_roles, get_all_users)
     59    get_users_with_local_roles, get_all_roles, get_all_users,
     60    get_users_with_role)
    5961
    6062from waeup.kofa.students.catalog import search as searchstudents
     
    836838    cancel_button =_(u'Cancel')
    837839
     840    def _notifyImportManagers(self, normalized_filename):
     841        """Send email to Import Managers
     842        """
     843        kofa_utils = getUtility(IKofaUtils)
     844        import_managers = get_users_with_role(
     845            'waeup.ImportManager', grok.getSite())
     846        rcpt_addrs = ','.join(
     847            [user['user_email'] for user in import_managers if
     848                user['user_email'] is not None])
     849        if rcpt_addrs:
     850            config = grok.getSite()['configuration']
     851            fullname = self.request.principal.title
     852            try:
     853                email = self.request.principal.email
     854            except AttributeError:
     855                email = config.email_admin
     856            username = self.request.principal.id
     857            usertype = getattr(self.request.principal,
     858                               'user_type', 'system').title()
     859            rcpt_name = _('Import Manager')
     860            subject = translate(
     861                      _('${a} Upload', mapping = {'a':config.acronym}),
     862                      'waeup.kofa',
     863                      target_language=kofa_utils.PORTAL_LANGUAGE)
     864            text = _('File ${a} uploaded.', mapping = {'a':normalized_filename})
     865            success = kofa_utils.sendContactForm(
     866                    fullname,email,
     867                    rcpt_name,rcpt_addrs,
     868                    username,usertype,config.name,
     869                    text,subject)
     870            if success:
     871                self.flash(
     872                    _('All import managers have been notified by email.'))
     873            else:
     874                self.flash(_('An smtp server error occurred.'))
     875            return
     876
    838877    def update(self, uploadfile=None, CANCEL=None, SUBMIT=None):
    839878        if CANCEL is not None:
     
    864903            ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    865904            logger.info('%s - uploaded: %s' % (ob_class, target))
     905            self._notifyImportManagers(normalized_filename)
     906
    866907        except IOError:
    867908            self.flash('Error while uploading file. Please retry.')
Note: See TracChangeset for help on using the changeset viewer.