为什么我的CSV导出未应用到引用字段

时间:2018-12-10 08:41:56

标签: web2py

我正在尝试使用web2py SQLFORM.grid,但我导出的csv并不应用表示,因此即使创建了此类,它也会返回id而不是name

from io import StringIO

class CSVExporter(object):

file_ext = "csv"
content_type = "text/csv"

def __init__(self, rows):
    self.rows = rows

def export(self):
    if self.rows:
        s = StringIO()
        self.rows.export_to_csv_file(s, represent=True)
        return s.getvalue()
    else:
        return ''

然后将export_classes设置为

export_classes = dict(csv=(CSVExporter, 'CSV'), json=False, html=False,
                 xml=False, csv_with_hidden_cols=False,
                  tsv_with_hidden_cols=False)

但是然后我将csv和tsv都返回了id而不是名称,即使设置代表True之后,我正在使用python3和最新的web2py 2.17.2稳定

我的模型中有一些表格

SPECIAL = ('True', 'False')
db.define_table('driver',
            Field('name', 'string'),
            Field('password', 'password', readable=False),
            Field('company_id','string'),
            Field('license_number', 'string'),
            Field('email', requires=IS_EMAIL()),
            Field('status', default='Available'),
            Field('phone'),
            Field('details', 'text'),
            Field('self_driver','string',requires=IS_IN_SET(SPECIAL, multiple=False), default=SPECIAL[1]),
            Field('current_trip', readable=False, writable=False),
            Field('current_trip_type', readable=False,writable=False),
            format='%(name)s',
            migrate=False)
  db.driver.id.readable=False
  vehicle_status = ('Available', '')
  db.define_table('vehicle',
            Field('reg_number', 'string', requires=IS_NOT_EMPTY()),
            Field('make', 'string'),
            Field('current_mileage', 'integer', requires=IS_NOT_EMPTY(), default=0),
            Field('status', default='Available'),
            Field('description', 'text'),
            format='%(reg_number)s',
            migrate=False)

   db.vehicle.id.readable=False

   db.define_table('company',
            Field('name', 'string'),
            Field('description', 'text'),
            format='%(name)s',
            migrate=False)
 db.company.id.readable = False

 TRIP_TYPE = ('Airport', 'Town Run', 'Up Country Trip', 'Out of Country Trip')
 db.define_table('trip',
            Field('comp_id', 'reference company'),
            Field('vehicle_id', 'reference vehicle'),
            Field('driver_id', 'reference driver'),
            Field('start_date'),
            Field('departure'),
            Field('start_mileage', 'integer'),
            Field('end_date'),
            Field('destination'),
            Field('end_mileage', 'integer'),
            Field('status', default='In_Progress'),
            Field('trip_type', requires=IS_IN_SET(TRIP_TYPE, multiple=False), default=TRIP_TYPE[0]),
            Field('signature', readable=False,writable=False),
            Field('image_flag', 'integer', default=0, readable=False),
            Field('signature_path', 'upload', uploadfolder=os.path.join(request.folder, 'static/images/signatures'),
                  autodelete=True, readable=False),
            Field('departure_geo_lat', readable=False,writable=False),
            Field('departure_geo_long', readable=False,writable=False),
            Field('destination_geo_lat', readable=False,writable=False),
            Field('destination_geo_long', readable=False,writable=False),
            migrate=False)

0 个答案:

没有答案