SMART
SMART copied to clipboard
Add newline display to project descriptions and annotation cards
Fixes #46. I need to display formatted content, and this requires that I have newlines for my project description, tag/label descriptions and especially the annotation cards themselves.
The project detail template had to be altered to use the linebreaks
option for the description. This was the only change required to make this work.
To make the cards use newlines, I had to alter both front-end and back-end components.
- I had to alter the
StringIO
wrapper around the form to use thenewline=None
parameter for CSV/TSV types. - I removed the stripping of
\n
and\r
from the backenddjango.core.utils.util.create_data_from_csv
method. - I then used
connection.cursor.copy_expert
with a raw SQL string I created that uses theCOPY FROM stdin WITH (FORMAT 'csv', DELIMITER E'\\t'
function of Postgres. It was not possible to generate the field list, sinceData._meta.get_fields()
returns more than the fields we need. - I had to convert any
\n
or\r
characters in the React card template into<br />
s, since newlines have no effect in HTML. The clean way to do this was to wrap each line of texts into its own<span>text<br/></span>
, so that is what I did.
That was it! Now you can more richly format project descriptions and cards :)
Here are images showing it works:
Updated to fix flake8 problems...
@rchew Any chance you could take a look at this? It makes the system much more useful as you can now display semi-structured data.