Exemple #1
0
 def get_most_recent_donation(self):
     try:
         query = (Transaction.select().order_by(Transaction.id.desc()))
         return list(query)[0].donation_amount
     except Exception as e:
         logging.info('Error retrieving most recent donation')
         logging.info(e)
Exemple #2
0
 def get_donors(self):
     try:
         query = (Transaction.select(Transaction.donor_name).distinct())
         return [i.donor_name for i in query]
     except Exception as e:
         logging.info('Failed to retrieve donor names')
         logging.info(e)
Exemple #3
0
 def get_sum_donations(self):
     try:
         query = (Transaction.select(Transaction.donation_amount).where(
             Transaction.donor_name == self.name))
         return float(sum([i.donation_amount for i in query]))
     except Exception as e:
         logging.info('Error calculating sum of donations')
         logging.info(e)
Exemple #4
0
 def get_num_donations(self):
     try:
         query = (Transaction.select(Transaction.donation_amount).where(
             Transaction.donor_name == self.name))
         return len(query)
     except Exception as e:
         logging.info('Error calculating number of donations')
         logging.info(e)
Exemple #5
0
 def get_average_donation(self):
     try:
         query = (Transaction.select(Transaction.donation_amount).where(
             Transaction.donor_name == self.name))
         return float(sum([i.donation_amount for i in query]) / len(query))
     except Exception as e:
         logging.info('Error calculating average donation')
         logging.info(e)
Exemple #6
0
 def update_row(self):
     try:
         query = (Transaction.select().execute())
         for row in query:
             print('{:8} {:18} {:8}'.format(row.id, row.donor_name,
                                            row.donation_amount))
         idx = input('Select the index of the transaction you want '
                     'to update')
         new_value = input('Enter the new amount')
         query = (Transaction.update(donation_amount=new_value).where(
             Transaction.id == idx).execute())
         logging.info('Successfully updated row')
     except Exception as e:
         logging.info('Error updating row')
         logging.info(e)
Exemple #7
0
 def delete_row(self):
     """I don't want to delete transactions where one user made the 
     same donation multiple times, which would occur if I deleted
     based on donor name and transaction amount. So I will give the 
     user the list of transactions and have the user delete based 
     on index"""
     try:
         query = (Transaction.select().execute())
         for row in query:
             print('{:8} {:18} {:8}'.format(row.id, row.donor_name,
                                            row.donation_amount))
         idx = input('Select the index of the transaction you want'
                     ' to delete')
         query = (Transaction.delete().where(
             Transaction.id == idx).execute())
         logging.info('Successfully deleted row')
     except Exception as e:
         logging.info('Error deleting row')
         logging.info(e)