Skip to content

Commit

Permalink
Bug fixes (#20)
Browse files Browse the repository at this point in the history
* Fix content damage on validation error
* Fix fixtures format and enable null values
* Fixed non-saving data of dynamically created quills
* Poetry fix
* Setup fix

Co-authored-by: Michał Dyczko <michal.dyczko@poczta.pl>
  • Loading branch information
michaldyczko and Michał Dyczko authored Aug 4, 2020
1 parent 9962c1b commit be1352a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
6 changes: 5 additions & 1 deletion django_quill/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FieldQuill:
def __init__(self, instance, field, json_string):
self.instance = instance
self.field = field
self.json_string = json_string
self.json_string = json_string or '{"delta":"","html":""}'
self._committed = True

def __eq__(self, other):
Expand Down Expand Up @@ -142,3 +142,7 @@ def get_prep_value(self, value):
if isinstance(value, Quill):
return value.json_string
return value

def value_to_string(self, obj):
value = self.value_from_object(obj)
return self.get_prep_value(value)
50 changes: 41 additions & 9 deletions django_quill/templates/django_quill/widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,46 @@
<div id="quill-{{ id }}" class="django-quill-widget" data-config="{{ config }}" data-type="django-quill"></div>
<input id="quill-input-{{ id }}" name="{{ name }}" type="hidden">
<script>
(function () {
var wrapper = new QuillWrapper('quill-{{ id }}', 'quill-input-{{ id }}', JSON.parse('{{ config|safe }}'));
{% if quill and quill.delta %}
var contents = JSON.parse('{{ quill.delta|safe|escapejs }}');
wrapper.quill.setContents(contents);
{% elif value %}
wrapper.quill.clipboard.dangerouslyPasteHTML(0, '{{ value|safe }}')
{% endif %}
})();
{% if "__prefix__" in id %}
$(document).on('DOMNodeInserted', function(e){
var node = $(e.target);
if(node.find('#quill-{{ id }}').length > 0){
var totalFormsInput = $('input[id="' + "{{ id }}".replace(/__prefix__.*/g, "TOTAL_FORMS") + '"]')
var totalForms = totalFormsInput.val();

var targetDiv = $('#quill-{{ id }}');
targetDiv.prop('id', targetDiv.attr('id').replace(/__prefix__/g, totalForms));
var targetDivId = targetDiv.prop('id')

var targetInput = $('#quill-input-{{ id }}');
targetInput.prop('id', targetInput.attr('id').replace(/__prefix__/g, totalForms));
var targetInputId = targetInput.prop('id')

totalFormsInput.val(totalForms + 1);

(function () {
var wrapper = new QuillWrapper(targetDivId, targetInputId, JSON.parse('{{ config|safe }}'));
{% if quill and quill.delta %}
var contents = JSON.parse('{{ quill.delta|safe|escapejs }}');
wrapper.quill.setContents(contents);
{% elif value %}
var value = JSON.parse('{{ value|safe|escapejs }}');
wrapper.quill.setContents(JSON.parse(value['delta']));
{% endif %}
})();
}
});
{% else %}
(function () {
var wrapper = new QuillWrapper("quill-{{ id }}", "quill-input-{{ id }}", JSON.parse('{{ config|safe }}'));
{% if quill and quill.delta %}
var contents = JSON.parse('{{ quill.delta|safe|escapejs }}');
wrapper.quill.setContents(contents);
{% elif value %}
var value = JSON.parse('{{ value|safe|escapejs }}');
wrapper.quill.setContents(JSON.parse(value['delta']));
{% endif %}
})();
{% endif %}
</script>
</div>
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "django-quill-editor"
version = "0.1.0"
description = ""
authors = ["이한영 <dev@lhy.kr>"]
packages = [
{ include = "django_quill" },
]

[tool.poetry.dependencies]
python = "^3.7"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python
import os

from setuptools import find_packages, setup

ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
README = open(os.path.join(ROOT_DIR, 'README.md')).read()
VERSION = open(os.path.join(ROOT_DIR, 'version.txt')).read()

Expand Down

0 comments on commit be1352a

Please sign in to comment.