Skip to content

Commit

Permalink
Added newlines in the Note field
Browse files Browse the repository at this point in the history
  • Loading branch information
TsimpDim committed Jun 4, 2018
1 parent cd534c9 commit 6ebbaf9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions _3RStore/templates/resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ <h4><a href="{{re.link}}" class="re_info">{{re.title}}</a></h4>
<!-- Note section -->
{% if re.note %}
<div class="card-footer">
{% if re.note|length > 600 %}
{% if re.note.split('</br>') | length > 5 %} <!-- If note has more than 5 lines -->
<button class="btn btn-info" type="button" data-toggle="collapse" data-target="#{{re.re_id}}_note">Expand/Collapse Note</button>
<p id="{{re.re_id}}_note" class="collapse re_note"><br>{{re.note}}</p>
<p id="{{re.re_id}}_note" class="collapse re_note"><br>{{ re.note | safe }}</p>
{% else %}
<p id="{{re.re_id}}_note" class="re_note" >{{re.note}}</p>
<p id="{{re.re_id}}_note" class="re_note">
{{ re.note | safe }}
</p>
{% endif %}
</div>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions _3RStore/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def add_resource():
if request.method == 'POST' and form.validate():
title = form.title.data
link = parse.unquote(form.link.data)
note = form.note.data
note = form.note.data.replace('\n','</br>') # So we can show the newlines in the note section
timestamp = datetime.datetime.fromtimestamp(
time()).strftime('%Y-%m-%d %H:%M:%S')

Expand Down Expand Up @@ -344,7 +344,7 @@ def edit_res(user_id, re_id):
form = forms.ResourceForm()
form.title.data = data[0]['title']
form.link.data = data[0]['link']
form.note.data = data[0]['note']
form.note.data = data[0]['note'].replace('</br>','\n') # Else the </br> tags will display as text

if data[0]['tags']:
form.tags.data = ','.join(data[0]['tags']) # Array to string
Expand All @@ -362,7 +362,7 @@ def edit_res(user_id, re_id):
# Grab the new form and its data
title = form.title.data
link = form.link.data
note = form.note.data
note = form.note.data.replace('\n','</br>') # Save newlines as </br> to display them properly later
tags = form.tags.data

# If not empty format for proper insertion into postgresql
Expand Down

0 comments on commit 6ebbaf9

Please sign in to comment.