Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Added support for multiple unique bones #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions bones/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import html5
from priorityqueue import editBoneSelector, viewDelegateSelector
import bones.string as strBone
from widgets.edit import InvalidBoneValueException
# from widgets.edit import InvalidBoneValueException
import re
# import string as py_string

class EmailViewBoneDelegate( strBone.StringViewBoneDelegate ):
def __init__(self, moduleName, boneName, skelStructure, *args, **kwargs ):
Expand Down Expand Up @@ -31,19 +32,19 @@ class EmailEditBone( strBone.StringEditBone ):
def __init__(self, moduleName, boneName,readOnly,*args, **kwargs ):
super( EmailEditBone, self ).__init__( moduleName, boneName,readOnly, *args, **kwargs )

@staticmethod
def isInvalid(value):
if not value:
return True
return not re.match("^[a-zA-Z0-9._%\-+]+@[a-zA-Z0-9._\-]+.[a-zA-Z]{2,6}$", value)

@staticmethod
def fromSkelStructure(moduleName, boneName, skelStructure, *args, **kwargs):
readOnly = "readonly" in skelStructure[ boneName ].keys() and skelStructure[ boneName ]["readonly"]
return EmailEditBone(moduleName, boneName, readOnly)

def unserialize(self, data):
if self.boneName in data.keys():
self.input["value"] = data[ self.boneName ] if data[ self.boneName ] else ""
if boneName in skelStructure.keys():
multiple = skelStructure[boneName].get("multiple", False)

def serializeForPost(self):
if not self["value"] or re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._-]+.[a-zA-Z]{2,6}$",self.input["value"]):
return( { self.boneName: self.input["value"] } )
raise InvalidBoneValueException()
return EmailEditBone(moduleName, boneName, readOnly, multiple=multiple)

def setSpecialType(self):
self.input["type"]="email"
Expand Down
26 changes: 21 additions & 5 deletions bones/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
viewDelegateSelector,\
extendedSearchWidgetSelector, \
extractorDelegateSelector

from widgets.edit import InvalidBoneValueException

class StringBoneExtractor(BaseBoneExtractor):

Expand Down Expand Up @@ -328,6 +328,10 @@ def onBtnGenTag(self, btn):
tag = self.genTag("", lang=btn.lang)
tag.focus()

@staticmethod
def isInvalid(value):
return False

def unserialize(self, data, extendedErrorInformation=None):
data = data.get(self.boneName)
if not data:
Expand Down Expand Up @@ -384,22 +388,34 @@ def serializeForPost(self):
res["%s.%s" % (self.boneName, lang)] = []
for child in self.langEdits[lang]._children:
if isinstance(child, Tag):
res["%s.%s" % (self.boneName, lang)].append(child.input["value"])
if not self.isInvalid(child.input["value"]):
res["%s.%s" % (self.boneName, lang)].append(child.input["value"])
else:
raise InvalidBoneValueException()

elif self.languages and not self.multiple:
for lang in self.languages:
txt = self.langEdits[lang]["value"]
if txt:
res["%s.%s" % (self.boneName, lang)] = txt
if not self.isInvalid(txt):
res["%s.%s" % (self.boneName, lang)] = txt
else:
raise InvalidBoneValueException()

elif not self.languages and self.multiple:
res[self.boneName] = []
for child in self.tagContainer._children:
if isinstance(child, Tag):
res[self.boneName].append(child.input["value"])
if not self.isInvalid(child.input["value"]):
res[self.boneName].append(child.input["value"])
else:
raise InvalidBoneValueException()

elif not self.languages and not self.multiple:
res[self.boneName] = self.input["value"]
if not self.isInvalid(self.input["value"]):
res[self.boneName] = self.input["value"]
else:
raise InvalidBoneValueException()

return res

Expand Down
1 change: 0 additions & 1 deletion public/vi.less
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,6 @@ form {
form fieldset {
width: 100%;
float: left;
overflow: hidden;
color: #333;
border: 0;
padding: 0;
Expand Down