Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
ckanext-odsh
Commits
9d9fecfe
Commit
9d9fecfe
authored
7 months ago
by
Thorge Petersen
Browse files
Options
Downloads
Patches
Plain Diff
Add package custom fields
parent
6cf88b4f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ckanext/odsh/templates/package/snippets/package_metadata_fields.html
+6
-0
6 additions, 0 deletions
...h/templates/package/snippets/package_metadata_fields.html
ckanext/odsh/templates/snippets/custom_form_fields.html
+46
-0
46 additions, 0 deletions
ckanext/odsh/templates/snippets/custom_form_fields.html
with
52 additions
and
0 deletions
ckanext/odsh/templates/package/snippets/package_metadata_fields.html
+
6
−
0
View file @
9d9fecfe
...
...
@@ -15,4 +15,10 @@
{{ form.input(field, label=_('Is replaced by'), placeholder=_('https://'), value=value, error=error,
classes=['control-full']) }}
{% block package_metadata_fields_custom %}
{% block custom_fields %}
{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
{% endblock %}
{% endblock %}
{% endblock %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ckanext/odsh/templates/snippets/custom_form_fields.html
0 → 100644
+
46
−
0
View file @
9d9fecfe
{#
Adds a block of custom form fields.
extras - The fields to add.
errors - A dict of errors for the fields.
limit - The total number of fields that should be output.
Example:
{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
#}
{% import "macros/form.html" as form %}
<div
data-module=
"custom-fields"
>
{% set custom_extras = ['licenseAttributionByText', 'temporal_start', 'temporal_end', 'issued', 'spatial_uri', 'groups'] %}
{% for extra in extras %}
{% if extra.key not in custom_extras %}
{% set prefix = 'extras__%d__' % (loop.index0 + (custom_extras|count)) %}
{{ form.custom(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % loop.index0,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endif %}
{% endfor %}
{# Add a max of 3 empty columns #}
{% set total_extras = data.extras|count %}
{% if total_extras
<
=
(
custom_extras
|
count
)
%}{%
set
total_extras =
(custom_extras|count)
%}{%
endif
%}
{%
set
empty_extras =
(limit
or
3)
-
total_extras
%}
{%
if
empty_extras
<=
0
%}{%
set
empty_extras =
1
%}{%
endif
%}
{%
for
extra
in
range
(
total_extras
,
total_extras
+
empty_extras
)
%}
{%
set
index =
loop.index0
+
total_extras
%}
{%
set
prefix =
'extras__%d__'
%
index
%}
{{
form.custom
(
names=
(prefix
~
'
key
',
prefix
~
'
value
',
prefix
~
'
deleted
'),
id=
'field-extras-%d'
%
index
,
label=
_('Custom
Field
'),
values=
(extra.key,
extra.value
,
extra.deleted
),
error=
errors[prefix
~
'
key
']
or
errors
[
prefix
~
'
value
']
)
}}
{%
endfor
%}
</
div
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment