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 1 commit
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
15 changes: 13 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 @@ -710,9 +711,19 @@ def get_action_links(self):

return self._allowed_action_links

def _get_custom_attributes(self, action_link):
attributes = None
if len(action_link) == 4:
attributes = action_link[3]
# take into account that 3 parameter can be string icon class
elif len(action_link) == 3 and isinstance(action_link[2], dict):
attributes = action_link[2]
return attributes

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 = action_link[2] if len(action_link) >= 3 and isinstance(action_link[2], str) else None
return {"label": action_link[0], "url": action_link[1],
"icon": icon, "attributes": self._get_custom_attributes(action_link)}

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
2 changes: 2 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ 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.
`('name', 'base_url', 'optional icon class', {'custom_attr_name': 'custom_attr_value'})`

### `get_field_actions(row)`

Expand Down