Skip to content

Commit

Permalink
added ability to specify not required parameter for action link. Fixe…
Browse files Browse the repository at this point in the history
…d `title` attribute fr links.
  • Loading branch information
wolendranh committed Nov 9, 2018
1 parent c6b482a commit ec3298d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit ec3298d

Please sign in to comment.