Ejemplo n.º 1
0
 def emailUsers(self, subject, body):
     """ Send an email to all users subscribed to given category. """
     mdh_ob = MDH()
     site = self.getSite()
     for user, fname, lname, email, instant, lang in self.getFlashUsers():
         mdh_ob.sendFlashEmail(body, body, email, site.mail_address_from,
                               subject)
Ejemplo n.º 2
0
    def instantTrigger(self, uid):
        """
        Used by cron tools to trigger instant notification.

        @param uid: site uid
        @type uid: string
        """
        if uid == self.get_site_uid():
            htmls = {}
            if self.notif_cache:
                #grab all the items
                self.notif_cache = self.clean_duplicates(self.notif_cache)
                #get the objects
                items_obj = []
                for item in self.notif_cache:
                    try:
                        items_obj.append(self.unrestrictedTraverse(item))
                    except KeyError:
                        pass
                xmls_html = self.instant_xml(items_obj, 'html')
                xmls_text = self.instant_xml(items_obj, 'text')
                htmls = {}
                for lang, xml in xmls_html.items():
                    #generate htmls
                    htmls[lang] = [self.instant_html(xml, 'html', lang)]
                for lang, xml in xmls_text.items():
                    #generate texts
                    htmls[lang].append(self.instant_html(xml, 'text', lang))
                #send notifications
                if htmls:
                    #at least one item
                    mdh_ob = MDH()
                    site = self.getSite()
                    authtool_ob = site.getAuthenticationTool()

                    for profile in site.getProfilesTool().getProfiles():
                        sheet_ob = profile.getSheetById(
                            self.getInstanceSheetId())
                        if sheet_ob.notify == 1:
                            #the user wants to receive instant notification
                            if sheet_ob.language in htmls.keys():
                                #get user
                                user = authtool_ob.getUser(profile.id)
                                #send email
                                html, text = htmls[sheet_ob.language]
                                mdh_ob.sendFlashEmail(
                                    html, text, '*****@*****.**',
                                    site.mail_address_from,
                                    'SEMIDE eFlash instant notification')
                    #clear cache
                    self.emptyNotifCache()
            return "e-Flash notification sent successfully"
Ejemplo n.º 3
0
    def instantTrigger(self, uid):
        """
        Used by cron tools to trigger instant notification.

        @param uid: site uid
        @type uid: string
        """
        if uid==self.get_site_uid():
            htmls = {}
            if self.notif_cache:
                #grab all the items
                self.notif_cache = self.clean_duplicates(self.notif_cache)
                #get the objects
                items_obj = []
                for item in self.notif_cache:
                    try:
                        items_obj.append(self.unrestrictedTraverse(item))
                    except KeyError:
                        pass
                xmls_html = self.instant_xml(items_obj, 'html')
                xmls_text = self.instant_xml(items_obj, 'text')
                htmls = {}
                for lang, xml in xmls_html.items():
                    #generate htmls
                    htmls[lang] = [self.instant_html(xml, 'html', lang)]
                for lang, xml in xmls_text.items():
                    #generate texts
                    htmls[lang].append(self.instant_html(xml, 'text', lang))
                #send notifications
                if htmls:
                    #at least one item
                    mdh_ob = MDH()
                    site = self.getSite()
                    authtool_ob = site.getAuthenticationTool()

                    for profile in site.getProfilesTool().getProfiles():
                        sheet_ob = profile.getSheetById(self.getInstanceSheetId())
                        if sheet_ob.notify == 1:
                            #the user wants to receive instant notification
                            if sheet_ob.language in htmls.keys():
                                #get user
                                user = authtool_ob.getUser(profile.id)
                                #send email
                                html, text = htmls[sheet_ob.language]
                                mdh_ob.sendFlashEmail(html, text, '*****@*****.**', site.mail_address_from, 'SEMIDE eFlash instant notification')
                    #clear cache
                    self.emptyNotifCache()
            return "e-Flash notification sent successfully"
Ejemplo n.º 4
0
    def mainTrigger(self, uid, now=0):
        """
        Used by cron tools to trigger the eFlash notification.

        @param uid: site uid
        @type uid: string
        """
        if uid==self.get_site_uid():
            archive = self.getFlashArchive()
            #check if this is the notification day
            today = self.utGetTodayDate()
            if (today.year() == self.notif_date.year() and \
                today.month() == self.notif_date.month() and \
                today.day() == self.notif_date.day()) or now:
                #start sending eFlash
                d = {}
                mdh_ob = MDH()
                site = self.getSite()
                auth_tool = site.getAuthenticationTool()
                for profile in site.getProfilesTool().getProfiles():
                    sheet_ob = profile.getSheetById(self.getInstanceSheetId())
                    if sheet_ob.language in self.langs:
                        #get user
                        user = auth_tool.getUser(profile.id)
                        if archive is not None:
                            try:
                                #get eFlash documents
                                html = archive._getOb('%s_html' % self.lastflashdate).getLocalProperty('body', sheet_ob.language)
                                text = archive._getOb('%s_text' % self.lastflashdate).getLocalProperty('body', sheet_ob.language)
                            except AttributeError:
                                if self.generate_flash():
                                    #get eFlash documents
                                    html = archive._getOb('%s_html' % self.lastflashdate).getLocalProperty('body', sheet_ob.language)
                                    text = archive._getOb('%s_text' % self.lastflashdate).getLocalProperty('body', sheet_ob.language)
                            try:
                                #send email
                                mdh_ob.sendFlashEmail(html, text, user.email, site.mail_address_from, self.title)
                            except:
                                pass
                #approve the html version of the eFlash
                try:
                    mesg = archive._getOb('%s_html' % self.lastflashdate)
                    mesg.title = 'Flash sent on %s' % self.utShowDateTime(self.utGetTodayDate())
                    mesg.approveThis()
                except AttributeError:
                    pass
                #delete the text version of the eFlash
                try:
                    archive.manage_delObjects('%s_text' % self.lastflashdate)
                except:
                    pass
                #update parameters

                #increment the news interval
                self.news_start_date = self.notif_date
                self.news_end_date = self.notif_date + 30

                #increment the event interval
                self.event_start_date = self.notif_date
                self.event_end_date = self.notif_date + 30

                #increment the documents interval
                self.doc_start_date = self.notif_date
                self.doc_end_date = self.notif_date + 30

                #increment the notification date
                self.notif_date = self.notif_date + 30

                self._p_changed = 1
            else:
                #check for admin notification date
                notif_admin_date = self.notif_date - self.notif_admin
                if today.year() == notif_admin_date.year() and \
                    today.month() == notif_admin_date.month() and \
                    today.day() == notif_admin_date.day():
                    #send email to administrator
                    #step 1: generate eFlash
                    self.generate_flash()
                    #step 2: send email
                    self.adminNotification()
            return "e-Flash notification sent successfully"
Ejemplo n.º 5
0
 def emailUsers(self, subject, body):
     """ Send an email to all users subscribed to given category. """
     mdh_ob = MDH()
     site = self.getSite()
     for user, fname, lname, email, instant, lang in self.getFlashUsers():
         mdh_ob.sendFlashEmail(body, body, email, site.mail_address_from, subject)
Ejemplo n.º 6
0
    def mainTrigger(self, uid, now=0):
        """
        Used by cron tools to trigger the eFlash notification.

        @param uid: site uid
        @type uid: string
        """
        if uid == self.get_site_uid():
            archive = self.getFlashArchive()
            #check if this is the notification day
            today = self.utGetTodayDate()
            if (today.year() == self.notif_date.year() and \
                today.month() == self.notif_date.month() and \
                today.day() == self.notif_date.day()) or now:
                #start sending eFlash
                d = {}
                mdh_ob = MDH()
                site = self.getSite()
                auth_tool = site.getAuthenticationTool()
                for profile in site.getProfilesTool().getProfiles():
                    sheet_ob = profile.getSheetById(self.getInstanceSheetId())
                    if sheet_ob.language in self.langs:
                        #get user
                        user = auth_tool.getUser(profile.id)
                        if archive is not None:
                            try:
                                #get eFlash documents
                                html = archive._getOb(
                                    '%s_html' %
                                    self.lastflashdate).getLocalProperty(
                                        'body', sheet_ob.language)
                                text = archive._getOb(
                                    '%s_text' %
                                    self.lastflashdate).getLocalProperty(
                                        'body', sheet_ob.language)
                            except AttributeError:
                                if self.generate_flash():
                                    #get eFlash documents
                                    html = archive._getOb(
                                        '%s_html' %
                                        self.lastflashdate).getLocalProperty(
                                            'body', sheet_ob.language)
                                    text = archive._getOb(
                                        '%s_text' %
                                        self.lastflashdate).getLocalProperty(
                                            'body', sheet_ob.language)
                            try:
                                #send email
                                mdh_ob.sendFlashEmail(html, text, user.email,
                                                      site.mail_address_from,
                                                      self.title)
                            except:
                                pass
                #approve the html version of the eFlash
                try:
                    mesg = archive._getOb('%s_html' % self.lastflashdate)
                    mesg.title = 'Flash sent on %s' % self.utShowDateTime(
                        self.utGetTodayDate())
                    mesg.approveThis()
                except AttributeError:
                    pass
                #delete the text version of the eFlash
                try:
                    archive.manage_delObjects('%s_text' % self.lastflashdate)
                except:
                    pass
                #update parameters

                #increment the news interval
                self.news_start_date = self.notif_date
                self.news_end_date = self.notif_date + 30

                #increment the event interval
                self.event_start_date = self.notif_date
                self.event_end_date = self.notif_date + 30

                #increment the documents interval
                self.doc_start_date = self.notif_date
                self.doc_end_date = self.notif_date + 30

                #increment the notification date
                self.notif_date = self.notif_date + 30

                self._p_changed = 1
            else:
                #check for admin notification date
                notif_admin_date = self.notif_date - self.notif_admin
                if today.year() == notif_admin_date.year() and \
                    today.month() == notif_admin_date.month() and \
                    today.day() == notif_admin_date.day():
                    #send email to administrator
                    #step 1: generate eFlash
                    self.generate_flash()
                    #step 2: send email
                    self.adminNotification()
            return "e-Flash notification sent successfully"