def __call__(self, *args, **kwargs):
     if not self._loaded:
         self._load_state()
     recipient = kwargs.get('recipient', None)
     if not IMailRecipient.providedBy(recipient):
         recipient = self._recipient_from_request()
     message = MIMEMultipart()
     self._set_headers(message, recipient)
     data = {
         'FROM_NAME' : self.sender.reply_name,
         'FROM_EMAIL' : self.sender.reply_address,
         'DATE_FORMATTED' : self.timefn(self.context.start(),
                                      context=aq_inner(self.context),
                                      request=self.request),
         'TIME_FORMATTED' : self.timefn(self.context.start(),
                                      time_only=True,
                                      context=aq_inner(self.context),
                                      request=self.request),
         'ITEM_TITLE' : self.context.Title(),
         'ITEM_DESCRIPTION' : self.context.Description(),
         'ITEM_URL' : self.context.absolute_url(),
         'RSVP_URL' : self._rsvp_url(),
         }
     body = INVITE_EMAIL_BODY % data
     message.attach(MIMEText(body))
     attachment = MIMEBase('text', 'x-vCalendar')
     attachment.set_payload(self._vcal()) #data
     encoders.encode_base64(attachment)
     attachment.add_header('Content-Disposition',
                           'attachment',
                           filename='event.vcs')
     message.attach(attachment)
     return message.as_string()
Beispiel #2
0
 def __call__(self, *args, **kwargs):
     if not self._loaded:
         self._load_state()
     recipient = kwargs.get('recipient', None)
     if not IMailRecipient.providedBy(recipient):
         recipient = self._recipient_from_request()
     message = MIMEMultipart()
     self._set_headers(message, recipient)
     if HAS_PAE and IEvent.providedBy(self.context):
         accessor = IEventAccessor(self.context)
         timezone = accessor.timezone
         if not timezone:
             timezone = pytz.UTC
         timezone = pytz.timezone(timezone)
         start = accessor.start.astimezone(timezone)  # localtime of event
     else:
         start = self.context.start()
     data = {
         'FROM_NAME' : self.sender.reply_name,
         'FROM_EMAIL' : self.sender.reply_address,
         'DATE_FORMATTED' : self.timefn(
             start,
             context=aq_inner(self.context),
             request=self.request,
             ),
         'TIME_FORMATTED' : self.timefn(
             start,
             time_only=True,
             context=aq_inner(self.context),
             request=self.request,
             ),
         'ITEM_TITLE' : self.context.Title(),
         'ITEM_DESCRIPTION' : self.context.Description(),
         'ITEM_URL' : self.context.absolute_url(),
         'RSVP_URL' : self._rsvp_url(),
         'ATTACH_FMT' : 'A vCal',
         }
     if HAS_PAE and IEvent.providedBy(self.context):
         data['ATTACH_FMT'] = 'An iCalendar (.ics)'
         data['TIME_FORMATTED'] += ' (%s / %s)' % (
             start.tzinfo.tzname(start),
             utc_offset_label(start),
             )
     body = INVITE_EMAIL_BODY % data
     message.attach(MIMEText(body))
     if HAS_PAE and IEvent.providedBy(self.context):
         attachment = MIMEBase('text', 'calendar')
         attachment.set_payload(self._ical()) #data
         encoders.encode_base64(attachment)
         attachment.add_header('Content-Disposition',
                               'attachment',
                               filename='event.ics')
     else:
         attachment = MIMEBase('text', 'x-vCalendar')
         attachment.set_payload(self._vcal()) #data
         encoders.encode_base64(attachment)
         attachment.add_header('Content-Disposition',
                               'attachment',
                               filename='event.vcs')
     message.attach(attachment)
     return message.as_string()