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

added ability to specify not required parameter for action link. Fixe… #321

Merged
merged 2 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ def _get_field_actions(self, obj):
)
),
"modal": self.get_modal_link(field_action["url"], obj),
'attributes': field_action["attributes"]
}
)
return actions
Expand Down Expand Up @@ -711,8 +712,16 @@ def get_action_links(self):
return self._allowed_action_links

def _build_action_link(self, action_link):
icon = action_link[2] if len(action_link) == 3 else None
return {"label": action_link[0], "url": action_link[1], "icon": icon}
icon, attributes = None, None
if len(action_link) == 3:
# icon can be 3-rd arg of link or specified inside inside dict with same index
if isinstance(action_link[2], str):
icon = action_link[2]
elif isinstance(action_link[2], dict):
icon = action_link[2].get('icon_class', None)
attributes = action_link[2].get('attributes', None)
return {"label": action_link[0], "url": action_link[1],
"icon": icon, "attributes": attributes}

def get_tool_links(self):
if not self.tool_links:
Expand Down
7 changes: 6 additions & 1 deletion arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ <h4 class="arctic-card__title">
{% block list_actions %}
<div class="list-actions">
{% for action in row.actions %}
<a href="{{ action.url }}" class="action-{{ action.label }} btn btn-secondary btn-sm show-on-hover" title="{{ link.label|capfirst }}"
<a href="{{ action.url }}" class="action-{{ action.label }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
{% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
{% if action.attributes %}
{% for attr_name, attr_value in action.attributes.items %}
{{ attr_name }}="{{ attr_value }}"
{% endfor %}
{% endif %}
>
{% if action.icon %}
<i class="fa {{ action.icon }} fa-lg"></i>
Expand Down
3 changes: 3 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ standard notation by prepending a minus to the field, for example `-name`.
optional list of `('name', 'base_url', 'optional icon class')` links, that
appear on the last column of the table and can apply a certain action, such
as delete.
In case if some custom attributes required, they can be specified as last argument in form of dict. In this case
optional icon class can be provided as part of that argument dict
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'custom_attr_name': 'custom_attr_value'}})`

### `get_field_actions(row)`

Expand Down