question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Custom CSV Dialect

See original GitHub issue

Use-case

  • Data is exported to be imported into another application.
  • Some applications only support one specific CSV dialect. (For example, the German tax consultancy software DATEV)
  • We need to give developers and administrators the choice to provide the dialect.

This will support the DRY principle, removing the need for case-specific implementations like this one: https://github.com/frappe/erpnext/blob/master/erpnext/regional/report/fichier_des_ecritures_comptables_[fec]/fichier_des_ecritures_comptables_[fec].js#L91-L97

Proposal

  1. Add Doctype “CSV Dialect” to frappe core.
  2. Extend UnicodeWriter to consider CSV Dialect

1. Add Doctype “CSV Dialect”

Proposed location: frappe.core.doctype.csv_dialect

Screenshots:

Some useful dialects

Dialect for German accounting monopolist

Fields:

Name Type Default
Quoting Select Minimal
Quote Character Data "
Delimiter Data ,
Doublequote Checkbox 1
Escape Character Data None
Line Terminator Data \r\n
Write Header Checkbox 1
Encoding Data utf-8

DocType:

https://github.com/alyf-de/frappe/blob/csv_dialect/frappe/core/doctype/csv_dialect/csv_dialect.json

2. Extend UnicodeWriter

Current: https://github.com/frappe/frappe/blob/bd2e410a02758733fd499273f497c13de25dced8/frappe/utils/csvutils.py#L96-L116

https://github.com/frappe/frappe/blob/d0e7690ae2f219c1688411a19f952179f885528d/frappe/public/js/frappe/misc/tools.js#L67-L77

Proposed: https://github.com/alyf-de/frappe/blob/csv_dialect/frappe/core/doctype/csv_dialect/csv_dialect.py

3. Give users the choice

In Report > Menu > Export > CSV, provide a link field to choose the CSV Dialect. Provided CSV shall conform to the dialect.

Result

Before a call to to_csv is made, we can ask the user to select a dialect which suits the target application. Required templates should come preinstalled and be set as default.

Thanks for reviewing. Maybe from @anandpdoshi who built the csv export?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vrmscommented, Feb 14, 2019

I don’t think @anandpdoshi is still an (active) member here any longer. So we may need to find someone else to review this.

1reaction
rmehtacommented, Mar 19, 2019

Looks good 👍 maybe we can encapsulate the behaviour inside the CSV Dialect DocType

Read more comments on GitHub >

github_iconTop Results From Across the Web

csv — CSV File Reading and Writing — Python 3.11.1 ...
csvfile can be any object with a write() method. If csvfile is a file object, it should be opened with newline='' 1. An...
Read more >
Python: Misleading Documentation of csv module Dialect class
Dialect.delimiter A one-character string used to separate fields. It defaults to ','. python · python-3.x · csv.
Read more >
Python CSV: Read And Write CSV Files - Python Land
You can create your own custom dialect by defining the dialect parameters yourself. This can be useful if you need to write a...
Read more >
Working with CSV Files | SpringerLink
This chapter introduces a module that supports the generation of CSV (or Comma Separated Values) files.
Read more >
Wrangling Messy CSV Files by Detecting Row and ... - arXiv
In this paper, we propose a dialect detection method based on a novel measure of data consistency of parsed data files. Our method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found