> I guess teh only way we can help you is if you post
> the complete method code.
Here is code that should update financial records/objects every payday
as well as a log
called change.log....
ASSET = financial.models.models.Asset
CHECKING_ENTRY = financial.models.models.CheckingEntry
PAYDAY_UPDATES = "financial/models/payday_updates"
change_log = open("change.log", "a")
def payday_update():
"""
Updates model elements for each payday. Reads update
categories and
amounts from a file. This update only gets run every other
week.
"""
if int(time.strftime("%U")) % 2 == 0: # Only every 2 weeks!
payday_updates = [l.split() for l in
open(PAYDAY_UPDATES, "r").readlines()]
update(payday_updates) # This is a function that
actually changes database.
def update(updates):
"""
Updates model elements.
"""
for e in updates: #updates is a dict with categories to
update and amounts to change by.
category = e[0].replace("_", " ") # Replace
underscores in file with spaces.
amount_ = decimal.Decimal(e[1])
if category == "CHECKING ACCOUNT":
CHECKING_ENTRY(description = "
".join(e[2:]), \
amount =
amount_, \
date =
datetime.date.today())
else:
asset = list(ASSET.select(ASSET.q.category
== \
category))[0]
change_log.write( \
time.asctime() + ": "
+ \
"Asset-" + asset.category + ": "
+ \
"old amount: " +
fix_str(asset.amount) + \
" new amount: " +
fix_str(asset.amount + \
amount_)
+ "\n")
asset.amount += amount_ # This line changes
asset.amount but not in DB!
change_log.flush()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---