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)
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)
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])
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', {}))
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)
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))
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)
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()
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)
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)
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)
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)
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)
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)
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()
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()
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)
def spreadsheet_check(self, req): isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True) completed, gcs_file_key = tools.checkTaskCompletion(s, req.job_id) status = tools.pipelineStatus(req.job_id) if completed: download_url = "http://commondatastorage.googleapis.com/" + gcs_file_key[1:] else: download_url = None return SpreadsheetCheck_Out(completed=completed, download_url=download_url, status=status)
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)
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)
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)
def mailchimp_lists(self, req): isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True) response = tools.getMailchimpLists(self, req.mc_apikey) mc_lists = None error_message = None if response[0] == True: mc_lists = json.dumps(response[1]) else: mc_lists = None error_message = response[1] return MailchimpLists_Out(success=response[0], mc_lists=mc_lists, error_message=error_message)
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))
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))
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()
def task(self, isAdmin, s): i_key = tools.getUserKey(self) i = i_key.get() template_variables = {"i": i} self.response.write( template.render('pages/mobile.html', template_variables))
def task(self, isAdmin, s): i = tools.getUserKey(self).get() template_variables = {"teams": None, "individual_name": i.name, "individual_key": i.key.urlsafe(), "teams": s.data.all_teams} self.response.write( template.render('pages/offline.html', template_variables))
def get(self): # By default, need admin priveleges to view isAdmin, s = tools.checkAuthentication(self, True) if isAdmin == None and s == None: self.redirect("/login") else: return self.task(isAdmin, s)
def new_team(self, req): message = "<b>" + req.name + "</b> created" success = True isAdmin, s = tools.checkAuthentication(self, True, from_endpoints=True) s.create.team(req.name) return SuccessMessage_Out(success=success, message=message)
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)