Adding Richtext type in schema
This commit is contained in:
@@ -31,4 +31,19 @@ def text_area(*args, **kwargs):
|
|||||||
return Field(*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)
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
from html import unescape
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
|
|
||||||
from ..core.models import CrudDocument, text_area
|
from ..core.models import CrudDocument, RichtextMultiline, RichtextSingleline
|
||||||
|
|
||||||
|
|
||||||
class PartyTemplate(BaseModel):
|
class PartyTemplate(BaseModel):
|
||||||
@@ -18,15 +19,22 @@ class PartyTemplate(BaseModel):
|
|||||||
part: str
|
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):
|
class ProvisionTemplate(CrudDocument):
|
||||||
name: str
|
name: str
|
||||||
title: str
|
title: str = RichtextSingleline()
|
||||||
label: str = None
|
label: str = ""
|
||||||
body: str = text_area(size=8)
|
body: str = RichtextMultiline(size=8)
|
||||||
|
|
||||||
@validator("label", always=True)
|
@validator("label", always=True)
|
||||||
def generate_label(cls, v, values, **kwargs):
|
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):
|
class Settings(CrudDocument.Settings):
|
||||||
fulltext_search = ['name', 'title', 'body']
|
fulltext_search = ['name', 'title', 'body']
|
||||||
@@ -61,5 +69,3 @@ class ContractTemplate(CrudDocument):
|
|||||||
default=[],
|
default=[],
|
||||||
format="dictionary",
|
format="dictionary",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from typing import List
|
|||||||
|
|
||||||
from .models import ContractTemplate, ProvisionTemplate, PartyTemplate, ProvisionTemplateReference, DictionaryEntry
|
from .models import ContractTemplate, ProvisionTemplate, PartyTemplate, ProvisionTemplateReference, DictionaryEntry
|
||||||
from ..core.schemas import Writer
|
from ..core.schemas import Writer
|
||||||
from ..core.models import text_area
|
from ..core.models import RichtextMultiline, RichtextSingleline
|
||||||
|
|
||||||
|
|
||||||
class ContractTemplateRead(ContractTemplate):
|
class ContractTemplateRead(ContractTemplate):
|
||||||
@@ -31,8 +31,8 @@ class ProvisionTemplateRead(ProvisionTemplate):
|
|||||||
|
|
||||||
class ProvisionTemplateCreate(Writer):
|
class ProvisionTemplateCreate(Writer):
|
||||||
name: str
|
name: str
|
||||||
title: str
|
title: str = RichtextSingleline()
|
||||||
body: str = text_area(size=8)
|
body: str = RichtextMultiline(size=8)
|
||||||
|
|
||||||
|
|
||||||
class ProvisionTemplateUpdate(BaseModel):
|
class ProvisionTemplateUpdate(BaseModel):
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ export class CrudFormlyJsonschemaOptions implements FormlyJsonschemaOptions {
|
|||||||
field.type = "hidden";
|
field.type = "hidden";
|
||||||
} else if (schema.type == "array" && schema.format == "dictionary") {
|
} else if (schema.type == "array" && schema.format == "dictionary") {
|
||||||
field.type = "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')) {
|
if (schema.hasOwnProperty('props')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user