Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add newline display to project descriptions and annotation cards #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rjurney
Copy link
Contributor

@rjurney rjurney commented Feb 27, 2020

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 :)

…tions and annotation cards. Altered backend to serialize the CSV uploads to Postgres while retaining \n and \r characters. Altered frontend React Card template to split on \n or \r, wrap each line in a span with a <br/> inside of it.
@rjurney
Copy link
Contributor Author

rjurney commented Feb 27, 2020

Here are images showing it works:

image

image

@rjurney
Copy link
Contributor Author

rjurney commented Feb 27, 2020

Updated to fix flake8 problems...

@rjurney
Copy link
Contributor Author

rjurney commented Mar 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display newlines for project descriptions, tag descriptions and annotation cards
1 participant