def form_valid(self,form):
emailTo = form.cleaned_data.get('<STR_LIT>')<EOL>emailType = form.cleaned_data.get('<STR_LIT>')<EOL>recipientName = form.cleaned_data.get('<STR_LIT>')<EOL>fromName = form.cleaned_data.get('<STR_LIT>')<EOL>message = form.cleaned_data.get('<STR_LIT:message>')<EOL>logger.info('<STR_LIT>')<EOL>try:<EOL><INDENT>voucher = Voucher.create_new_code(<EOL>prefix='<STR_LIT>',<EOL>name=_('<STR_LIT>' % (getConstant('<STR_LIT>'),self.amount, emailTo)),<EOL>category=getConstant('<STR_LIT>'),<EOL>originalAmount=self.amount,<EOL>singleUse=False,<EOL>forFirstTimeCustomersOnly=False,<EOL>expirationDate=None,<EOL>)<EOL><DEDENT>except IntegrityError:<EOL><INDENT>logger.error('<STR_LIT>' % self.invoiceId)<EOL>emailErrorMessage(_('<STR_LIT>'), self.invoiceId)<EOL><DEDENT>template = getConstant('<STR_LIT>')<EOL>rf = RequestFactory()<EOL>pdf_request = rf.get('<STR_LIT:/>')<EOL>pdf_kwargs = {<EOL>'<STR_LIT>': getConstant('<STR_LIT>'),<EOL>'<STR_LIT>': getConstant('<STR_LIT>'),<EOL>'<STR_LIT>': voucher.originalAmount,<EOL>'<STR_LIT>': voucher.voucherId,<EOL>'<STR_LIT>': message,<EOL>'<STR_LIT>': recipientName,<EOL>'<STR_LIT>': fromName,<EOL>}<EOL>if recipientName:<EOL><INDENT>pdf_kwargs.update({})<EOL><DEDENT>attachment = GiftCertificatePDFView(request=pdf_request).get(request=pdf_request,**pdf_kwargs).content or None<EOL>if attachment:<EOL><INDENT>attachment_name = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>attachment_name = None<EOL><DEDENT>email_class = EmailRecipientMixin()<EOL>email_class.email_recipient(<EOL>subject=template.subject,<EOL>content=template.content,<EOL>send_html=template.send_html,<EOL>html_content=template.html_content,<EOL>from_address=template.defaultFromAddress,<EOL>from_name=template.defaultFromName,<EOL>cc=template.defaultCC,<EOL>to=emailTo,<EOL>currencySymbol=getConstant('<STR_LIT>'),<EOL>businessName=getConstant('<STR_LIT>'),<EOL>certificateAmount=voucher.originalAmount,<EOL>certificateCode=voucher.voucherId,<EOL>certificateMessage=message,<EOL>recipientName=recipientName,<EOL>fromName=fromName,<EOL>emailType=emailType,<EOL>recipient_name=recipientName,<EOL>attachment_name=attachment_name,<EOL>attachment=attachment<EOL>)<EOL>self.request.session.pop(INVOICE_VALIDATION_STR,None)<EOL>return HttpResponseRedirect(self.get_success_url())<EOL>
Create the gift certificate voucher with the indicated information and send
the email as directed.