Christopher Arndt wrote:
You should re-use the database connection created in your model file and pass
that to your load_* functions.

from myproject.model import hub
cnx = hub.getConnection()

Thanks, that makes sense. So far, I've only been working on model, test
and widget code, I haven't had to manage the hub connection myself at
all in those contexts.

Is there some magic to model.py's attribute __connection__ that I could
duplicate in util.py? If not, what should the functions do to set their
connection before creating an object with Group(...)? Do I need 'from
turbogears import database' for connection management to work?

util.py:
-------------------------------------------------------------------------
import csv
from myproject.model import hub, Group, User

__connection__ = hub

def load_groups(filename=None):
   """Load groups from CSV format data file:
   "group_name","display_name"
   """
   data = csv.DictReader(open(filename,'r'))
   for row in data:
       Group(group_name=row['group_name'],
             display_name=row['display_name'])

-----------------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to