<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

fiber_request = state_change[\'object\']\n
portal = state_change.getPortal()\n
support = portal.WebSite_getSupportEntity()\n
\n
if fiber_request.getGenderValue() is None:\n
  raise ValueError, "Gender must be set"\n
\n
#We get notification message as text of email\n
notification_reference = \'vifib.fiber-request.confirm\'\n
notification_message = context.NotificationTool_getDocumentValue(notification_reference,language=fiber_request.getLanguage())\n
mapping_dict = {\'customer_name\':fiber_request.getTitle()}\n
mail_text = notification_message.asText(\n
  substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
mail_title = notification_message.getTitle()\n
mail_format = notification_message.getTextFormat()\n
\n
\n
#We get notification message as contract\n
notification_reference = \'vifib.fiber-hosting.contract\'\n
notification_message = context.NotificationTool_getDocumentValue(notification_reference, fiber_request.getLanguage())\n
\n
#the method asText except AttributeError and so we can send pdf with error. \n
#We simulate the generation of it to bu sure we don\'t get error\n
method_id = notification_message.getTextContentSubstitutionMappingMethodId()\n
if method_id:\n
  mapping = getattr(fiber_request,method_id)(fiber_request=fiber_request)\n
\n
\n
contract_text = notification_message.asText(\n
  substitution_method_parameter_dict={\'fiber_request\':fiber_request})\n
\n
#create temp document to generate a pdf\n
\n
# Generate the pdf data\n
module = portal.getDefaultModule(portal_type=\'Web Page\')\n
\n
# Generate the pdf data\n
pdf_data = module.newContent(portal_type="Web Page",\n
                             temp_object= 1,\n
                             text_format = notification_message.getTextFormat())\n
\n
# Build the text and save it\n
if pdf_data.getTextFormat() == \'text/html\':\n
  text_content = \'<html><body>%s</body></html>\' % contract_text\n
else:\n
  text_content = contract_text\n
pdf_data.setTextContent(text_content)\n
\n
# Create the pdf document in the mode\n
#TODO : use ingestion_tool instead of\n
module = portal.getDefaultModule(portal_type=\'PDF\')\n
pdf = module.newContent(\n
    portal_type=\'PDF\',\n
    data=str(pdf_data.convert(format=\'pdf\')[1]),\n
    content_type=\'application/pdf\'\n
)\n
pdf.setFollowUpValue(fiber_request)\n
reference = \'%s-%s.pdf\' % (notification_reference,fiber_request.getId())\n
pdf.setReference(reference)\n
# set filename of document, as other scripts are expecting such value\n
pdf.setFilename(reference)\n
pdf.share()\n
pdf.archive()\n
\n
\n
#Create new mail message event\n
portal.portal_notifications.sendMessage(\n
  sender=support,\n
  recipient=(fiber_request, ),\n
  subject=mail_title,\n
  attachment_document_list=(pdf, ),\n
  message=mail_text,\n
  message_text_format=notification_message.getTextFormat(),\n
  notifier_list=(\'Mail Message\',),\n
  store_as_event=True,\n
  event_keyword_argument_dict={\'follow_up_value\': fiber_request},\n
  )\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>state_change</string> </value>
        </item>
        <item>
            <key> <string>_proxy_roles</string> </key>
            <value>
              <tuple>
                <string>Manager</string>
              </tuple>
            </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>FreeFiberRequest_sendConfirmationMail</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
