Exemplo n.º 1
0
    def new_offline_donation(self, req):
        message = "Offline donation created"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        # Make req variables local
        name, email, amount_donated, notes, address, team_key, individual_key, \
        add_deposit = req.name, req.email, tools.toDecimal(req.amount_donated), req.notes, \
                      req.address, req.team_key, req.individual_key, req.add_deposit

        # Check for null value in individual field
        if individual_key == "none":
            individual_key = None

        if address:
            address = [address.street, address.city, address.state, address.zipcode]

        if team_key:
            team_key = tools.getKey(team_key)

        if individual_key:
            individual_key = tools.getKey(individual_key)

        s.create.donation(name, email, amount_donated, "offline", address=address, team_key=team_key,
                          individual_key=individual_key, add_deposit=add_deposit, special_notes=notes)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 2
0
    def public_individual_info(self, req):
        i = tools.getKey(req.individual_key).get()
        t_key = tools.getKey(req.team_key)
        info = i.data.info(t_key)

        return IndividualInfo_Out(image_url=info[0], name=info[1], description=info[2],
                                  percentage=info[3], message=info[4])
Exemplo n.º 3
0
    def contact_delete(self, req):
        message = "Contact deleted"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        tools.getKey(req.contact_key).delete()

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 4
0
    def deleteTeam(self, req):
        message = "Team deleted"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        tools.getKey(req.team_key).delete()

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 5
0
    def merge_contacts(self, req):
        message = "Contacts merged"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        c1 = tools.getKey(req.contact1)
        c2 = tools.getKey(req.contact2)

        tools.mergeContacts(c1, c2)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 6
0
    def run(self, mode, file_name, keys):
        # Open GCS file for writing
        gcs_file_key, gcs_file = tools.newFile("text/csv", file_name)

        si = cStringIO.StringIO()
        writer = csv.writer(si)

        for k in keys:
            try:
                e = tools.getKey(k).get()

                row_data = []

                if mode == "contacts":
                    c = e
                    row_data.append(c.name)
                    row_data.append(c.data.donation_total)
                    row_data.append(c.data.number_donations)
                    row_data.append(c.phone)
                    row_data.append(c.address[0])
                    row_data.append(c.address[1])
                    row_data.append(c.address[2])
                    row_data.append(c.address[3])
                    row_data.append(str(c.creation_date))

                    for e in c.email:
                        row_data.append(e)

                elif mode == "donations":
                    d = e
                    c = d.contact.get()
                    row_data.append(str(d.donation_date))
                    row_data.append(d.name)
                    row_data.append(d.given_email)
                    row_data.append(str(d.amount_donated))
                    row_data.append(d.payment_type)
                    row_data.append(d.designated_team)
                    row_data.append(d.designated_individual)
                    row_data.append(str(d.reviewed))
                    row_data.append(c.phone)
                    row_data.append(c.address[0])
                    row_data.append(c.address[1])
                    row_data.append(c.address[2])
                    row_data.append(c.address[3])

                elif mode == "individuals":
                    i = e
                    row_data.append(i.name)
                    row_data.append(i.email)
                    row_data.append(i.data.readable_team_names)
                    row_data.append(str(i.data.donation_total))
                    row_data.append(str(i.creation_date))

                writer.writerow(row_data)

            except Exception, e:
                logging.error("Failed on key " + k + " because " + str(e))

            # Call the garbage handler
            gc.collect()
Exemplo n.º 7
0
    def get_team_donation_total(self, req):
        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        t = tools.getKey(req.team_key).get()
        donation_total = tools.moneyAmount(t.data.donation_total)

        return GetTeamDonationTotal_Out(donation_total=donation_total)
Exemplo n.º 8
0
    def update_contact(self, req):
        message = "Contact has been saved"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        c = tools.getKey(req.contact_key).get()

        a = req.address
        address = [a.street, a.city, a.state, a.zipcode]

        # Check to see if a new email was added and see if it already exists
        list_diff = tools.listDiff(c.email, req.email)

        if list_diff:
            email_exists = s.exists.contact(email=list_diff)[0]
        else:
            email_exists = False

        if email_exists == True:
            success = False
            message = "Whoops! You entered an email address already in use by another contact."
        else:
            c.update(req.name, req.email, req.phone, req.notes, address)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 9
0
    def task(self, isAdmin, s):
        contact_key = self.request.get("c")
        c = tools.getKey(contact_key).get()

        template_variables = {"c": c, "s": s}
        self.response.write(
            template.render('pages/contact.html', template_variables))
Exemplo n.º 10
0
    def task(self, isAdmin, s):
        try:

            contact_key = self.request.get("c")
            year = int(self.request.get("y"))

            if contact_key == "" or year == "" or len(str(year)) != 4:
                # Throw an error if you don't have those two pieces of info or if the year isn't a number
                raise Exception("Don't know contact key or year.")

            c = tools.getKey(contact_key).get()
            s = c.settings.get()

            donations = c.data.annual_donations(year)
            donation_total = tools.toDecimal(0)

            for d in donations:
                donation_total += d.confirmation_amount

            donation_total = "${:,.2f}".format(donation_total)

            template_variables = {"s": s, "c": c, "donations": donations, "year": str(year),
                                  "donation_total": str(donation_total), "street": c.address[0], "city": c.address[1],
                                  "state": c.address[2], "zip": c.address[3]}

            self.response.write(
                template.render("pages/letters/donor_report_print.html", template_variables))


        except:
            # If there's a malformed URL, give a 500 error
            self.error(500)
            self.response.write(
                template.render('pages/letters/thankyou_error.html', {}))
Exemplo n.º 11
0
    def task(self, isAdmin, s):

        if isAdmin == True:
            # If an admin, they can get whatever user they want
            i_key = self.request.get("i")

            # if no key specified, go to admin's personal account
            if i_key == "":
                i_key = tools.getUserKey(self)
            else:
                i_key = tools.getKey(i_key)

        else:
            # If a regular user, they can ONLY get their own profile
            i_key = tools.getUserKey(self)

        i = i_key.get()
        logging.info("Getting profile page for: " + i.name)

        # Creating a blobstore upload url
        upload_url = blobstore.create_upload_url('/ajax/profile/upload')

        template_variables = {"s": s, "i": i, "upload_url": upload_url, "isAdmin": isAdmin}
        self.response.write(
            template.render("pages/profile.html", template_variables))
Exemplo n.º 12
0
    def task(self, isAdmin, s):
        team_key = self.request.get("t")
        t = tools.getKey(team_key).get()

        template_variables = {"t": t}
        self.response.write(
            template.render('pages/team_members.html', template_variables))
Exemplo n.º 13
0
    def post(self):
        donation_key = self.request.get("donation_key")
        d = tools.getKey(donation_key).get()

        logging.info("Retrying confirmation email through task queue for donation: " + donation_key)

        d.confirmation.email()
Exemplo n.º 14
0
    def post(self):
        entity_key = self.request.get("e")

        try:
            e = tools.getKey(entity_key).get()
            e.search.index()
        except Exception, e:
            logging.error(str(e))
            self.error(500)
Exemplo n.º 15
0
    def public_all_teams(self, req):
        s = tools.getKey(req.settings_key).get()

        all_teams = []
        for t in s.data.display_teams:
            team = Team_Data(name=t.name, key=t.key.urlsafe())
            all_teams.append(team)

        return AllTeams_Out(objects=all_teams)
Exemplo n.º 16
0
    def donation_mark_unreviewed(self, req):
        message = "Donation marked as unreviewed"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        d = tools.getKey(req.donation_key).get()
        d.review.markUnreviewed()

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 17
0
    def donation_archive(self, req):
        message = "Donation archived"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        d = tools.getKey(req.donation_key).get()
        d.review.archive()

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 18
0
    def new_impression(self, req):
        message = "Impression saved"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        c = tools.getKey(req.contact_key).get()
        c.create.impression(req.impression, req.notes)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 19
0
    def update_team(self, req):
        message = "Team has been updated"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        t = tools.getKey(req.team_key).get()
        t.update(req.name, req.show_team)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 20
0
    def post(self):
        email = self.request.get("email")
        name = self.request.get("name")

        settings_key = self.request.get("settings")
        s = tools.getKey(settings_key).get()

        s.mailchimp.add(email, name, True)

        logging.info("Retrying Mailchimp add through task queue for: " + email + " under settings ID: " + settings_key)
Exemplo n.º 21
0
    def public_team_info(self, req):
        t = tools.getKey(req.team_key).get()

        info_list = []
        m_list = t.data.members_list
        for m in m_list:
            info = TeamInfo_Data(name=m[0], photo_url=m[1], tl_key=m[2])
            info_list.append(info)

        return TeamInfo_Out(info_list=info_list)
Exemplo n.º 22
0
    def get_team_totals(self, req):
        s = tools.getSettingsKey(self, endpoints=True).get()

        i = tools.getKey(req.individual_key).get()

        team_totals = []
        for tl in i.teamlist_entities:
            total = GetTeamTotals_Data(team_name=tl.team_name, donation_total=tools.moneyAmount(tl.data.donation_total))
            team_totals.append(total)

        return GetTeamTotals_Out(team_totals=team_totals)
Exemplo n.º 23
0
    def post(self):
        target_year = int(self.request.get("year"))
        s = tools.getKey(self.request.get("skey"))
        mode = self.request.get("mode")

        td1 = datetime(target_year, 1, 1, 0, 0)
        td2 = datetime(target_year, 12, 31, 0, 0)

        annual_donations = models.Donation.query(models.Donation.settings == s,
                                                 models.Donation.donation_date >= td1,
                                                 models.Donation.donation_date <= td2)

        all_contacts = set([d.contact for d in annual_donations])

        with_email = []
        without_email = []
        missing_contacts = []

        for c_key in all_contacts:
            c = c_key.get()
            if not c:
                missing_contacts.append(c_key)

            else:

                if c.email != ['']:
                    with_email.append(c)

                else:
                    donation_total = c.data.donation_total
                    if donation_total >= tools.toDecimal("250"):
                        without_email.append(c)

                    elif c.data.number_donations == 1 and donation_total >= tools.toDecimal("100"):
                        without_email.append(c)

        body = ""

        body += "\n" + "#### " + str(len(with_email)) + " Donors with Email Addresses ####"
        for c in with_email:
            body += "\n" + c.websafe

        body += "\n" + "\n\n\n#### " + str(len(without_email)) + " Donors WITHOUT Email Addresses ####"
        for c in without_email:
            body += "\n" + "https://ghidonations.appspot.com/reports/donor?c=" + c.websafe + "&y=2013"

        body += "\n" + "\n\n\n#### " + str(len(missing_contacts)) + " Missing Contacts ####"
        for c in missing_contacts:
            body += "\n" + str(c)

        # Writing text file
        gcs_file_key, gcs_file = tools.newFile("text/plain", "GHI_Donations_" + str(target_year) + ".txt")
        gcs_file.write(body)
        gcs_file.close()
Exemplo n.º 24
0
    def printReceipt(self, req):
        message = "Receipt open for printing"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)
        d = tools.getKey(req.donation_key).get()

        # Print receipt to donor
        d.review.archive()
        print_url = d.confirmation.print_url(None)

        return ConfirmationPrint_Out(success=success, message=message, print_url=print_url)
Exemplo n.º 25
0
    def task(self, isAdmin, s):
        try:
            mode = self.request.get("m")
            individual_key = self.request.get("i")

            if mode == "" or individual_key == "":
                # Throw an error if you don't have those two pieces of info
                raise Exception("Don't know mode or individual_key.")

            i = tools.getKey(individual_key).get()
            s = tools.getKey(i.settings).get()

            template_variables = {"s": s, "i": i}
            self.response.write(
                template.render('pages/letters/individual.html', template_variables))

        except:
            # If there's a malformed URL, give a 500 error
            self.error(500)
            self.response.write(
                template.render('pages/letters/thankyou_error.html', {}))
Exemplo n.º 26
0
    def semi_get_team_members(self, req):
        # Returns team information
        isAdmin, s = tools.checkAuthentication(self, False, from_endpoints=True)

        t = tools.getKey(req.team_key).get()
        members_list = t.data.members_list

        members = []
        for m in members_list:
            member = SemiGetTeamMembers_Data(key=m[2], name=m[0])
            members.append(member)

        return SemiGetTeamMembers_Out(objects=members)
Exemplo n.º 27
0
    def update_donation(self, req):
        message = "Donation has been saved"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        d = tools.getKey(req.donation_key).get()

        # Make req variables local
        team_key, individual_key = req.team_key, req.individual_key

        if team_key:
            if team_key == "general":
                team_key = None
            else:
                team_key = tools.getKey(team_key)

        if individual_key:
            individual_key = tools.getKey(individual_key)

        d.update(req.notes, team_key, individual_key, None, req.donation_date)

        return SuccessMessage_Out(success=success, message=message)
Exemplo n.º 28
0
    def get(self):
        self.response.headers['Access-Control-Allow-Origin'] = '*'

        settings = self.request.get("s")

        try:
            s = tools.getKey(settings).get()

            template_variables = {"s": s}
            self.response.write(
                template.render('pages/public_pages/pub_donate.html', template_variables))

        except:
            self.response.write("Sorry, this URL triggered an error.  Please try again.")
Exemplo n.º 29
0
    def post(self):
        s_key = self.request.get("s_key")
        s = tools.getKey(s_key).get()

        contacts = []

        for c in s.data.all_contacts:
            contact = {}
            contact["label"] = c.name
            contact["key"] = str(c.websafe)

            contacts.append(contact)

        s.contacts_json = json.dumps(contacts)
        s.put()
Exemplo n.º 30
0
    def confirmation_email(self, req):
        message = "Email sent"
        success = True

        isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True)

        d = tools.getKey(req.donation_key).get()

        if not d.email or d.email == ['']:
            success = False
            message = "Email not sent. Contact doesn't have an email address."

        else:
            # Email receipt to donor
            d.review.archive()
            d.confirmation.task(60)

        return SuccessMessage_Out(success=success, message=message)