ISSUE-8: format m2m confirmation values (#15)
* feat(ISSUE-8): Formatting m2m confirmation values as html lists * feat(ISSUE-8): Remove comments Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>main
parent
6f41e6cfdb
commit
fea907b3c8
6
Makefile
6
Makefile
|
|
@ -18,10 +18,10 @@ package:
|
||||||
python3 setup.py sdist bdist_wheel
|
python3 setup.py sdist bdist_wheel
|
||||||
|
|
||||||
upload-testpypi:
|
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:
|
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:
|
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}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ class AdminConfirmMixin:
|
||||||
field_object = model._meta.get_field(name)
|
field_object = model._meta.get_field(name)
|
||||||
initial_value = getattr(obj, name)
|
initial_value = getattr(obj, name)
|
||||||
if isinstance(field_object, ManyToManyField):
|
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:
|
if initial_value != new_value:
|
||||||
changed_data[name] = [initial_value, new_value]
|
changed_data[name] = [initial_value, new_value]
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
from django import template
|
from django import template
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
from django.utils.html import escape
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def format_change_data_field_value(field_value):
|
def format_change_data_field_value(field_value):
|
||||||
if isinstance(field_value, QuerySet):
|
if isinstance(field_value, str):
|
||||||
return list(field_value)
|
return field_value
|
||||||
|
try:
|
||||||
return field_value
|
output = "<ul>"
|
||||||
|
for value in iter(field_value):
|
||||||
|
output += "<li>" + escape(value) + "</li>"
|
||||||
|
output += "</ul>"
|
||||||
|
return mark_safe(output)
|
||||||
|
except:
|
||||||
|
return field_value
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE=tests.test_project.settings.test
|
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
|
testpaths = admin_confirm
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -6,7 +6,7 @@ README = open(os.path.join(here, "README.md")).read()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="django-admin-confirm",
|
name="django-admin-confirm",
|
||||||
version="0.2.3.dev2",
|
version="0.2.3.dev3",
|
||||||
packages=["admin_confirm"],
|
packages=["admin_confirm"],
|
||||||
description="Adds confirmation to Django Admin changes, additions and actions",
|
description="Adds confirmation to Django Admin changes, additions and actions",
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
"""
|
|
||||||
Django settings for test_project project.
|
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 3.0.10.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/3.0/topics/settings/
|
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
|
||||||
https://docs.djangoproject.com/en/3.0/ref/settings/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
|
||||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
|
||||||
SECRET_KEY = "=yddl-40388w3e2hl$e8)revce=n67_idi8pfejtn3!+2%!_qt"
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
|
||||||
DEBUG = True
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
|
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
|
||||||
"admin_confirm",
|
|
||||||
"django.contrib.admin",
|
|
||||||
"django.contrib.auth",
|
|
||||||
"django.contrib.contenttypes",
|
|
||||||
"django.contrib.sessions",
|
|
||||||
"django.contrib.messages",
|
|
||||||
"django.contrib.staticfiles",
|
|
||||||
"market",
|
|
||||||
]
|
|
||||||
|
|
||||||
MIDDLEWARE = [
|
|
||||||
"django.middleware.security.SecurityMiddleware",
|
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
||||||
"django.middleware.common.CommonMiddleware",
|
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
||||||
]
|
|
||||||
|
|
||||||
ROOT_URLCONF = "test_project.urls"
|
|
||||||
|
|
||||||
TEMPLATES = [
|
|
||||||
{
|
|
||||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
||||||
"DIRS": [],
|
|
||||||
"APP_DIRS": True,
|
|
||||||
"OPTIONS": {
|
|
||||||
"context_processors": [
|
|
||||||
"django.template.context_processors.debug",
|
|
||||||
"django.template.context_processors.request",
|
|
||||||
"django.contrib.auth.context_processors.auth",
|
|
||||||
"django.contrib.messages.context_processors.messages",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
WSGI_APPLICATION = "test_project.wsgi.application"
|
|
||||||
|
|
||||||
|
|
||||||
# Database
|
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
"default": {
|
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
|
||||||
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
|
||||||
|
|
||||||
LANGUAGE_CODE = "en-us"
|
|
||||||
|
|
||||||
TIME_ZONE = "UTC"
|
|
||||||
|
|
||||||
USE_I18N = True
|
|
||||||
|
|
||||||
USE_L10N = True
|
|
||||||
|
|
||||||
USE_TZ = True
|
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
|
||||||
|
|
||||||
STATIC_URL = "/static/"
|
|
||||||
|
|
@ -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 *
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue