From db96a267fc532a81f8ce71078ac7095a63eb08f6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 5 Jun 2023 13:16:10 -0400 Subject: [PATCH] better render array and dict in edit form --- boofilsic/settings.py | 3 +-- catalog/common/jsondata.py | 12 +++++---- catalog/forms.py | 1 - catalog/movie/models.py | 4 +++ catalog/tv/models.py | 8 ++++++ common/static/scss/_form.scss | 45 ++++++++++++++++++++++++++++++++ common/static/scss/_legacy2.scss | 16 ++++++------ common/static/scss/neodb.scss | 1 + requirements.txt | 3 +-- 9 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 common/static/scss/_form.scss diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 20244adf..96b83929 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -49,9 +49,9 @@ INSTALLED_APPS = [ "django.contrib.staticfiles", "django.contrib.humanize", "django.contrib.postgres", - "django_sass", "django_rq", "django_bleach", + "django_jsonform", "oauth2_provider", "tz_detect", "sass_processor", @@ -60,7 +60,6 @@ INSTALLED_APPS = [ "polymorphic", "easy_thumbnails", "user_messages", - "jsoneditor", "fontawesomefree", ] diff --git a/catalog/common/jsondata.py b/catalog/common/jsondata.py index 299560e0..7e3a3e38 100644 --- a/catalog/common/jsondata.py +++ b/catalog/common/jsondata.py @@ -9,10 +9,12 @@ from django.core.exceptions import FieldError from django.db.models import fields from django.utils import dateparse, timezone -from django.contrib.postgres.fields import ArrayField as DJANGO_ArrayField +# from django.contrib.postgres.fields import ArrayField as DJANGO_ArrayField +from django_jsonform.models.fields import ArrayField as DJANGO_ArrayField # from django.db.models import JSONField as DJANGO_JSONField -from jsoneditor.fields.django3_jsonfield import JSONField as DJANGO_JSONField +# from jsoneditor.fields.django3_jsonfield import JSONField as DJANGO_JSONField +from django_jsonform.models.fields import JSONField as DJANGO_JSONField __all__ = ( @@ -232,9 +234,9 @@ class URLField(JSONFieldMixin, fields.URLField): class ArrayField(JSONFieldMixin, DJANGO_ArrayField): - def __init__(self, *args, **kwargs): - kwargs["help_text"] = _("多项之间以英文逗号分隔") - super().__init__(*args, **kwargs) + # def __init__(self, *args, **kwargs): + # kwargs["help_text"] = _("多项之间以英文逗号分隔") + # super().__init__(*args, **kwargs) def from_json(self, value): # backward compatible with dirty legacy data if value: diff --git a/catalog/forms.py b/catalog/forms.py index 941a9984..88ef0ea0 100644 --- a/catalog/forms.py +++ b/catalog/forms.py @@ -1,6 +1,5 @@ from django import forms from django.utils.translation import gettext_lazy as _ - from catalog.models import * from common.forms import PreviewImageInput diff --git a/catalog/movie/models.py b/catalog/movie/models.py index 98aceea3..a39c413b 100644 --- a/catalog/movie/models.py +++ b/catalog/movie/models.py @@ -93,6 +93,10 @@ class Movie(Item): null=True, blank=True, default=list, + schema={ + "type": "array", + "items": {"type": "dict", "additionalProperties": True, "keys": []}, + }, # TODO fix it as simple dict... ) site = jsondata.URLField( verbose_name=_("官方网站"), blank=True, default="", max_length=200 diff --git a/catalog/tv/models.py b/catalog/tv/models.py index 594d5646..3b407df0 100644 --- a/catalog/tv/models.py +++ b/catalog/tv/models.py @@ -145,6 +145,10 @@ class TVShow(Item): null=True, blank=True, default=list, + schema={ + "type": "array", + "items": {"type": "dict", "additionalProperties": True, "keys": []}, + }, # TODO fix it as simple dict... ) site = jsondata.URLField( verbose_name=_("官方网站"), blank=True, default="", max_length=200 @@ -277,6 +281,10 @@ class TVSeason(Item): null=True, blank=True, default=list, + schema={ + "type": "array", + "items": {"type": "dict", "additionalProperties": True, "keys": []}, + }, # TODO fix it as simple dict... ) site = jsondata.URLField( verbose_name=_("官方网站"), blank=True, default="", max_length=200 diff --git a/common/static/scss/_form.scss b/common/static/scss/_form.scss new file mode 100644 index 00000000..e8d66a23 --- /dev/null +++ b/common/static/scss/_form.scss @@ -0,0 +1,45 @@ +// override django_jsonform/react-json-form styles +.rjf-form-wrapper { + input[type="text"] { + max-width: unset !important; + margin-top: 0 !important; + margin-bottom: 0 !important; + font-size: unset !important; + } + + .rjf-add-button { + background: var(--pico-background) !important; + color: var(--pico-secondary) !important; + border: solid 1px var(--pico-secondary) !important; + margin-left: 5px !important; + } + + .rjf-form-row-controls { + button { + padding: unset !important; + font-size: unset !important; + margin-bottom: 0 !important; + } + } + + .rjf-form-row-inner>div { + display: grid !important; + grid-template-columns: repeat(auto-fit, minmax(0%, 1fr)); + + >label { + margin-top: var(--pico-form-element-spacing-vertical); + } + + >* { + width: max-content !important; + + + button { + padding: unset !important; + font-size: unset !important; + margin-bottom: 0 !important; + } + + } + } +} diff --git a/common/static/scss/_legacy2.scss b/common/static/scss/_legacy2.scss index 7eedb997..ce3056c3 100644 --- a/common/static/scss/_legacy2.scss +++ b/common/static/scss/_legacy2.scss @@ -1,12 +1,12 @@ -/*** django-jsoneditor ***/ -div.jsoneditor { - border-color: #ccc !important; -} +// /*** django-jsoneditor ***/ +// div.jsoneditor { +// border-color: #ccc !important; +// } -div.jsoneditor-menu { - background-color: #606c76 !important; - border-color: #606c76 !important; -} +// div.jsoneditor-menu { +// background-color: #606c76 !important; +// border-color: #606c76 !important; +// } /***** MODAL DIALOG ****/ #modal { diff --git a/common/static/scss/neodb.scss b/common/static/scss/neodb.scss index 3af02899..eec18dfb 100644 --- a/common/static/scss/neodb.scss +++ b/common/static/scss/neodb.scss @@ -16,3 +16,4 @@ @import '_sidebar.scss'; @import '_common.scss'; @import '_login.scss'; +@import '_form.scss'; diff --git a/requirements.txt b/requirements.txt index 003ab990..d35bcdae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,8 +4,7 @@ rq>=1.12.0 django~=3.2.19 django-auditlog django-markdownx @ git+https://github.com/alphatownsman/django-markdownx.git@e69480c64ad9c5d0499f4a8625da78cf2bb7691b -django-jsoneditor @ git+https://github.com/alphatownsman/django-jsoneditor.git@fa2ae41aeeb34447bd8a808a520e843c853fd16e -django-sass +django-jsonform libsass django-compressor django-sass-processor