X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=bluechips%2Fcontrollers%2Fspend.py;h=43293071bdca31592c60f10d575bd281a6872363;hb=4d724b5efd7fd7c2c38a25e9d9210fe869aa0441;hp=ddd0a3cd45947b3fbe9d3e466ebce6c6f33d8901;hpb=53c0833dd52f70a3f57f00b2dc2ca436dd76e94f;p=bluechips.git diff --git a/bluechips/controllers/spend.py b/bluechips/controllers/spend.py index ddd0a3c..4329307 100644 --- a/bluechips/controllers/spend.py +++ b/bluechips/controllers/spend.py @@ -63,6 +63,12 @@ def validate_state(value_dict, state, validator): ValidateNotAllZero = SimpleFormValidator(validate_state) +def prune_tags(): + for tag in meta.Session.query(model.Tag).all(): + if not tag.expenditures: + meta.Session.delete(tag) + meta.Session.commit() + class ExpenditureSchema(Schema): "Validate an expenditure." allow_extra_fields = False @@ -163,6 +169,8 @@ class SpendController(BaseController): 'op': op}) g.handle_notification(involved_users, show, body) + prune_tags() + return h.redirect_to('/') def delete(self, id): @@ -195,4 +203,6 @@ class SpendController(BaseController): 'op': 'deleted'}) g.handle_notification(involved_users, show, body) + prune_tags() + return h.redirect_to('/')