def update(self, id=None): with meta.Session.no_autoflush: if id is None: t = model.Transfer() meta.Session.add(t) op = 'created' else: t = meta.Session.query(model.Transfer).get(id) if t is None: abort(404) op = 'updated' update_sar(t, self.form_result) if not t.debtor: t.debtor = meta.Session.query(model.User).get(t.debtor_id) if not t.creditor: t.creditor = meta.Session.query(model.User).get(t.creditor_id) meta.Session.commit() show = ('Transfer of %s from %s to %s %s.' % (t.amount, t.debtor, t.creditor, op)) log.info(show) h.flash(show) # Send email notification to involved users if they have an email set. body = render('/emails/transfer.txt', extra_vars={ 'transfer': t, 'op': op }) g.handle_notification((t.debtor, t.creditor), show, body) return h.redirect_to('/')
def update(self, id=None): # Either create a new object, or, if we're editing, get the # old one involved_users = set() if id is None: e = model.Expenditure() meta.Session.add(e) op = 'created' old_expenditure = None else: e = meta.Session.query(model.Expenditure).get(id) if e is None: abort(404) old_expenditure = render('/emails/expenditure.txt', extra_vars={ 'expenditure': e, 'op': 'previously', 'old_expenditure': None }) # If a user gets removed from a transaction, they should # still get an email involved_users.update(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) op = 'updated' # Set the fields that were submitted shares = self.form_result.pop('shares') update_sar(e, self.form_result) users = dict(meta.Session.query(model.User.id, model.User).all()) split_dict = {} for share_params in shares: user = users[share_params['user_id']] split_dict[user] = Decimal(str(share_params['amount'])) e.split(split_dict) meta.Session.commit() show = ("Expenditure of %s paid for by %s %s." % (e.amount, e.spender, op)) h.flash(show) # Send email notification to involved users if they have an email set. involved_users.update(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) body = render('/emails/expenditure.txt', extra_vars={ 'expenditure': e, 'op': op, 'old_expenditure': old_expenditure }) g.handle_notification(involved_users, show, body) return h.redirect_to('/')
def update(self, id=None): # Either create a new object, or, if we're editing, get the # old one involved_users = set() if id is None: e = model.Expenditure() meta.Session.add(e) op = 'created' old_expenditure = None else: e = meta.Session.query(model.Expenditure).get(id) if e is None: abort(404) old_expenditure = render('/emails/expenditure.txt', extra_vars={'expenditure': e, 'op': 'previously', 'old_expenditure': None}) # If a user gets removed from a transaction, they should # still get an email involved_users.update(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) op = 'updated' # Set the fields that were submitted shares = self.form_result.pop('shares') update_sar(e, self.form_result) users = dict(meta.Session.query(model.User.id, model.User).all()) split_dict = {} for share_params in shares: user = users[share_params['user_id']] split_dict[user] = Decimal(str(share_params['amount'])) e.split(split_dict) meta.Session.commit() show = ("Expenditure of %s paid for by %s %s." % (e.amount, e.spender, op)) h.flash(show) # Send email notification to involved users if they have an email set. involved_users.update(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) body = render('/emails/expenditure.txt', extra_vars={'expenditure': e, 'op': op, 'old_expenditure': old_expenditure}) g.handle_notification(involved_users, show, body) return h.redirect_to('/')
def update(self, id=None): # Either create a new object, or, if we're editing, get the # old one if id is None: e = model.Expenditure() meta.Session.add(e) op = 'created' else: e = meta.Session.query(model.Expenditure).get(id) if e is None: abort(404) op = 'updated' # Set the fields that were submitted shares = self.form_result.pop('shares') tags = self.form_result.pop('tags') or set() update_sar(e, self.form_result) users = dict(meta.Session.query(model.User.id, model.User).all()) split_dict = {} split_text_dict = {} for share_params in shares: user = users[share_params['user_id']] amount_text, amount = share_params['amount'] or ('',Decimal('0')) split_dict[user] = amount split_text_dict[user] = amount_text e.split(split_dict, split_text_dict) e.tags.clear() e.tags |= tags meta.Session.commit() show = ("Expenditure of %s paid for by %s %s." % (e.amount, e.spender, op)) h.flash(show) # Send email notification to involved users if they have an email set. involved_users = set(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) body = render('/emails/expenditure.txt', extra_vars={'expenditure': e, 'op': op}) g.handle_notification(involved_users, show, body) prune_tags() return h.redirect_to('/')
def destroy(self, id): t = meta.Session.query(model.Transfer).get(id) if t is None: abort(404) if 'delete' in request.params: meta.Session.delete(t) meta.Session.commit() show = ("Transfer of %s from %s to %s deleted." % (t.amount, t.debtor, t.creditor)) h.flash(show) body = render('/emails/transfer.txt', extra_vars={'transfer': t, 'op': 'deleted'}) g.handle_notification((t.debtor, t.creditor), show, body) return h.redirect_to('/')
def destroy(self, id): t = meta.Session.query(model.Transfer).get(id) if t is None: abort(404) if 'delete' in request.params: meta.Session.delete(t) meta.Session.commit() show = ("Transfer of %s from %s to %s deleted." % (t.amount, t.debtor, t.creditor)) h.flash(show) body = render('/emails/transfer.txt', extra_vars={ 'transfer': t, 'op': 'deleted' }) g.handle_notification((t.debtor, t.creditor), show, body) return h.redirect_to('/')
def destroy(self, id): e = meta.Session.query(model.Expenditure).get(id) if e is None: abort(404) if 'delete' in request.params: meta.Session.delete(e) meta.Session.commit() show = ("Expenditure of %s paid for by %s deleted." % (e.amount, e.spender)) h.flash(show) involved_users = set(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) body = render('/emails/expenditure.txt', extra_vars={'expenditure': e, 'op': 'deleted'}) g.handle_notification(involved_users, show, body) return h.redirect_to('/')
def update(self, id=None): if id is None: t = model.Transfer() meta.Session.add(t) op = 'created' else: t = meta.Session.query(model.Transfer).get(id) if t is None: abort(404) op = 'updated' update_sar(t, self.form_result) meta.Session.commit() show = ('Transfer of %s from %s to %s %s.' % (t.amount, t.debtor, t.creditor, op)) h.flash(show) # Send email notification to involved users if they have an email set. body = render('/emails/transfer.txt', extra_vars={'transfer': t, 'op': op}) g.handle_notification((t.debtor, t.creditor), show, body) return h.redirect_to('/')
def destroy(self, id): e = meta.Session.query(model.Expenditure).get(id) if e is None: abort(404) if 'delete' in request.params: meta.Session.delete(e) meta.Session.commit() show = ("Expenditure of %s paid for by %s deleted." % (e.amount, e.spender)) h.flash(show) involved_users = set(sp.user for sp in e.splits if sp.share != 0) involved_users.add(e.spender) body = render('/emails/expenditure.txt', extra_vars={ 'expenditure': e, 'op': 'deleted', 'old_expenditure': None }) g.handle_notification(involved_users, show, body) return h.redirect_to('/')