import logging
import re
+import string
from decimal import Decimal, InvalidOperation
from bluechips.lib.base import *
except:
raise formencode.Invalid("Not a valid mathematical expression", value, state)
+class TagValidator(validators.FancyValidator):
+ def _to_python(self, value,state):
+ try:
+ return set(map(string.strip, value.split(',')))
+ except:
+ raise formencode.Invalid("Unable to parse tags", value, state)
class ShareSchema(Schema):
"Validate individual user shares."
spender_id = validators.Int(not_empty=True)
amount = model.types.CurrencyValidator(not_empty=True)
description = validators.UnicodeString(not_empty=True)
+ tags = TagValidator()
date = validators.DateConverter()
shares = ForEach(ShareSchema)
chained_validators = [ValidateNotAllZero]
if user.resident:
val = Decimal(1)
c.values['shares-%d.amount' % ii] = val
+
+ c.values['tags'] = u""
else:
c.title = 'Edit an Expenditure'
c.expenditure = meta.Session.query(model.Expenditure).get(id)
share = shares_by_user.get(user, '')
c.values['shares-%d.amount' % ii] = share
+ c.values['tags'] = ', '.join([tag.tag for tag in c.expenditure.tags])
+
return render('/spend/index.mako')
@redirect_on_get('edit')
# 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[user] = amount
split_text_dict[user] = amount_text
e.split(split_dict, split_text_dict)
-
+ e.tag(tags)
+
meta.Session.commit()
show = ("Expenditure of %s paid for by %s %s." %