Em Terça 25 Abril 2006 13:53, Ed Singleton escreveu:
> I was assuming I would create a dictionary that defined my changes.
> Fieldname to fieldname mappings for changed fieldnames, and fieldname
(...)
> I thought it would just be a fairly simple script that could be run in
> tg-admin shell.
(...)
> I've already written something similar (code below) that does that,
> for moving data from a legacy database with the class def generated
(...)
Ed, I can't tell for the tg-admin part -- you should be able to write an
extension for it, you just have to assign the correct entry point and it will
be made available -- but I'd go the CSV route.
I've done that for an old project here and it took very few lines using SQL
Object to read a CSV file and insert it into the database. Dumping data to a
CSV file should be fairly easy, and you can use SQL Object for that as well.
IIRC, my solution had 5 or 6 lines of code -- I was filtering data as
well ;-)) to do this task.
Here's some sample and old code I used in another application similar to the
one I am talking about above, but with much more lines ;-)
===============================================================================
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlobject
import csv
conn_str = 'postgres://godoy:[EMAIL PROTECTED]/sgi'
connection = sqlobject.connectionForURI(conn_str)
sqlobject.sqlhub.processConnection = connection
class Documents(sqlobject.SQLObject):
class sqlmeta:
fromDatabase = True
################################################################################
# CSV file handling
# We use the Excel dialect because both Excel and OO.org suggest this
# by default.
input_file = 'SGI_file.csv'
source = open(input_file)
csv_reader = csv.reader(source)
for row in csv_reader:
# row has a list of read fields: file name, pt_BR name and en_US name
record = Documents.select(Documents.q.file == row[0])
print "Fixing", row[0], "with pt_BR desc of", row[1], "and en_US of",
row[2]
record[0].obs = row[1]
record[0].obsEn = row[2]
===============================================================================
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---