Skip to content

Render fields as markdown #1747

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/onegov/org/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3348,6 +3348,9 @@
elif self.directory.numbering == 'custom':
self.custom_body_attributes['data-default-marker-icon'] = 'custom'

def show_label(self, field: Field) -> bool:
return False

Check warning on line 3352 in src/onegov/org/layout.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/org/layout.py#L3352

Added line #L3352 was not covered by tests

@cached_property
def breadcrumbs(self) -> list[Link]:
return [
Expand Down
19 changes: 12 additions & 7 deletions src/onegov/org/templates/directory.pt
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@
<p tal:case="False">${directory.configuration.empty_notice}</p>
</tal:b>

<!--? display in accordion mode -->
<!-- display content fields of each entry in accordion mode -->
<ul tal:condition="directory.layout == 'accordion'" class="accordion" data-accordion>
<li tal:repeat="entry entries" class="accordion-navigation small-12-cell" style="">
<a tal:attributes="href python:'#panel'+str(repeat['entry'].index)">
<span class="h5">${entry.title}</span>
</a>
<div tal:attributes="id python:'panel'+str(repeat['entry'].index)" class="content">
<ul tal:repeat="field directory.fields" style="list-style: none; margin-left: 0">
<li tal:condition="field.type == 'textarea'" tal:define="key field.human_id; value entry.values[field.id]" tal:content="Markup('<strong>{}</strong>: <br>{}').format(key, value)" style="white-space: pre-wrap;"></li>
<li tal:condition="field.type != 'textarea'" tal:define="key field.human_id; value entry.values[field.id]" tal:content="Markup('<strong>{}</strong>: {}').format(key, value)"></li>
</ul>
<ul style="list-style: none; margin-left: 0">
<metal:b use-macro="layout.macros['display_fields']"
tal:define="
fields entry.content_fields;
allow_downloads True;
allow_views True;
form entry.directory.form_obj;
linkify_display True;
"
/>
<ul tal:condition="request.is_manager" style="list-style: none; margin-left: 0">
<li>
<a tal:condition="request.is_manager" class="edit-link" tal:attributes="href request.link(entry, 'edit')">
<a class="edit-link" tal:attributes="href request.link(entry, 'edit')">
<i class="fa fa-edit"></i>
</a>
</li>
Expand Down
8 changes: 8 additions & 0 deletions src/onegov/org/theme/styles/org.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3566,6 +3566,14 @@ button {

}

.accordion .accordion-navigation .field-display {
margin-bottom: 1rem;
}
.accordion .accordion-navigation .field-display dd a {
padding: 0;
display: inline;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there only a CSS change for Org, does Town6 not need one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fort town6 it was introduced with ogc-1634, ed93c7d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this change is about .field-display not .accordion-title or .accordion-content. If anything you'd be missing CSS rules for both Org and Town now, just different ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now found a way to make it independent of .field-display

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My problem is not with the rules you added or what elements they address.

I'm asking why you have custom CSS for the header and content of the accordion in Town6 and not Org, and why you have custom styling for the display of the fields in Org but not Town6.

If you're satisfied with how it looks in both styles I'm satisfied too.

I was merely puzzled by the difference between Org and Town6, since you've decided to manually style completely different elements in both cases. So I was asking whether or not that was intentional or if you accidentally forgot to sync the rules between Org and Town6.

/*
Popup Menu
*/
Expand Down
19 changes: 12 additions & 7 deletions src/onegov/town6/templates/directory.pt
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@
<tal:b content="text"/>
</div>

<!-- displaying in accordion mode -->
<!-- display content fields of each entry in accordion mode -->
<ul tal:condition="directory.layout == 'accordion'" class="accordion more-list page-links" data-accordion>
<li tal:repeat="entry entries" class="accordion-item small-12-cell" data-accordion-item style="">
<a href="#" class="accordion-title">
<span class="h5">${entry.title}</span>
</a>
<div class="accordion-content" data-tab-content>
<ul tal:repeat="field directory.fields" style="list-style: none; margin-left: 0">
<li tal:condition="field.type == 'textarea'" tal:define="key field.human_id; value entry.values[field.id]" tal:content="Markup('<strong>{}</strong>: <br>{}').format(key, value)" style="white-space: pre-wrap;"></li>
<li tal:condition="field.type != 'textarea'" tal:define="key field.human_id; value entry.values[field.id]" tal:content="Markup('<strong>{}</strong>: {}').format(key, value)"></li>
</ul>
<ul style="list-style: none; margin-left: 0">
<metal:b use-macro="layout.macros['display_fields']"
tal:define="
fields entry.content_fields;
allow_downloads True;
allow_views True;
form entry.directory.form_obj;
linkify_display True;
"
/>
<ul tal:condition="request.is_manager" style="list-style: none; margin-left: 0">
<li>
<a tal:condition="request.is_manager" class="edit-link" tal:attributes="href request.link(entry, 'edit')">
<a class="edit-link" tal:attributes="href request.link(entry, 'edit')">
<i class="far fa-edit"></i>
</a>
</li>
Expand Down
94 changes: 72 additions & 22 deletions tests/onegov/town6/test_views_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,84 @@ def test_directory_entry_subscription(client):

def test_create_directory_accordion_layout(client):

def create_directory(client, title):
page = (client.get('/directories').
click('Verzeichnis'))
def create_directory(client, title, structure):
page = (client.get('/directories').click('Verzeichnis'))
page.form['title'] = title
page.form['structure'] = "Question *= ___\nAnswer *= ___"
page.form['structure'] = structure
page.form['title_format'] = '[Question]'
page.form['content_fields'] = 'Question\nAnswer'
page.form['layout'] = 'accordion'
return page.form.submit().follow()

def edit_directory(client, dir_url_name, structure):
page = client.get(f'/directories/{dir_url_name}')
page = page.click('Konfigurieren')
page.form['structure'] = structure
return page.form.submit().form.submit().follow()

def create_directory_entry(directory, question, answer):
page = directory.click('Eintrag')
page.form['question'] = question
page.form['answer'] = answer
return page.form.submit().follow()

client.login_admin()
title = "Questions and Answers about smurfs"

faq_dir = create_directory(client, title)
title = "Questions and Answers about smurfs"
structure = "Question *= ___\nAnswer *= ___"
faq_dir = create_directory(client, title, structure)
assert title in faq_dir

question = "Are smurfs real?"
answer = "Yes, they are."
q1 = faq_dir.click('Eintrag')
q1.form['question'] = question
q1.form['answer'] = answer
q1 = q1.form.submit().follow()
assert question in q1
assert answer not in q1

question = "Who is the boss of the smurfs?"
q2 = faq_dir.click('Eintrag')
q2.form['question'] = question
q2.form['answer'] = 'Papa Schlumpf'
q2 = q2.form.submit().follow()
assert question in q2
assert answer not in q2
question_1 = "Are smurfs real?"
answer_1 = "Yes, they are."
page = create_directory_entry(faq_dir, question_1, answer_1)
assert question_1 in page
assert answer_1 in page

question_2 = "Who is the boss of the smurfs?"
answer_2 = "Papa Smurf"
page = create_directory_entry(faq_dir, question_2, answer_2)
assert question_2 in page
assert answer_2 in page

question_3 = "How many smurfs are there?"
answer_3 = '- Papa Smurf\n- Smurfette\n- Brainy Smurf\n- Grouchy Smurf'
q3 = create_directory_entry(faq_dir, question_3, answer_3)
assert question_3 in q3
for smurf in answer_3.split('\n'):
assert smurf in q3

page = client.get('/directories/questions-and-answers-about-smurfs')
assert question_1 in page
assert answer_1 in page
assert question_2 in page
assert answer_2 in page
assert question_3 in page
for smurf in answer_3.split('\n'):
assert smurf in page

# with multiline answers
structure = "Question *= ___\nAnswer *= ...[10]"
page = edit_directory(
client, 'questions-and-answers-about-smurfs', structure)
assert question_1 in page
assert answer_1 in page
assert question_2 in page
assert answer_2 in page
assert question_3 in page
for smurf in answer_3.split('\n'):
assert smurf in page

# with markdown answers
structure = "Question *= ___\nAnswer *= <markdown>"
page = edit_directory(
client, 'questions-and-answers-about-smurfs', structure)
assert question_1 in page
assert answer_1 in page
assert question_2 in page
assert answer_2 in page
assert question_3 in page
for smurf in answer_3.replace('- ', '').split('\n'):
assert smurf in page
# ensure markdown rendered each smurf in separate li tag
assert f'<li>{smurf}</li>' in page