当前位置: 首页>>代码示例>>Python>>正文


Python GlobalUtilities类代码示例

本文整理汇总了Python中GlobalUtilities的典型用法代码示例。如果您正苦于以下问题:Python GlobalUtilities类的具体用法?Python GlobalUtilities怎么用?Python GlobalUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GlobalUtilities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_contact

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:26,代码来源:ghiendpoints.py

示例2: get_team_donation_total

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:7,代码来源:ghiendpoints.py

示例3: public_individual_info

    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])
开发者ID:rhefner1,项目名称:ghidonations,代码行数:7,代码来源:ghiendpoints.py

示例4: task

    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', {}))
开发者ID:rhefner1,项目名称:ghidonations,代码行数:34,代码来源:mooha.py

示例5: semi_get_individual_donations

    def semi_get_individual_donations(self, req):
        isAdmin, s = tools.checkAuthentication(self, False, from_endpoints=True)
        query = "individual_key:" + str(req.individual_key)

        results = s.search.donation(query, query_cursor=req.query_cursor)
        logging.info("Getting individual donations with query: " + query)

        donations = []
        new_cursor = tools.getWebsafeCursor(results[1])

        for d in results[0]:
            f = d.fields

            team_name = f[6].value
            if team_name == None:
                team_name = ""

            donation = Donation_Data(key=f[0].value, formatted_donation_date=f[9].value, name=f[2].value,
                                     email=tools.truncateEmail(f[3].value),
                                     payment_type=f[5].value, amount_donated=tools.moneyAmount(f[4].value),
                                     team_name=team_name)

            donations.append(donation)

        return Donations_Out(objects=donations, new_cursor=new_cursor)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:25,代码来源:ghiendpoints.py

示例6: new_offline_donation

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:28,代码来源:ghiendpoints.py

示例7: run

    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()
开发者ID:,项目名称:,代码行数:60,代码来源:

示例8: contact_delete

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:9,代码来源:ghiendpoints.py

示例9: deleteTeam

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:9,代码来源:ghiendpoints.py

示例10: update_team

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:10,代码来源:ghiendpoints.py

示例11: donation_archive

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:10,代码来源:ghiendpoints.py

示例12: donation_mark_unreviewed

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:10,代码来源:ghiendpoints.py

示例13: new_impression

    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)
开发者ID:rhefner1,项目名称:ghidonations,代码行数:10,代码来源:ghiendpoints.py

示例14: _run

    def _run(self):

        # Scheduled cron job to update analytics for all settings accounts every hour
        all_settings = models.Settings.query()
        for s in all_settings:

            ## Update one_week_history
            last_week = datetime.today() - timedelta(days=7)

            # Get donations made in the last week
            donations = models.Donation.gql(
                "WHERE settings = :s AND donation_date > :last_week ORDER BY donation_date DESC",
                s=s.key, last_week=last_week)

            donation_count = 0
            total_money = tools.toDecimal(0)

            for d in donations:
                # Counting total money
                total_money += d.amount_donated

                # Counting number of donations
                donation_count += 1

            one_week_history = [donation_count, str(total_money)]
            s.one_week_history = json.dumps(one_week_history)

            #####################################################################################################

            ## Update one_month_history
            last_week = datetime.today() - timedelta(days=30)

            # Get donations made in the last week
            donations = models.Donation.gql(
                "WHERE settings = :s AND donation_date > :last_week ORDER BY donation_date DESC",
                s=s.key, last_week=last_week)

            one_month_history = [["Date", "Amount Donated ($)"]]
            donations_dict = {}

            for d in donations:
                d_date = tools.convertTime(d.donation_date)
                day = str(d_date.month).zfill(2) + "/" + str(d_date.day).zfill(2)

                if day in donations_dict:
                    donations_dict[day] += d.amount_donated
                else:
                    donations_dict[day] = d.amount_donated

            for date in sorted(donations_dict.iterkeys()):
                one_month_history.append([date, float(donations_dict[date])])

            s.one_month_history = json.dumps(one_month_history)

            s.put()
开发者ID:rhefner1,项目名称:ghidonations,代码行数:55,代码来源:tasks.py

示例15: post

    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()
开发者ID:rhefner1,项目名称:ghidonations,代码行数:54,代码来源:tasks.py


注:本文中的GlobalUtilities类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。