Skip to content
Snippets Groups Projects
Commit d446bd1c authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Added add item buttons.

parent 2615e949
No related branches found
No related tags found
1 merge request!42Added add item buttons.
......@@ -194,6 +194,7 @@ class ViewAndEditTableTab(object):
# And return the context
return {
'add_button_for': self._get_item_type_filter(kwargs),
'type_label': kwargs.get('label', '?'),
'table': table,
'upload_form': upload_form,
......@@ -205,6 +206,38 @@ class ViewAndEditTableTab(object):
})
}
def _get_item_type_filter(self, kwargs):
""" If this tab displays a single item-type, return the associated
term
This parses the filters to see if there is any item-types
filter. Items can only have one item type.
Args:
kwargs: Tab settings
Returns:
dict or None: The term object
"""
if 'filters' not in kwargs or 'terms' not in kwargs['filters']:
return None
for filter_expr in kwargs['filters']['terms']:
try:
(tax, name) = filter_expr.split(':', 1)
except ValueError:
# Not our place to validate this.
pass
if tax == 'item-types':
matches = transport.terms.list(
taxonomy=tax,
name=name
)
if len(matches) > 0:
return matches[0]
return None
def _get_view_and_edit_form_request_parameters(params):
""" Return the parameters of the given request.
......
......@@ -5,15 +5,24 @@
<div class="panel-heading panel-heading-large clearfix">
<span class="fa fa-table fa-fw"></span>
<h2>{{ type_label }}</h2>
<div class="pull-right">
<div class="pull-right btn-group">
{% if add_button_for %}
<a class="btn btn-primary" type="button"
href="{% url "add-item" item_type=add_button_for.name %}?next={{ request.path }}">
<span class="fa fa-fw fa-plus-square"></span>
{% blocktrans with add_button_for.long_name as label %}
Add {{ label }}
{% endblocktrans %}
</a>
{% endif %}
{% if upload_form %}
<form action="{% url "sources-upload" %}"
method="post"
enctype="multipart/form-data"
class="auto-upload-file">
class="auto-upload-file pull-left">
{% csrf_token %}
{% bootstrap_form upload_form show_label=False %}
<a class="btn item-source-upload btn-block btn-primary upload-button" type="button" value="Upload" href="{% url "tabbed-page" name="main" tab_name="all" %}"><span class="fa fa-upload fa-fw"></span>{% blocktrans %}Upload {{ type_label }}{% endblocktrans %}</a>
<a class="btn item-source-upload btn-primary upload-button pull-left" type="button" value="Upload" href="{% url "tabbed-page" name="main" tab_name="all" %}"><span class="fa fa-upload fa-fw"></span>{% blocktrans %}Upload {{ type_label }}{% endblocktrans %}</a>
</form>
{% endif %}
</div>
......
......@@ -337,3 +337,28 @@ def test_views_item_get_request_parameters_sets_default_action_and_location():
}
actual = _get_view_and_edit_form_request_parameters(query)
assert actual.dict() == expected
@pytest.mark.django_db
def test_view_and_edit_table_tab_sets_add_button_context():
item_types = TaxonomyFactory(slug="item-types", name="Item Types")
test_item_type = TermFactory(
name='test-item-type',
taxonomy=item_types,
long_name="Test Item Type"
)
page = TabbedPageFactory()
tab_instance = TabInstanceFactory(page=page)
request = Mock(GET={})
tab = ViewAndEditTableTab()
filters = {'terms': ['item-types:test-item-type']}
context_data = tab.get_context_data(
tab_instance, request, filters=filters
)
assert context_data['add_button_for'] == {
'taxonomy': 'item-types',
'name': test_item_type.name,
'long_name': test_item_type.long_name
}
......@@ -78,6 +78,11 @@ td.created, td.timestamp {
float:inherit;
}
// Add/upload buttons
.panel-heading .btn-group .btn {
margin-left: 15px;
}
// Button header (and footer) for tables
.panel-body form .table-button-group {
margin-bottom: @padding-base-vertical;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment