Skip to content

Commit

Permalink
#296 simplified 'actions' in list_items content_data attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
d.choban committed May 30, 2018
1 parent c421add commit 8960492
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Always reference the ticket number at the end of the issue description.

- added data attribute data-id in base_data_table row to easily distinct rows

## Changed

- changed format of list items, simplified and moved to dict-like structure

## 1.1.1

Expand Down
4 changes: 2 additions & 2 deletions arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def get_list_items(self, objects): # noqa: C901

actions = self._get_field_actions(obj)
if actions:
row['actions'].append(actions)
row['actions'].extend(actions)
self.has_action_links = True
if self.sorting_field:
row['sorting_field'] = {
Expand Down Expand Up @@ -653,7 +653,7 @@ def get_list_items(self, objects):
row = {
'id': getattr(obj, 'id', ''),
'fields': [],
'actions': [],
'actions': []
}
for field_name in fields:
field = {'field': field_name, 'type': 'field'}
Expand Down
2 changes: 1 addition & 1 deletion arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def _get_field_actions(self, obj):
'confirm': self.get_confirm_link(
field_action['url'], obj),
})
return {'type': 'actions', 'actions': actions}
return actions

def _get_allowed_field_actions(self, field_actions, all_actions):
allowed_urls = [a['url'] for a in all_actions]
Expand Down
26 changes: 13 additions & 13 deletions arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,34 @@ <h4 class="arctic-card__title">
{% endif %}
</td>
{% endfor %}
{% for action in row.actions %}
{% if row.actions %}
<td>
{% block list_actions %}
<div class="list-actions">
{% for link in action.actions %}
<a href="{{ link.url }}" class="action-{{ link.label }} btn btn-secondary btn-sm show-on-hover" title="{{ link.label|capfirst }}"
{% if link.confirm %}
{% 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 }}"
{% if action.confirm %}
data-toggle="modal"
data-target="#confirm-dialog"
data-confirm-title="{{ link.confirm.title }}"
data-confirm-message="{{ link.confirm.message|linebreaks }}"
data-confirm-ok="{{ link.confirm.ok }}"
data-confirm-cancel="{{ link.confirm.cancel }}"
data-confirm-class="{{ link.confirm.class }}"
data-confirm-title="{{ action.confirm.title }}"
data-confirm-message="{{ action.confirm.message|linebreaks }}"
data-confirm-ok="{{ action.confirm.ok }}"
data-confirm-cancel="{{ action.confirm.cancel }}"
data-confirm-class="{{ action.confirm.class }}"
{% endif %}
>
{% if link.icon %}
<i class="fa {{ link.icon }} fa-lg"></i>
{% if action.icon %}
<i class="fa {{ action.icon }} fa-lg"></i>
{% else %}
{{ link.label|capfirst }}
{{ action.label|capfirst }}
{% endif %}
</a>
{% endfor %}
<div class="list-actions-placeholder"></div>
</div>
{% endblock %}
</td>
{% endfor %}
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 4 additions & 4 deletions tests/test_generics/test_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_field_actions(self, admin_client):
response = admin_client.get(reverse('articles:list'),
{'description': ''})
list_items = response.context_data['list_items']
assert len(list_items[0]['actions'][-1]['actions']) == 1
assert len(list_items[1]['actions'][-1]['actions']) == 2
assert len(list_items[0]['actions']) == 1
assert len(list_items[1]['actions']) == 2

def test_field_actions_allowing(self, admin_client):
def get_field_actions(self, obj):
Expand All @@ -178,5 +178,5 @@ def get_field_actions(self, obj):
response = admin_client.get(reverse('articles:list'),
{'description': ''})
list_items = response.context_data['list_items']
assert len(list_items[0]['actions'][-1]['actions']) == 1
assert len(list_items[1]['actions'][-1]['actions']) == 2
assert len(list_items[0]['actions']) == 1
assert len(list_items[1]['actions']) == 2

0 comments on commit 8960492

Please sign in to comment.