def post(self):
        fields = OrderedDict([
            ("Candidate Details", OrderedDict([
                ("Full Name", "name"),
                ("Phone", "phone"),
                ("Email", "email")
            ])),
            ("Nomination", {"State": "nomination_state"}),
            ("Seconder Details", OrderedDict([
                ("Full Name", "seconder_name"),
                ("Phone", "seconder_phone"),
                ("Email", "seconder_email")
            ])),
            ("Candidate Questions", OrderedDict([
                ("Why do you feel that you are qualified for the position for which you have declared your candidacy?", "q1"),
                ("Why are you seeking the position for which you have declared your candidacy?", "q2"),
                ("What experience/contribution have you made so far to the Pirate movement, and what will you do to advance or better the Party and movement?", "q3"),
                ("Do you agree with the Pirate Party platform and its ideals? What other political movements or parties have you been a part of?", "q4"),
                ("# Disclosure of history", "background")
            ])),
            ("Submission", {"Pledge agreed to?": "pledge"})
        ])

        # Deal with files
        attachments = []
        for file in self.request.files.values():
            attachments.append(create_attachment(file[0]['filename'], file[0]['body']))

        answers = []
        for heading, x in fields.items():
            answers.append("\n# %s" % heading)
            for k, v in x.items():
                if heading == "Candidate Questions":
                    answers.append("%s\n%s\n" % (k, self.get_argument(v, "")))
                elif heading == "Submission":
                    answers.append("%s\n%s\n" % (k, "Yes" if self.get_argument(v, "") == "on" else "No"))
                else:
                    answers.append("%s: %s" % (k, self.get_argument(v, "")))

        name = self.get_argument("name")
        text = "\n".join(answers).strip()
        frm = "%s <%s>" % (name, self.get_argument('email'))

        sendmail(create_email(
            frm=self.application.email_to,
            to=self.application.email_to,
            subject="Preselection Nomination: %s" % name,
            text=text,
            attachments=attachments
        ))

        logging.debug(text)
        self.write(self.application.success_template % text)
示例#2
0
    def create_and_send_invoice(self, member, invoice):
        if invoice['payment_method'] == "paypal":
            biller_info = self.paypal.create_biller_info(
                member['given_names'],
                member['surname'],
                member['primary_phone'],
                member['residential_address'],
                None,
                member['residential_suburb'],
                member['residential_state'],
                member['residential_postcode']
            )

            response = self.paypal.create_and_send_invoice(
                self.config['email'],
                member['email'],
                self.paypal.get_merchant_info(),
                biller_info,
                self.paypal.create_invoice_item(invoice['items'][0]['item'], str(invoice['items'][0]['price']/100)),
                payment_terms="Net30"
            )

            if response['responseEnvelope']['ack'].startswith("Success"):
                invoice['reference'] = response['invoiceNumber']
                invoice['paypal_id'] = response['invoiceID']
                return invoice
            else:
                return None

        elif invoice['payment_method'] in ("direct_deposit", "cheque"):
            personal = {
              "name": "Pirate Party Australia Incorporated",
              "address": [],
              "contact": {
                "Email": "*****@*****.**",
                "Website": "<a href='http://pirateparty.org.au'>http://pirateparty.org.au</a>"
              },
              "business_number": "99 462 965 754",
              "payment_methods": [
                {
                  "Direct Deposit": [
                    "Name: Pirate Party Australia Incorporated",
                    "BSB: 012084",
                    "Account number: 213142205",
                    "Bank: ANZ"
                  ]
                }, {
                  "Cheque": [
                    "Address:",
                    "Pirate Party Australia",
                    "PO Box 385",
                    "Figtree NSW 2525"
                  ]
                }
              ]
            }


            member_level = "INVALID"
            if member['membership_level'] == "full":
                member_level = "Full Membership"
            elif member['membership_level'] == "associate":
                member_level = "Associate Membership"

            invoice_tmpl = {
                "regarding": member_level,
                "name": "%s %s" % (member['given_names'], member['surname']),
                "reference": invoice['reference'],
                "items": [
                  {
                    "rate_price": invoice['items'][0]['price'],
                    "tax": "0",
                    "description": invoice['items'][0]['item'],
                    "hours_qty": "1"
                  }
                ],
                "already_paid": "0",
                "details": "",
                "address": [
                  member['residential_address'],
                  "%s %s %s" % (member['residential_suburb'],
                      member['residential_state'], member['residential_postcode'])
                ],
                "date": invoice['issued_date'].strftime("%d/%m/%Y"),
                "message": "Thanks for joining Pirate Party Australia!",
                "payment_due": invoice['due_date'].strftime("%d/%m/%Y")
            }

            pdf_data = Invoice(invoice_tmpl, personal).to_pdf()
            try:
                sendmail(create_email(
                    frm="*****@*****.**",
                    to="%s %s <%s>" % (member['given_names'], member['surname'], member['email']),
                    subject="Pirate Party Membership Invoice (%s)" % invoice_tmpl['reference'],
                    text=self.invoice_email.format(name=member['given_names'].split(" ")[0]),
                    attachments=[create_attachment("ppau-invoice.pdf", pdf_data)]
                ))
                return invoice
            except Exception as e:
                logging.error("Failed to send invoice - %s" % e)
            return None
        else:
            raise Exception("How did you even get here?")