Merge pull request #309 from dbrgn/actions_on_top_bottom

Implemented actions_on_top and actions_on_bottom
This commit is contained in:
Daniel Greenfeld 2013-07-08 09:58:12 -07:00
commit 2ec6441de3
5 changed files with 48 additions and 27 deletions

View file

@ -2,7 +2,7 @@ $(function() {
var element = $("#model-list");
var selectAllCheckbox = element.find('.model-select-all');
var selectCheckbox = element.find('.model-select');
var selectedCount = element.find('#selected-count');
var selectedCount = element.find('.selected-count');
var updateSelectedCount = function() {
var count = 0;

View file

@ -0,0 +1,24 @@
{% load admin2_tags i18n %}
<div class="navbar actions-{{ position }}">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{% for action in actions %}
<li><a tabindex="-1" href="#" data-name="action" data-value="{{ action.name }}">{{ action.description }}</a></li>
{% endfor %}
</ul>
</div>
<input type="hidden" name="action" value="" />
<small class="muted">
{% blocktrans with selected='<span class="selected-count">0</span>' total=object_list|length %}{{selected}} of {{total}} selected{% endblocktrans %}
</small>
<div class="pull-right">
{% if permissions.has_add_permission %}
<a href="{% url view|admin2_urlname:'create' %}" class="btn"><i class="icon-plus"></i> {% blocktrans with model_verbose_name=model|model_verbose_name %}Add {{ model_verbose_name }}{% endblocktrans %}</a>
{% endif %}
</div>
</div>

View file

@ -42,29 +42,10 @@
{% csrf_token %}
<div class="span12">
<div class="navbar">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{% for action in actions %}
<li><a tabindex="-1" href="#" data-name="action" data-value="{{ action.name }}">{{ action.description }}</a></li>
{% endfor %}
</ul>
</div>
<input type="hidden" name="action" value="" />
<small class="muted">
{% blocktrans with selected='<span id="selected-count">0</span>' total=object_list|length %}{{selected}} of {{total}} selected{% endblocktrans %}
</small>
<div class="pull-right">
{% if permissions.has_add_permission %}
<a href="{% url view|admin2_urlname:'create' %}" class="btn"><i class="icon-plus"></i> {% blocktrans with model_verbose_name=model|model_verbose_name %}Add {{ model_verbose_name }}{% endblocktrans %}</a>
{% endif %}
</div>
</div>
{% if view.model_admin.actions_on_top %}
{% include 'djadmin2/bootstrap/includes/list_actions.html' with position='top' %}
{% endif %}
<table class="table table-bordered table-striped">
<thead>
@ -110,7 +91,12 @@
</tbody>
</table>
{{ object_list|length }} {{ model_name_pluralized }}
{% if view.model_admin.actions_on_bottom %}
{% include 'djadmin2/bootstrap/includes/list_actions.html' with position='bottom' %}
{% endif %}
<div>{{ object_list|length }} {{ model_name_pluralized }}</div>
</div>
</form>

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals
from django.contrib import messages
from django.utils.translation import ugettext_lazy
@ -37,6 +38,8 @@ class PostAdmin(djadmin2.ModelAdmin2):
class CommentAdmin(djadmin2.ModelAdmin2):
search_fields = ('body', '=post__title')
list_filter = ['post', ]
actions_on_top = True
actions_on_bottom = True
# Register each model with the admin

View file

@ -24,16 +24,18 @@ class AdminIndexTest(BaseIntegrationTest):
response = self.client.get(reverse("admin2:dashboard"))
self.assertContains(response, reverse("admin2:blog_post_index"))
class UserListTest(BaseIntegrationTest):
def test_search_users_m2m_group(self):
# This test should cause the distinct search path to exectue
group = Group.objects.create(name="Test Group")
self.user.groups.add(group)
params = {"q":"group"}
params = {"q": "group"}
response = self.client.get(reverse("admin2:auth_user_index"), params)
self.assertContains(response, 'user')
class CommentListTest(BaseIntegrationTest):
def test_search_comments(self):
# Test search across Foriegn Keys
@ -43,7 +45,7 @@ class CommentListTest(BaseIntegrationTest):
Comment.objects.create(body="comment_post_1_b", post=post_1)
Comment.objects.create(body="comment_post_2", post=post_2)
params = {"q":"post_1_title"}
params = {"q": "post_1_title"}
response = self.client.get(reverse("admin2:blog_comment_index"), params)
self.assertContains(response, "comment_post_1_a")
self.assertContains(response, "comment_post_1_b")
@ -66,6 +68,12 @@ class PostListTest(BaseIntegrationTest):
response = self.client.get(reverse("admin2:blog_post_index"))
self.assertInHTML('<a tabindex="-1" href="#" data-name="action" data-value="DeleteSelectedAction">Delete selected items</a>', response.content)
def test_actions_displayed_twice(self):
# If actions_on_top and actions_on_bottom are both set
response = self.client.get(reverse("admin2:blog_comment_index"))
self.assertContains(response, '<div class="navbar actions-top">')
self.assertContains(response, '<div class="navbar actions-bottom">')
def test_delete_selected_post(self):
post = Post.objects.create(title="A Post Title", body="body")
params = {'action': 'DeleteSelectedAction', 'selected_model_pk': str(post.pk)}
@ -89,7 +97,7 @@ class PostListTest(BaseIntegrationTest):
Post.objects.create(title="A Post Title", body="body")
Post.objects.create(title="Another Post Title", body="body")
Post.objects.create(title="Post With Keyword In Body", body="another post body")
params = {"q":"another"}
params = {"q": "another"}
response = self.client.get(reverse("admin2:blog_post_index"), params)
self.assertContains(response, "Another Post Title")
self.assertContains(response, "Post With Keyword In Body")