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

#18 combine name and email display #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,14 @@ Help text may be provided in multiple languages like [label fields](#label).
### `help_inline`

Display help text inline if set to `true`. Default is `false`.

### `hide_field`
Hide the field from the `package_read` view if set to `true`.
This is useful for name fields, such as `author`, in combination with related
email fields, such as `author_email`.

### `display_email_name_field`
Useful for email fields, this property specifies the `field_name` of the related
name field. The label will be the titlecased `field_name` (e.g. "Author" instead
of "Author Email"); the value will be rendered with `field_name`'s value, i.e.
the email will be rendered as a clickable name.
17 changes: 17 additions & 0 deletions ckanext/scheming/camel_photos.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@
}
]
},
{
"field_name": "photographer",
"label": "Photographer",
"help_text": "This field will be collapsed with the related email field if hide_field and display_email_name_field are set accordingly.",
"help_inline": true,
"form_placeholder": "Joe Bloggs",
"display_property": "dc:creator",
"hide_field": "true"
},
{
"field_name": "photographer_email",
"label": "Photographer Email",
"form_placeholder": "[email protected]",
"display_property": "dc:creator",
"display_snippet": "email.html",
"display_email_name_field": "photographer"
},
{
"field_name": "a_relevant_date",
"label": "A relevant date",
Expand Down
6 changes: 4 additions & 2 deletions ckanext/scheming/ckan_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"field_name": "author",
"label": "Author",
"form_placeholder": "Joe Bloggs",
"display_property": "dc:creator"
"display_property": "dc:creator",
"display_field": false
},
{
"field_name": "author_email",
Expand All @@ -69,7 +70,8 @@
"field_name": "maintainer",
"label": "Maintainer",
"form_placeholder": "Joe Bloggs",
"display_property": "dc:contributor"
"display_property": "dc:contributor",
"display_field": false
},
{
"field_name": "maintainer_email",
Expand Down
5 changes: 3 additions & 2 deletions ckanext/scheming/templates/scheming/package/read.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{% extends "package/read.html" %}

{%- set schema = h.scheming_get_dataset_schema(dataset_type) -%}

<!-- template scheming package read -->
{% block package_notes %}
{%- if not dataset_type -%}
<p>
dataset_type not passed to template. your version of CKAN
might not be compatible with ckanext-scheming
</p>
{%- endif -%}
{% if 'notes' in schema.dataset_fields and c.pkg_notes_formatted %}
{# if 'notes' in schema.dataset_fields and c.pkg_notes_formatted #}
{% if c.pkg_notes_formatted %}
<div class="notes embedded-content">
{{ c.pkg_notes_formatted }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,36 @@
{%- set exclude_fields = [
'id',
'title',
'name',
'notes',
'name',
'tag_string',
'license_id',
'owner_org',
] -%}
'owner_org'
] -%}

{% block package_additional_info %}

{%- for field in schema.dataset_fields -%}
{%- if field.field_name not in exclude_fields
and field.display_snippet is not none -%}
{%- if field.field_name not in exclude_fields -%}
{%- if not field.hide_field -%}
<tr>
<th scope="row" class="dataset-label">{{
h.scheming_language_text(field.label) }}</th>
<td class="dataset-details"{%
if field.display_property %} property="{{ field.display_property
}}"{% endif %}>{%- snippet 'scheming/snippets/display_field.html',
field=field, data=pkg_dict, schema=schema -%}</td>
<th scope="row" class="dataset-label">
{% if field.display_email_name_field %}
{{ h.scheming_language_text(field.display_email_name_field)|title }}
{% else %}
{{ h.scheming_language_text(field.label) }}
{% endif %}
</th>
<td class="dataset-details"
{% if field.display_property %}
property="{{ field.display_property}}"
{% endif %}>
{%- snippet 'scheming/snippets/display_field.html',
field=field, data=pkg_dict -%}
</td>
</tr>
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{% if h.check_access('package_update',{'id':pkg_dict.id}) %}
<tr>
Expand Down
6 changes: 6 additions & 0 deletions ckanext/scheming/tests/test_dataset_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def test_dataset_displays_custom_fields(self):
type='camel-photos',
name='set-one',
humps=3,
photographer='John Newton',
photographer_email='[email protected]',
resources=[{
'url':"http://example.com/camel.txt",
'camels_in_photo': 2}])
Expand All @@ -27,6 +29,8 @@ def test_resource_displays_custom_fields(self):
type='camel-photos',
name='set-two',
humps=3,
photographer='John Newton',
photographer_email='[email protected]',
resources=[{
'url':"http://example.com/camel.txt",
'camels_in_photo': 2}])
Expand All @@ -41,6 +45,8 @@ def test_choice_field_shows_labels(self):
d = Dataset(
user=user,
type='camel-photos',
photographer='John Newton',
photographer_email='[email protected]',
name='with-choice',
category='hybrid',
)
Expand Down