Skip to content

Commit

Permalink
feat(ISSUE-8): Formatting m2m confirmation values as html lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Thu Trang Pham committed Feb 20, 2021
1 parent 5d8d88e commit dd034ad
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 131 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package:
python3 setup.py sdist bdist_wheel

upload-testpypi:
python3 -m twine upload --repository testpypi dist/django_admin_confirm-$(VERSION)*
python3 -m twine upload --repository testpypi dist/django_admin_confirm-$(VERSION)

i-have-tested-with-testpypi-and-am-ready-to-release:
python3 -m twine upload --repository pypi dist/django_admin_confirm-$(VERSION)*
python3 -m twine upload --repository pypi dist/django_admin_confirm-$(VERSION)

install-testpypi:
python -m pip install --index-url https://test.pypi.org/simple/ django_admin_confirm
python -m pip install --index-url https://test.pypi.org/simple/ django_admin_confirm==${VERSION}
2 changes: 1 addition & 1 deletion admin_confirm/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _get_changed_data(
field_object = model._meta.get_field(name)
initial_value = getattr(obj, name)
if isinstance(field_object, ManyToManyField):
initial_value = field_object.value_to_string(obj)
initial_value = field_object.value_from_object(obj)

if initial_value != new_value:
changed_data[name] = [initial_value, new_value]
Expand Down
19 changes: 16 additions & 3 deletions admin_confirm/templatetags/formatting.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from django import template
from django.db.models.query import QuerySet
from django.utils.html import escape
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter
def format_change_data_field_value(field_value):
if isinstance(field_value, QuerySet):
return list(field_value)
if isinstance(field_value, str):
return field_value
try:
output = "<ul>"
for value in iter(field_value):
output += "<li>" + escape(value) + "</li>"
output += "</ul>"
return mark_safe(output)
except:
return field_value

return field_value
# if isinstance(field_value, QuerySet):
# return list(field_value)

# return field_value
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE=tests.test_project.settings.test
addopts = --doctest-modules -ra -l --tb=short --show-capture=log --color=yes
addopts = --doctest-modules -ra -l --tb=short --show-capture=stdout --color=yes
testpaths = admin_confirm
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="django-admin-confirm",
version="0.2.3.dev2",
version="0.2.3.dev3",
packages=["admin_confirm"],
description="Adds confirmation to Django Admin changes, additions and actions",
long_description_content_type="text/markdown",
Expand Down
121 changes: 0 additions & 121 deletions tests/test_project/settings.py

This file was deleted.

7 changes: 6 additions & 1 deletion tests/test_project/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .local import * # noqa
# For some reason the working directory of tests
# And running the server are different
# (Possibly due to test_project being within a subfolder)
# This defaults settings to local unless
# DJANGO_SETTINGS is specified.
from .local import *

0 comments on commit dd034ad

Please sign in to comment.