示例#1
0
 def action_export_as_ods(self, resource, context, form):
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # XXX Create a new process and send ODS file by mail for performances ?
     # XXX We do not export product without declination
     # XXX We do not export product without product model
     # Get list of groups
     groups = []
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         if group.get_property('use_default_price') is True:
             continue
         groups.append(group)
     # DB
     root = context.root
     shop = get_shop(resource)
     document = odf_new_document_from_type('spreadsheet')
     body = document.get_body()
     models = shop.get_resource('products-models').get_resources()
     for product_model in models:
         lines = []
         # We create one TAB by product model
         table = odf_create_table(product_model.get_title())
         search = root.search(product_model=str(product_model.get_abspath()))
         for brain in search.get_documents():
               product = root.get_resource(brain.abspath)
               for d in product.search_resources(cls=Declination):
                   # Ref - Declination name - Declination title
                   line = [product.get_property('reference'),
                           d.name,
                           d.get_declination_title().encode('utf-8')]
                   # Stock
                   line.append(str(d.get_quantity_in_stock()))
                   # Price by group (HT or TTC)
                   for group in groups:
                       k_price = {'id_declination': d.name,
                                  'prefix': group.get_prefix(),
                                  'pretty': True}
                       if group.get_property('show_ht_price'):
                           price = product.get_price_without_tax(**k_price)
                       else:
                           price = product.get_price_with_tax(**k_price)
                       line.append(str(price))
                   # Add row
                   lines.append(','.join(line))
         data = '\n'.join(lines)
         table = import_from_csv(StringIO(data), product_model.name)
         body.append(table)
     # Extport as ODS
     f = StringIO()
     document.save(f)
     content = f.getvalue()
     f.close()
     # Return ODS
     context.set_content_type('application/vnd.oasis.opendocument.spreadsheet')
     context.set_content_disposition('attachment', 'export.ods')
     return content
示例#2
0
def add_csv(filename, output_doc):
    output_body = output_doc.get_body()

    # Make the name
    name = splitext(basename(filename))[0]
    name = _get_table_name(name, output_body)

    table = import_from_csv(filename, name)

    output_body.append(table)
示例#3
0
def add_csv(filename, output_doc):
    output_body = output_doc.get_body()

    # Make the name
    name = splitext(basename(filename))[0]
    name = _get_table_name(name, output_body)

    table = import_from_csv(filename, name)

    output_body.append(table)
 def setUp(self):
     self.table = import_from_csv(StringIO(csv_data), u"From CSV")
示例#5
0
# Import from the Standard Library
from glob import glob

# Import from lpod
from lpod.document import odf_new_document_from_type
from lpod.frame import odf_create_image_frame
from lpod.paragraph import odf_create_paragraph
from lpod.table import import_from_csv, odf_create_column

# Get elements
document = odf_new_document_from_type('spreadsheet')
body = document.get_body()

for id, filename in enumerate(glob('./files/*.csv')):
    table = import_from_csv(filename, u'Table %s' % (id + 1))

    # Some information
    width = table.get_table_width()
    height = table.get_table_height()

    # Remove empty rows and cells on the edge
    table.rstrip_table()

    # Accessing rows
    first_row = table.get_row(0)
    first_row.set_row_style(u"Another style")

    # Accessing cells from the row
    first_cell = first_row.get_cell(0)
示例#6
0
 def action_export_as_ods(self, resource, context, form):
     if lpod_is_install is False:
         msg = ERROR(u'Please install LPOD')
         return context.come_back(msg)
     # XXX Create a new process and send ODS file by mail for performances ?
     # XXX We do not export product without declination
     # XXX We do not export product without product model
     # Get list of groups
     groups = []
     for option in UserGroup_Enumerate.get_options():
         group = context.root.get_resource(option['name'])
         if group.get_property('use_default_price') is True:
             continue
         groups.append(group)
     # DB
     root = context.root
     shop = get_shop(resource)
     document = odf_new_document_from_type('spreadsheet')
     body = document.get_body()
     models = shop.get_resource('products-models').get_resources()
     for product_model in models:
         lines = []
         # We create one TAB by product model
         table = odf_create_table(product_model.get_title())
         search = root.search(
             product_model=str(product_model.get_abspath()))
         for brain in search.get_documents():
             product = root.get_resource(brain.abspath)
             for d in product.search_resources(cls=Declination):
                 # Ref - Declination name - Declination title
                 line = [
                     product.get_property('reference'), d.name,
                     d.get_declination_title().encode('utf-8')
                 ]
                 # Stock
                 line.append(str(d.get_quantity_in_stock()))
                 # Price by group (HT or TTC)
                 for group in groups:
                     k_price = {
                         'id_declination': d.name,
                         'prefix': group.get_prefix(),
                         'pretty': True
                     }
                     if group.get_property('show_ht_price'):
                         price = product.get_price_without_tax(**k_price)
                     else:
                         price = product.get_price_with_tax(**k_price)
                     line.append(str(price))
                 # Add row
                 lines.append(','.join(line))
         data = '\n'.join(lines)
         table = import_from_csv(StringIO(data), product_model.name)
         body.append(table)
     # Extport as ODS
     f = StringIO()
     document.save(f)
     content = f.getvalue()
     f.close()
     # Return ODS
     context.set_content_type(
         'application/vnd.oasis.opendocument.spreadsheet')
     context.set_content_disposition('attachment', 'export.ods')
     return content
示例#7
0
 def setUp(self):
     self.table = import_from_csv(StringIO(csv_data), u"From CSV")