本文整理汇总了Python中GlobalUtilities.toDecimal方法的典型用法代码示例。如果您正苦于以下问题:Python GlobalUtilities.toDecimal方法的具体用法?Python GlobalUtilities.toDecimal怎么用?Python GlobalUtilities.toDecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalUtilities
的用法示例。
在下文中一共展示了GlobalUtilities.toDecimal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
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()
示例2: task
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
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', {}))
示例3: new_offline_donation
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
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)
示例4: _run
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
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()
示例5: update
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
def update(self, name, email, team_list, description, change_image, password, show_donation_page,
show_progress_bar):
name_changed = False
show_donation_changed = False
if name != self.name:
self.name = name
name_changed = True
if email:
if email != self.email:
self.email = email
if password != None and password != "" and self.password != password:
self.password = password
else:
self.email = None
self.password = None
if show_donation_page != self.show_donation_page:
self.show_donation_page = show_donation_page
show_donation_changed = True
if show_progress_bar != self.show_progress_bar:
self.show_progress_bar = show_progress_bar
show_donation_changed = True
# Initializes DictDiffer object to tell differences from current dictionary to server-side one
team = json.loads(team_list)
dd = tools.DictDiffer(team, self.data.team_list)
for key in dd.added():
new_tl = TeamList()
new_tl.individual = self.key
new_tl.team = tools.getKey(key)
new_tl.fundraise_amt = tools.toDecimal(team[key][1])
new_tl.put()
for key in dd.removed():
query = TeamList.gql("WHERE team = :t AND individual = :i", t=tools.getKey(key), i=self.key)
tl = query.fetch(1)[0]
for d in tl.data.donations:
d.team = None
d.put()
tl.key.delete()
for key in dd.changed():
query = TeamList.gql("WHERE team = :t AND individual = :i", t=tools.getKey(key), i=self.key)
tl = query.fetch(1)[0]
tl.fundraise_amt = tools.toDecimal(team[key][1])
tl.put()
if description != self.description:
self.description = description
if change_image != None:
# If change_image = None, there isn't any change. If it isn't, it
# contains a
if self.photo != None:
# Delete old blob to keep it from orphaning
old_blobkey = self.photo
old_blob = blobstore.BlobInfo.get(old_blobkey)
old_blob.delete()
self.photo = change_image
try:
if name_changed or show_donation_changed:
for tl in self.teamlist_entities:
if name_changed == True:
tl.sort_name = name
if show_donation_changed:
tl.show_donation_page = show_donation_page
tl.show_progress_bar = show_progress_bar
tl.put()
except:
pass
self.put()
if name_changed:
# Reindexing donations on name change
taskqueue.add(url="/tasks/reindex", params={'mode': 'team', 'key': self.websafe}, countdown=1,
queue_name="backend")
示例6: _from_base_type
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
def _from_base_type(self, value):
return tools.toDecimal(value)
示例7: post
# 需要导入模块: import GlobalUtilities [as 别名]
# 或者: from GlobalUtilities import toDecimal [as 别名]
#.........这里部分代码省略.........
team_key = tools.getKeyIfExists(decoded_custom[0])
individual_key = tools.getKeyIfExists(decoded_custom[1])
special_notes = decoded_custom[2]
if s.exists.entity(team_key) == False:
team_key = None
if s.exists.entity(individual_key) == False:
individual_key = None
except:
logging.error("Excepted on designation.")
team_key = None
individual_key = None
special_notes = None
try:
cover_trans = decoded_custom[3]
email_subscr = decoded_custom[4]
except:
cover_trans = False
email_subscr = False
try:
phone = parameters['contact_phone']
if len(phone) > 10:
special_notes += "\nContact phone: " + phone
phone = None
except:
logging.info("Excepted on phone number.")
phone = None
confirmation_amount = tools.toDecimal(0)
amount_donated = tools.toDecimal(0)
try:
confirmation_amount = parameters['mc_gross']
amount_donated = float(parameters['mc_gross']) - float(parameters['mc_fee'])
except:
pass
# Find out what kind of payment this was - recurring, one-time, etc.
try:
payment_type = parameters['txn_type']
except:
logging.info("Txn_type not available, so continuing with payment status")
payment_type = payment_status
if payment_type == "recurring_payment_profile_created" or payment_type == "subscr_signup":
logging.info("This is the start of a recurring payment. Create info object.")
payment_id = parameters['subscr_id']
# Duration between payments
duration = "recurring"
# s.create.recurring_donation(payment_id, duration, ipn_data)
elif payment_type == "recurring_payment" or payment_type == "subscr_payment":
logging.info("This is a recurring donation payment.")
payment_id = parameters['subscr_id']
payment_type = "recurring"
# Create a new donation