From fc0cbdf5338761bcd02b8a2fdbe7e44007398af0 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Thu, 14 Jul 2022 14:12:45 -0400 Subject: [PATCH 01/14] Initial implementation of Quill widget --- hawc/apps/assessment/forms.py | 11 +++++++-- hawc/apps/common/forms.py | 20 +++++++++++++++- hawc/apps/common/widgets.py | 43 +++++++++++++++++++++++++++++++++++ hawc/static/js/quilltext.js | 3 +++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 hawc/static/js/quilltext.js diff --git a/hawc/apps/assessment/forms.py b/hawc/apps/assessment/forms.py index 87274b913a..205d6844aa 100644 --- a/hawc/apps/assessment/forms.py +++ b/hawc/apps/assessment/forms.py @@ -13,7 +13,12 @@ from hawc.services.epa.dsstox import DssSubstance -from ..common.forms import BaseFormHelper, form_actions_apply_filters, form_actions_create_or_close +from ..common.forms import ( + BaseFormHelper, + QuillField, + form_actions_apply_filters, + form_actions_create_or_close, +) from ..common.helper import new_window_a, tryParseInt from ..common.selectable import AutoCompleteSelectMultipleWidget, AutoCompleteWidget from ..common.widgets import DateCheckboxInput @@ -45,6 +50,9 @@ class Meta: widgets = { "public_on": DateCheckboxInput, } + field_classes = { + "assessment_objective": QuillField, + } def __init__(self, *args, **kwargs): self.user = kwargs.pop("user", None) @@ -88,7 +96,6 @@ def helper(self): widget = self.fields[fld].widget if type(widget) == forms.Textarea: widget.attrs["rows"] = 3 - widget.attrs["class"] = widget.attrs.get("class", "") + " html5text" if self.instance.id: inputs = { diff --git a/hawc/apps/common/forms.py b/hawc/apps/common/forms.py index f243257b06..6369d37f8e 100644 --- a/hawc/apps/common/forms.py +++ b/hawc/apps/common/forms.py @@ -7,7 +7,7 @@ from django import forms from django.template.loader import render_to_string -from . import selectable, validators +from . import selectable, validators, widgets ASSESSMENT_UNIQUE_MESSAGE = "Must be unique for assessment (current value already exists)." @@ -222,3 +222,21 @@ def format_value(self, value) -> List[str]: if value is None: return [] return value.split(",") + + +class QuillField(forms.CharField): + """ + Quill text editor input. + Cleans HTML and validates urls. + """ + + widget = widgets.QuillWidget + + def __init__(self, *args, **kwargs): + # Force use of Quill widget + kwargs["widget"] = self.widget + super().__init__(*args, **kwargs) + + def validate(self, value): + super().validate(value) + validators.validate_hyperlinks(value) diff --git a/hawc/apps/common/widgets.py b/hawc/apps/common/widgets.py index f65adc0a95..67014785aa 100644 --- a/hawc/apps/common/widgets.py +++ b/hawc/apps/common/widgets.py @@ -1,6 +1,9 @@ from random import randint from typing import List, Type +import bleach +from bleach.css_sanitizer import CSSSanitizer +from django.conf import settings from django.forms import ValidationError from django.forms.widgets import ( CheckboxInput, @@ -8,6 +11,7 @@ MultiWidget, Select, SelectMultiple, + Textarea, TextInput, ) from django.utils import timezone @@ -107,3 +111,42 @@ class SelectOtherWidget(ChoiceOtherWidget): class SelectMultipleOtherWidget(ChoiceOtherWidget): choice_widget = SelectMultiple template_name = "common/select_other_widget.html" + + +class QuillWidget(Textarea): + """ + Uses the Quill text editor for input. + Cleaning is done to remove invalid styles and tags; all inner text is kept. + """ + + class Media: + js = (f"{settings.STATIC_URL}js/quilltext.js",) + + def build_attrs(self, base_attrs, extra_attrs=None): + attrs = super().build_attrs(base_attrs, extra_attrs) + class_name = attrs.get("class") + attrs["class"] = class_name + " quilltext" if class_name else "quilltext" + return attrs + + def value_from_datadict(self, data, files, name): + value = data.get(name) + if value: + tags = [ + "span", + "a", + "blockquote", + "sub", + "sup", + "strong", + "em", + "u", + "s", + "ol", + "ul", + "li", + ] + attrs = {"*": ["style"], "a": ["href", "rel", "target"]} + css_sanitizer = CSSSanitizer(allowed_css_properties=["color", "background-color"]) + return bleach.clean( + value, tags=tags, attributes=attrs, css_sanitizer=css_sanitizer, strip=True + ) diff --git a/hawc/static/js/quilltext.js b/hawc/static/js/quilltext.js new file mode 100644 index 0000000000..4de1e4039d --- /dev/null +++ b/hawc/static/js/quilltext.js @@ -0,0 +1,3 @@ +(function($){$(document).ready(() => { + $("textarea.quilltext").quillify(); +});})(jQuery) From d1b719b923a12087f6d891ce19ec9a0a5a4661c5 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Thu, 14 Jul 2022 15:37:38 -0400 Subject: [PATCH 02/14] Replace quill with field --- frontend/animal/EditEndpoint.js | 4 ---- hawc/apps/animal/forms.py | 17 ++++++++------ .../templates/animal/animalgroup_form.html | 2 -- .../templates/animal/dosingregime_form.html | 2 -- .../templates/animal/experiment_form.html | 1 - hawc/apps/assessment/forms.py | 22 +++++-------------- .../assessment/_assessment_form_js.html | 1 - .../assessment/assessment_detail.html | 1 - .../templates/assessment/dataset_form.html | 1 - hawc/apps/lit/forms.py | 7 ++---- hawc/apps/lit/templates/lit/search_form.html | 2 -- hawc/apps/riskofbias/forms.py | 12 +++++----- .../templates/riskofbias/arob_text_form.html | 8 ------- .../riskofbias/riskofbiasdomain_form.html | 1 - .../riskofbias/riskofbiasmetric_form.html | 1 - hawc/apps/study/forms.py | 6 ++--- .../study/templates/study/study_form.html | 1 - 17 files changed, 25 insertions(+), 64 deletions(-) diff --git a/frontend/animal/EditEndpoint.js b/frontend/animal/EditEndpoint.js index b5e875a364..148b4ce70b 100644 --- a/frontend/animal/EditEndpoint.js +++ b/frontend/animal/EditEndpoint.js @@ -23,10 +23,6 @@ class EditEndpoint { // reorganize forms $("#endpointGroups").insertBefore($("div.form-actions")); - // html5 enabled form - $("#id_results_notes").quillify(); - $("#id_endpoint_notes").quillify(); - //update values in doses table $("#doses_title").html(`Dose
(${firstDoses.name})`); $(".doses").each(function(i, v) { diff --git a/hawc/apps/animal/forms.py b/hawc/apps/animal/forms.py index 0963ab4bd9..50ba267221 100644 --- a/hawc/apps/animal/forms.py +++ b/hawc/apps/animal/forms.py @@ -12,7 +12,12 @@ from ..assessment.lookups import DssToxIdLookup, EffectTagLookup, SpeciesLookup, StrainLookup from ..assessment.models import DoseUnits from ..common import selectable -from ..common.forms import BaseFormHelper, CopyAsNewSelectorForm, form_actions_apply_filters +from ..common.forms import ( + BaseFormHelper, + CopyAsNewSelectorForm, + QuillField, + form_actions_apply_filters, +) from ..study.lookups import AnimalStudyLookup from ..vocab.constants import VocabularyNamespace from . import constants, lookups, models @@ -22,6 +27,7 @@ class ExperimentForm(ModelForm): class Meta: model = models.Experiment exclude = ("study",) + field_classes = {"description": QuillField} def __init__(self, *args, **kwargs): parent = kwargs.pop("parent", None) @@ -63,8 +69,6 @@ def helper(self): if type(widget) != forms.CheckboxInput: widget.attrs["class"] = "form-control" - self.fields["description"].widget.attrs["rows"] = 4 - if self.instance.id: inputs = { "legend_text": f"Update {self.instance}", @@ -135,6 +139,7 @@ class Meta: model = models.AnimalGroup exclude = ("experiment", "dosing_regime", "generation", "parents") labels = {"lifestage_assessed": "Lifestage at assessment"} + field_classes = {"comments": QuillField} def __init__(self, *args, **kwargs): parent = kwargs.pop("parent", None) @@ -166,8 +171,6 @@ def __init__(self, *args, **kwargs): experiment=self.instance.experiment ) - self.fields["comments"].widget.attrs["rows"] = 4 - @property def helper(self): for fld in list(self.fields.keys()): @@ -252,14 +255,13 @@ class DosingRegimeForm(ModelForm): class Meta: model = models.DosingRegime exclude = ("dosed_animals",) + field_classes = {"description": QuillField} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @property def helper(self): - - self.fields["description"].widget.attrs["rows"] = 4 for fld in list(self.fields.keys()): self.fields[fld].widget.attrs["class"] = "form-control" @@ -414,6 +416,7 @@ class Meta: "effect_term": forms.HiddenInput, "effect_subtype_term": forms.HiddenInput, } + field_classes = {"results_notes": QuillField, "endpoint_notes": QuillField} def __init__(self, *args, **kwargs): animal_group = kwargs.pop("parent", None) diff --git a/hawc/apps/animal/templates/animal/animalgroup_form.html b/hawc/apps/animal/templates/animal/animalgroup_form.html index 274e9242e4..862f7a5072 100644 --- a/hawc/apps/animal/templates/animal/animalgroup_form.html +++ b/hawc/apps/animal/templates/animal/animalgroup_form.html @@ -68,8 +68,6 @@ ); }; - $('#id_comments').quillify(); - $('#id_description').quillify(); $('#id_species') .change(onSpeciesChange) .trigger('change'); diff --git a/hawc/apps/animal/templates/animal/dosingregime_form.html b/hawc/apps/animal/templates/animal/dosingregime_form.html index 1fe6051f22..be96a7e562 100644 --- a/hawc/apps/animal/templates/animal/dosingregime_form.html +++ b/hawc/apps/animal/templates/animal/dosingregime_form.html @@ -25,8 +25,6 @@ {% block extrajs %} diff --git a/hawc/apps/assessment/templates/assessment/assessment_detail.html b/hawc/apps/assessment/templates/assessment/assessment_detail.html index f220908925..4f9f570a1e 100644 --- a/hawc/apps/assessment/templates/assessment/assessment_detail.html +++ b/hawc/apps/assessment/templates/assessment/assessment_detail.html @@ -248,7 +248,6 @@

Assessment details for team members*

// attachment-form events const form = $(target).find('.attachment-form'); if (form) { - form.find('.html5text').quillify(); form.find("#id_title").focus(); } }); diff --git a/hawc/apps/assessment/templates/assessment/dataset_form.html b/hawc/apps/assessment/templates/assessment/dataset_form.html index 7374cfa93f..9414e06322 100644 --- a/hawc/apps/assessment/templates/assessment/dataset_form.html +++ b/hawc/apps/assessment/templates/assessment/dataset_form.html @@ -9,7 +9,6 @@ {% block extrajs %} -{% endblock extrajs %} diff --git a/hawc/apps/riskofbias/templates/riskofbias/riskofbiasdomain_form.html b/hawc/apps/riskofbias/templates/riskofbias/riskofbiasdomain_form.html index 022f19578e..cda2a180f0 100644 --- a/hawc/apps/riskofbias/templates/riskofbias/riskofbiasdomain_form.html +++ b/hawc/apps/riskofbias/templates/riskofbias/riskofbiasdomain_form.html @@ -9,7 +9,6 @@ {% block extrajs %} diff --git a/hawc/apps/riskofbias/templates/riskofbias/riskofbiasmetric_form.html b/hawc/apps/riskofbias/templates/riskofbias/riskofbiasmetric_form.html index 677ab01dbe..6ae7d8a13f 100644 --- a/hawc/apps/riskofbias/templates/riskofbias/riskofbiasmetric_form.html +++ b/hawc/apps/riskofbias/templates/riskofbias/riskofbiasmetric_form.html @@ -69,7 +69,6 @@ From 7f5d81ca793121559cdefa53c89df52fd0f0731e Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Thu, 14 Jul 2022 16:09:26 -0400 Subject: [PATCH 03/14] Added bleach to requirements --- requirements/base.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/base.txt b/requirements/base.txt index 870b51c2e7..ab7d2a29a3 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -26,6 +26,7 @@ redis==4.1.4 requests==2.27.1 pydantic==1.9.0 myst-parser==0.16.1 +bleach[css]==5.0.1 # computational numpy==1.22.2 From a041514018710ef98811de76d6218058f46054e4 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Thu, 14 Jul 2022 16:44:45 -0400 Subject: [PATCH 04/14] Fixed import form --- hawc/apps/lit/forms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hawc/apps/lit/forms.py b/hawc/apps/lit/forms.py index 29a916da9b..a24124e27b 100644 --- a/hawc/apps/lit/forms.py +++ b/hawc/apps/lit/forms.py @@ -92,6 +92,9 @@ def helper(self): class ImportForm(SearchForm): + class Meta(SearchForm.Meta): + field_classes = {"description": QuillField} + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields["source"].choices = [(1, "PubMed"), (2, "HERO")] @@ -101,7 +104,6 @@ def __init__(self, *args, **kwargs): "search_string" ].help_text = "Enter a comma-separated list of database IDs for import." # noqa self.fields["search_string"].label = "ID List" - self.fields["search_string"].widget.attrs.pop("class") else: self.fields.pop("search_string") From fc7656562361e47005be0735584607d3549d1347 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Fri, 15 Jul 2022 17:45:00 -0400 Subject: [PATCH 05/14] Fix quill fields on all forms --- hawc/apps/animal/templates/animal/dosingregime_form.html | 1 + hawc/apps/assessment/templates/assessment/dataset_form.html | 1 + hawc/apps/lit/templates/lit/search_form.html | 1 + .../riskofbias/templates/riskofbias/arob_text_form.html | 4 ++++ .../templates/riskofbias/riskofbiasdomain_form.html | 1 + .../templates/riskofbias/riskofbiasmetric_form.html | 1 + hawc/apps/study/forms.py | 6 +++--- hawc/apps/study/templates/study/study_form.html | 1 + 8 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hawc/apps/animal/templates/animal/dosingregime_form.html b/hawc/apps/animal/templates/animal/dosingregime_form.html index be96a7e562..394b753c98 100644 --- a/hawc/apps/animal/templates/animal/dosingregime_form.html +++ b/hawc/apps/animal/templates/animal/dosingregime_form.html @@ -24,6 +24,7 @@ {% endblock %} {% block extrajs %} + {{ form.media }} " + cleaned_html = fld.to_python(html) + assert cleaned_html == "alert();" + + # attrs should be cleaned + html = 'link' + cleaned_html = fld.to_python(html) + assert cleaned_html == 'link' + + # styles should be cleaned + html = 'test' + cleaned_html = fld.to_python(html) + assert cleaned_html == 'test' From d62b2a4017f7b9b0009efbb0cb6e65d62de62036 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Mon, 18 Jul 2022 00:46:48 -0400 Subject: [PATCH 07/14] quick fix --- hawc/apps/common/forms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hawc/apps/common/forms.py b/hawc/apps/common/forms.py index a2d50c8e6a..4ab5d16284 100644 --- a/hawc/apps/common/forms.py +++ b/hawc/apps/common/forms.py @@ -239,8 +239,7 @@ def __init__(self, *args, **kwargs): def to_python(self, value): value = super().to_python(value) - if value: - return validators.clean_html(value) + return validators.clean_html(value) if value else value def validate(self, value): super().validate(value) From 8360797a36a9b4a3f87560eb5b6b95195d7c4301 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Wed, 20 Jul 2022 12:47:14 -0400 Subject: [PATCH 08/14] Moved form media check to base.html --- .../animal/templates/animal/animalgroup_copy_selector.html | 1 - hawc/apps/animal/templates/animal/animalgroup_form.html | 1 - hawc/apps/animal/templates/animal/dosingregime_form.html | 1 - hawc/apps/animal/templates/animal/endpoint_copy_selector.html | 1 - hawc/apps/animal/templates/animal/endpoint_form.html | 1 - hawc/apps/animal/templates/animal/endpoint_list.html | 1 - .../animal/templates/animal/experiment_copy_selector.html | 1 - hawc/apps/animal/templates/animal/experiment_form.html | 1 - .../templates/assessment/assessment_create_form.html | 1 - .../apps/assessment/templates/assessment/assessment_form.html | 1 - .../assessment/templates/assessment/assessment_log_list.html | 4 ---- hawc/apps/assessment/templates/assessment/dataset_form.html | 1 - hawc/apps/assessment/templates/assessment/doseunits_form.html | 4 ---- hawc/apps/assessment/templates/assessment/effecttag_form.html | 1 - hawc/apps/epi/templates/epi/adjustmentfactor_form.html | 3 --- .../templates/epi/comparisonset_outcome_copy_selector.html | 1 - .../epi/templates/epi/comparisonset_sp_copy_selector.html | 1 - hawc/apps/epi/templates/epi/criteria_form.html | 3 --- hawc/apps/epi/templates/epi/exposure_copy_selector.html | 1 - hawc/apps/epi/templates/epi/exposure_form.html | 2 -- hawc/apps/epi/templates/epi/outcome_copy_selector.html | 1 - hawc/apps/epi/templates/epi/outcome_form.html | 4 ---- hawc/apps/epi/templates/epi/outcome_list.html | 1 - hawc/apps/epi/templates/epi/result_copy_selector.html | 1 - hawc/apps/epi/templates/epi/result_form.html | 1 - .../apps/epi/templates/epi/studypopulation_copy_selector.html | 1 - hawc/apps/epi/templates/epi/studypopulation_form.html | 1 - hawc/apps/epimeta/templates/epimeta/metaprotocol_form.html | 1 - .../epimeta/templates/epimeta/metaresult_copy_selector.html | 1 - hawc/apps/epimeta/templates/epimeta/metaresult_form.html | 1 - hawc/apps/epimeta/templates/epimeta/metaresult_list.html | 1 - hawc/apps/epiv2/templates/epiv2/design_form.html | 1 - hawc/apps/invitro/templates/invitro/ivcelltype_form.html | 4 ---- hawc/apps/invitro/templates/invitro/ivchemical_form.html | 2 +- hawc/apps/invitro/templates/invitro/ivendpoint_form.html | 1 - hawc/apps/invitro/templates/invitro/ivendpoint_list.html | 1 - hawc/apps/invitro/templates/invitro/ivexperiment_form.html | 3 --- hawc/apps/lit/templates/lit/search_copy_selector.html | 1 - hawc/apps/lit/templates/lit/search_form.html | 1 - hawc/apps/riskofbias/templates/riskofbias/arob_text_form.html | 3 --- .../templates/riskofbias/riskofbiasdomain_form.html | 1 - .../templates/riskofbias/riskofbiasmetric_form.html | 1 - hawc/apps/study/templates/study/study_form.html | 1 - hawc/templates/base.html | 3 +++ 44 files changed, 4 insertions(+), 64 deletions(-) diff --git a/hawc/apps/animal/templates/animal/animalgroup_copy_selector.html b/hawc/apps/animal/templates/animal/animalgroup_copy_selector.html index 7345024d53..8a25f4bc59 100644 --- a/hawc/apps/animal/templates/animal/animalgroup_copy_selector.html +++ b/hawc/apps/animal/templates/animal/animalgroup_copy_selector.html @@ -15,7 +15,6 @@ {% endblock content %} {% block extrajs %} - {{ form.media }} {% render_bundle 'main' %} + {% if form %} + {{ form.media }} + {% endif %} {% block extrajs %}{% endblock %} From f8d1811d1a5d28636345d04d4f43fc4e62234e05 Mon Sep 17 00:00:00 2001 From: Daniel Rabstejnek Date: Wed, 20 Jul 2022 12:52:48 -0400 Subject: [PATCH 09/14] Remove form media from automatically being added by crispy --- hawc/apps/common/forms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hawc/apps/common/forms.py b/hawc/apps/common/forms.py index 4ab5d16284..f0b89a506c 100644 --- a/hawc/apps/common/forms.py +++ b/hawc/apps/common/forms.py @@ -32,6 +32,7 @@ class BaseFormHelper(cf.FormHelper): error_text_inline = False use_custom_control = True + include_media = False def __init__(self, form=None, **kwargs): self.attrs = {} From 70d36ebe48d5a3edba651398a5d37890fac696cb Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Thu, 1 Sep 2022 10:47:29 -0400 Subject: [PATCH 10/14] add doi.org; improve type checking --- hawc/apps/common/validators.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hawc/apps/common/validators.py b/hawc/apps/common/validators.py index d79f080d9a..0d1123ec8c 100644 --- a/hawc/apps/common/validators.py +++ b/hawc/apps/common/validators.py @@ -1,5 +1,5 @@ import re -from typing import Sequence +from typing import Optional, Sequence from urllib import parse import bleach @@ -36,12 +36,13 @@ valid_css_properties = {"color", "background-color"} valid_scheme = {"", "http", "https"} valid_netloc_endings = { - ".gov", ".edu", + ".gov", ".who.int", - "sciencedirect.com", + "doi.org", "elsevier.com", "public.tableau.com", + "sciencedirect.com", } @@ -67,7 +68,7 @@ def clean_html(html: str) -> str: ) -def validate_html_tags(html: str, field: str = None) -> str: +def validate_html_tags(html: str, field: Optional[str] = None) -> str: """Html contains a subset of acceptable tags. Args: From d6dcc1ed9e271865640601610da61b4be85aa147 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Thu, 1 Sep 2022 13:39:34 -0400 Subject: [PATCH 11/14] restore focus for object other than quill object --- frontend/shared/utils/Quillify.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/shared/utils/Quillify.js b/frontend/shared/utils/Quillify.js index 7257bf1577..5f1f609aa9 100644 --- a/frontend/shared/utils/Quillify.js +++ b/frontend/shared/utils/Quillify.js @@ -61,10 +61,11 @@ const toolbarOptions = { }; export default function() { - let modal = $("#smartTagModal"), + let focusedItem = $(":focus"), + modal = $("#smartTagModal"), showHawcTools = modal.length === 1; - return this.each(function() { + this.each(function() { let editor = document.createElement("div"), textarea = $(this), q; @@ -98,4 +99,7 @@ export default function() { q.stc.enableModals(); } }); + + // restore original focus + $(focusedItem).focus(); } From 7ba036252e14305df2a1775994fe6edc554b09a2 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Thu, 1 Sep 2022 13:39:58 -0400 Subject: [PATCH 12/14] update epiv2 forms --- frontend/epiv2/form.js | 5 +---- hawc/apps/epiv2/forms.py | 11 ++++++----- hawc/apps/epiv2/templates/epiv2/design_form.html | 3 +-- .../epiv2/templates/epiv2/fragments/_design_edit.html | 1 + 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/epiv2/form.js b/frontend/epiv2/form.js index 7c5e0e2c15..5c61a327a1 100644 --- a/frontend/epiv2/form.js +++ b/frontend/epiv2/form.js @@ -5,10 +5,7 @@ import {EXPOSURE_BIOMONITORING} from "./constants"; const designFormStartup = function(form) { $(form) - .find(".html5text") - .quillify(); - $(form) - .find("#id_study_design") + .find("#id_summary") .focus(); }, exposureFormStartup = function(form) { diff --git a/hawc/apps/epiv2/forms.py b/hawc/apps/epiv2/forms.py index 671b7b2488..af61e8bde3 100644 --- a/hawc/apps/epiv2/forms.py +++ b/hawc/apps/epiv2/forms.py @@ -5,7 +5,7 @@ from ..assessment.lookups import DssToxIdLookup from ..common import selectable -from ..common.forms import ArrayCheckboxSelectMultiple +from ..common.forms import ArrayCheckboxSelectMultiple, QuillField from ..common.widgets import SelectMultipleOtherWidget, SelectOtherWidget from . import constants, lookups, models @@ -23,6 +23,11 @@ class Meta: model = models.Design exclude = ("study",) widgets = {"age_profile": ArrayCheckboxSelectMultiple(choices=constants.AgeProfile.choices)} + field_classes = { + "criteria": QuillField, + "susceptibility": QuillField, + "comments": QuillField, + } def __init__(self, *args, **kwargs): study = kwargs.pop("parent", None) @@ -32,10 +37,6 @@ def __init__(self, *args, **kwargs): @property def helper(self): - for fld in ("criteria", "susceptibility", "comments"): - self.fields[fld].widget.attrs["class"] = "html5text" - self.fields[fld].widget.attrs["rows"] = 3 - if self.instance.id: helper = BaseFormHelper(self) helper.form_tag = False diff --git a/hawc/apps/epiv2/templates/epiv2/design_form.html b/hawc/apps/epiv2/templates/epiv2/design_form.html index b948927bd4..7a00cae709 100644 --- a/hawc/apps/epiv2/templates/epiv2/design_form.html +++ b/hawc/apps/epiv2/templates/epiv2/design_form.html @@ -16,7 +16,6 @@ {% block extrajs %} {% endblock extrajs %} diff --git a/hawc/apps/epiv2/templates/epiv2/fragments/_design_edit.html b/hawc/apps/epiv2/templates/epiv2/fragments/_design_edit.html index 19ad667fd0..98c28ae0f2 100644 --- a/hawc/apps/epiv2/templates/epiv2/fragments/_design_edit.html +++ b/hawc/apps/epiv2/templates/epiv2/fragments/_design_edit.html @@ -15,4 +15,5 @@ + {{form.media}} From d177f34d9c85ba1ff4acd35eae8b0106d84ebde5 Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Thu, 1 Sep 2022 13:50:45 -0400 Subject: [PATCH 13/14] update tests --- tests/hawc/apps/common/test_forms.py | 49 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/hawc/apps/common/test_forms.py b/tests/hawc/apps/common/test_forms.py index 0f9444c297..351da87c3f 100644 --- a/tests/hawc/apps/common/test_forms.py +++ b/tests/hawc/apps/common/test_forms.py @@ -8,34 +8,33 @@ class TestQuillField: def test_validate(self): fld = QuillField() - # invalid scheme - html = 'link' - with pytest.raises(ValidationError): - fld.validate(html) - - # invalid TLD - html = 'link' - with pytest.raises(ValidationError): - fld.validate(html) - # valid html = 'link' fld.validate(html) + # invalid + for html in [ + 'link', # schema + 'link', # tld + ]: + with pytest.raises(ValidationError): + fld.validate(html) + def test_to_python(self): fld = QuillField() - - # tags should be cleaned - html = "" - cleaned_html = fld.to_python(html) - assert cleaned_html == "alert();" - - # attrs should be cleaned - html = 'link' - cleaned_html = fld.to_python(html) - assert cleaned_html == 'link' - - # styles should be cleaned - html = 'test' - cleaned_html = fld.to_python(html) - assert cleaned_html == 'test' + data = [ + # remove script tag + ("", "alert();"), + # remove attribute + ( + 'link', + 'link', + ), + # remove some styles + ( + 'test', + 'test', + ), + ] + for input_html, output_html in data: + assert fld.to_python(input_html) == output_html From 75427b9c7bd5fe884dc1589440c6029851e7761e Mon Sep 17 00:00:00 2001 From: Andy Shapiro Date: Thu, 1 Sep 2022 15:49:34 -0400 Subject: [PATCH 14/14] fix edit row --- .../templates/assessment/fragments/attachment_edit_row.html | 1 + 1 file changed, 1 insertion(+) diff --git a/hawc/apps/assessment/templates/assessment/fragments/attachment_edit_row.html b/hawc/apps/assessment/templates/assessment/fragments/attachment_edit_row.html index 469f29c816..5c3187ac73 100644 --- a/hawc/apps/assessment/templates/assessment/fragments/attachment_edit_row.html +++ b/hawc/apps/assessment/templates/assessment/fragments/attachment_edit_row.html @@ -32,5 +32,6 @@ + {{ form.media }} {% endif %}