-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #904 from jazzband/899-merge-tags
Enable Tag Merging
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% extends "admin/base.html" %} {% block content %} | ||
<div id="mergeTagsModal"> | ||
<div> | ||
<div> | ||
<div> | ||
<form | ||
id="merge-tags-form" | ||
method="post" | ||
action="{% url 'admin:taggit_tag_merge_tags' %}" | ||
> | ||
{% csrf_token %} {% for field in form %} | ||
<div> | ||
{{ field.label_tag }} {{ field }} {% if field.errors %} | ||
<ul class="errorlist"> | ||
{% for error in field.errors %} | ||
<li>{{ error }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
{% endfor %} | ||
<p><i><strong>Enter new or existing tag name</strong></strong></i></p> | ||
<div> | ||
<input type="submit" class="btn btn-primary"></input> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from taggit.models import Tag | ||
|
||
from .models import Food | ||
|
||
|
||
|
@@ -10,6 +12,11 @@ def setUp(self): | |
super().setUp() | ||
self.apple = Food.objects.create(name="apple") | ||
self.apple.tags.add("Red", "red") | ||
self.pear = Food.objects.create(name="pear") | ||
self.pear.tags.add("red", "RED") | ||
self.peach = Food.objects.create(name="peach") | ||
self.peach.tags.add("red", "Yellow") | ||
|
||
user = User.objects.create_superuser( | ||
username="admin", email="[email protected]", password="password" | ||
) | ||
|
@@ -40,3 +47,33 @@ def test_get_change(self): | |
reverse("admin:tests_food_change", args=(self.apple.pk,)) | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_tag_merging(self): | ||
response = self.client.get(reverse("admin:taggit_tag_changelist")) | ||
|
||
# merging red and RED into Red | ||
pks_to_select = [Tag.objects.get(name="red").pk, Tag.objects.get(name="RED").pk] | ||
response = self.client.post( | ||
reverse("admin:taggit_tag_changelist"), | ||
data={"action": "render_tag_form", "_selected_action": pks_to_select}, | ||
) | ||
# we're redirecting | ||
self.assertEqual(response.status_code, 302) | ||
# make sure what we expected got into the session keys | ||
assert "selected_tag_ids" in self.client.session.keys() | ||
self.assertEqual( | ||
self.client.session["selected_tag_ids"], ",".join(map(str, pks_to_select)) | ||
) | ||
|
||
# let's do the actual merge operation | ||
response = self.client.post( | ||
reverse("admin:taggit_tag_merge_tags"), {"new_tag_name": "Red"} | ||
) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
# time to check the result of the merges | ||
self.assertSetEqual({tag.name for tag in self.apple.tags.all()}, {"Red"}) | ||
self.assertSetEqual({tag.name for tag in self.pear.tags.all()}, {"Red"}) | ||
self.assertSetEqual( | ||
{tag.name for tag in self.peach.tags.all()}, {"Yellow", "Red"} | ||
) |