Adding Richtext type in schema

This commit is contained in:
2023-02-09 15:42:49 +01:00
parent 308aec4706
commit 6a5c1852e4
4 changed files with 34 additions and 10 deletions

View File

@@ -31,4 +31,19 @@ def text_area(*args, **kwargs):
return Field(*args, **kwargs)
def RichtextMultiline(*args, **kwargs):
kwargs['props'] = {
"richtext": True,
"multiline": True
}
return Field(*args, **kwargs)
def RichtextSingleline(*args, **kwargs):
kwargs['props'] = {
"richtext": True,
"multiline": False
}
return Field(*args, **kwargs)

View File

@@ -1,8 +1,9 @@
from typing import List, Dict
from html import unescape
from pydantic import BaseModel, Field, validator
from ..core.models import CrudDocument, text_area
from ..core.models import CrudDocument, RichtextMultiline, RichtextSingleline
class PartyTemplate(BaseModel):
@@ -18,15 +19,22 @@ class PartyTemplate(BaseModel):
part: str
def remove_html_tags(text):
"""Remove html tags from a string"""
import re
clean = re.compile('<.*?>')
return re.sub(clean, '', text)
class ProvisionTemplate(CrudDocument):
name: str
title: str
label: str = None
body: str = text_area(size=8)
title: str = RichtextSingleline()
label: str = ""
body: str = RichtextMultiline(size=8)
@validator("label", always=True)
def generate_label(cls, v, values, **kwargs):
return "{} - \"{}\"".format(values['name'], values['title'])
return "{} - \"{}\"".format(values['name'], unescape(remove_html_tags(values['title'])))
class Settings(CrudDocument.Settings):
fulltext_search = ['name', 'title', 'body']
@@ -61,5 +69,3 @@ class ContractTemplate(CrudDocument):
default=[],
format="dictionary",
)

View File

@@ -3,7 +3,7 @@ from typing import List
from .models import ContractTemplate, ProvisionTemplate, PartyTemplate, ProvisionTemplateReference, DictionaryEntry
from ..core.schemas import Writer
from ..core.models import text_area
from ..core.models import RichtextMultiline, RichtextSingleline
class ContractTemplateRead(ContractTemplate):
@@ -31,8 +31,8 @@ class ProvisionTemplateRead(ProvisionTemplate):
class ProvisionTemplateCreate(Writer):
name: str
title: str
body: str = text_area(size=8)
title: str = RichtextSingleline()
body: str = RichtextMultiline(size=8)
class ProvisionTemplateUpdate(BaseModel):

View File

@@ -47,6 +47,9 @@ export class CrudFormlyJsonschemaOptions implements FormlyJsonschemaOptions {
field.type = "hidden";
} else if (schema.type == "array" && schema.format == "dictionary") {
field.type = "dictionary";
} else if (schema.type == "string" && schema.hasOwnProperty('props')
&& schema.props.hasOwnProperty("richtext") && schema.props.richtext) {
field.type = "richtext";
}
if (schema.hasOwnProperty('props')) {