SMART icon indicating copy to clipboard operation
SMART copied to clipboard

Add newline display to project descriptions and annotation cards

Open rjurney opened this issue 4 years ago • 3 comments

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 the newline=None parameter for CSV/TSV types.
  • I removed the stripping of \n and \r from the backend django.core.utils.util.create_data_from_csv method.
  • I then used connection.cursor.copy_expert with a raw SQL string I created that uses the COPY FROM stdin WITH (FORMAT 'csv', DELIMITER E'\\t' function of Postgres. It was not possible to generate the field list, since Data._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 :)

rjurney avatar Feb 27 '20 22:02 rjurney

Here are images showing it works:

image

image

rjurney avatar Feb 27 '20 22:02 rjurney

Updated to fix flake8 problems...

rjurney avatar Feb 27 '20 23:02 rjurney

@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.

rjurney avatar Mar 02 '20 19:03 rjurney