Subdomain Posts
None | 1 day ago
None | 1 day ago
None | 1 day ago
None | 2 days ago
None | 2 days ago
None | 2 days ago
None | 2 days ago
None | 2 days ago
None | 11 days ago
None | 11 days ago
Recent Posts
None | 9 sec ago
None | 14 sec ago
Linden Scripting | 17 sec ago
None | 19 sec ago
None | 22 sec ago
None | 28 sec ago
None | 41 sec ago
None | 58 sec ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By deesto on the 4th of Feb 2009 04:41:25 PM Download | Raw | Embed | Report
  1. [root@adminweb04 Announcements]# cat subscribers.py
  2. # -*- coding: utf-8 -*-
  3.  
  4. def isEventTransitionOk(obj, event):
  5.     """check for non-existing state (new objects)."""
  6.     if event.transition is not None:
  7.         return event.transition
  8.     else:
  9.         return False
  10.  
  11. def isObjectTypeOk(obj, event):
  12.     """check for non-existing type (new objects)."""
  13.     if obj.portal_type is not None:
  14.         return obj.portal_type
  15.     else:
  16.         return False
  17.  
  18. def portalMessageModifier(obj, event):
  19.     """custom portal info reminder message;
  20.       this should fire *only* on unpublished announcement objects."""
  21.     ##parameters=state_change
  22.     from Products.CMFCore.utils import getToolByName
  23.     from Products.Archetypes.interfaces import IObjectInitializedEvent,IObjectEditedEvent
  24.     putils = getToolByName(obj, 'plone_utils')
  25.    
  26.     # this condition should catch any *new* announcement object in the process
  27.     # of being created:
  28.     if obj.portal_type=='Announcement' and obj.checkCreationFlag():
  29. #    if obj.checkCreationFlag() and event.transition:
  30.         mymessage=(u"Please note: after you create this announcement, please remember to review and *Publish* it. Email notification will *not* be sent until you change the State of your announcement to *Published*!")
  31.         putils.addPortalMessage(mymessage)
  32.  
  33.     # this condition should catch any *existing* announcement object that
  34.     # has not been published:
  35.     elif obj.portal_type=='Announcement' and event.transition and event.transition.id != 'publish':
  36.         mymessage=(u"Please note: this announcement has been created, but email notification will *not* be sent until you change the State of your announcement to *Published*!")
  37.         putils.addPortalMessage(mymessage)
  38.  
  39.     # this message should be displayed *only* when an announcement object is published:
  40.     elif event.transition and event.transition.id == 'publish':
  41.         mymessage=(u"Thank you. This announcement has been published via email to the specified lists.")
  42.         putils.addPortalMessage(mymessage)
  43.  
  44.     # finally, if the object is not an announcement, *or* if no transition has occured,
  45.     # *or* the object is in the process of being created, nothing should happen!
  46.     else:
  47.         return
  48.  
  49. def emailListListener(obj, event):
  50.     """object state change subscriber; sends email to selected lists; fires on publish."""
  51.     if not event.transition or \
  52.         event.transition.id != 'publish':
  53.         return  
  54.  
  55.     ##parameters=state_change
  56.  
  57.     # get membership info and the mailhost from the server:
  58.     from Products.CMFCore.utils import getToolByName
  59. #    mship = obj.portal_membership
  60.     mship = getToolByName(obj,'portal_membership')
  61.     mhost = obj.MailHost
  62.  
  63.     # get member's email address:
  64. #    from Products.CMFCore.utils import getToolByName
  65.     mymemberinfo = getToolByName(obj,'portal_membership')
  66.     mymember = mymemberinfo.getAuthenticatedMember()
  67.     memail = mymember.getProperty('email')
  68.  
  69.     # set the 'from' address:
  70.     emailFrom = 'RACF Facility Announcements <announce@rcf.rhic.bnl.gov>'
  71.     # grab the object title and set the subject:
  72.     emailSubject = "RACF Facility Announcement: " + obj.Title()
  73.  
  74.     # get the list of To: addresses from the mailingList:
  75.     emailToList = obj.getMailingList()
  76.     # check for member's email in the email list:
  77.     to_list = list(emailToList)
  78.     if '$memail' in to_list:
  79.         to_list.remove('$memail')
  80.         to_list.append(memail)
  81.  
  82.     # get the other object values:
  83.     #
  84.     # get the description field: description is in unicode; decode to UTF8 1st:
  85.     rawDescription = obj.Description().encode('utf-8')
  86.     # affectedAreas is a tuple; get rid of the cruft, and convert it into a string:
  87.     annAreas = str(', '.join(obj.getAffectedArea()))
  88.     # eventType is a tuple; get rid of the cruft, and convert it into a string:
  89.     annType = str(', '.join(obj.getEventType()))
  90.     # experiments is a tuple; get rid of the cruft, and convert it into a string:
  91.     annExperiments = str(', '.join(obj.getExperiments()))
  92.     # get the event start time and convert it into a string:
  93.     rawStartTime = obj.start()
  94.     startTime = str(rawStartTime.strftime('%B %d, %Y, %I:%M %p %Z'))
  95.  
  96.     # for testing; not needed now:
  97.     #import pdb; pdb.set_trace()
  98.  
  99.     # get the event end time and convert it into a string:
  100.     rawEndTime = obj.end()
  101.     endTime = str(rawEndTime.strftime('%B %d, %Y, %I:%M %p %Z'))
  102.  
  103.     # get the object URL, and correct it for site/proxy domain:
  104.     rawAnnUrl = obj.absolute_url()
  105.     annUrl = "https://wwww.racf.bnl.gov/announcements/" + rawAnnUrl.split("/")[-1]
  106.  
  107.     # formulate the message body:
  108.     msg = "Dear computing list subscriber," + "\n\n"
  109.     msg += "A new RACF Computing Facility announcement has been posted:" + "\n" +  obj.Title() + "\n\n"
  110.     # description isn't working at the moment; it seems to get pulled but then stripped out
  111.     # before appearing in email or web object (bad decode function call?):
  112.     msg += "Description: " + "\n" + rawDescription + "\n\n"
  113.     msg += "Duration: " + "\n" + startTime + " - "+ endTime + "\n\n"
  114.     msg += "RACF Group: " + "\n" + obj.getGroupResponsible() + "\n\n"
  115.     msg += "Affected Area(s) of Operations: " + "\n" + annAreas + "\n\n"
  116.     msg += "Affected Experiment Group(s): " + "\n" + annExperiments + "\n\n"
  117.     msg += "Type of event: " + "\n" + annType + "\n\n"
  118.     # get object's main text, and strip its HTML code for emailing:
  119.     msg += "Details: " + "\n" + obj.getText(mimetype="text/plain") + "\n\n"
  120.     msg += "See this message in full on the RACF facility web site: " + "\n" + annUrl + "\n\n"
  121.     msg += "With best regards," + "\n"
  122.     msg += "RACF Site Administration" + "\n"
  123.  
  124.     # finally, send the message:
  125.     mhost.send(msg,to_list,emailFrom,emailSubject)
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: