Skip to content

tillroy/container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Define data structure

from container.fields import Container, Value
from container.rule import Rule

class Cont(Container):
    body = {
        "a": Value("int", meta={"edit": True}),
        "b": Value("int", meta={"edit": True}, required=True)
    }

class Cont1(Container):
    body = {
        "a": Value("int", meta={"edit": True}),
        "b": Value("int", meta={"edit": False}),
        "c": Value("int", meta={"edit": True}),
        "d": Cont()
    }
    # 'a' has to be less then "d.b"
    rules = (
        Rule(cell1="a", do="lt", cell2="d.b"),
        )

Fill container data

c = Cont(strict=False)

c.populate({"a": 1, "b": "22,5"})

Show data

print(c.value)

{'b': 22.5, 'a': 1}
c1 = Cont1()
c1["a"] = 100
c1["d"]["b"] = "22,5"

Raise as exception

Traceback (most recent call last):
  File "/mnt/hdd/myprojects/container/container/fields.py", line 449, in <module>
    print(c1.value)
  File "/mnt/hdd/myprojects/container/container/fields.py", line 335, in value
    self.use_rules()
  File "/mnt/hdd/myprojects/container/container/fields.py", line 377, in use_rules
    print(rule.use())
  File "/mnt/hdd/myprojects/container/container/rule.py", line 62, in use
    raise ValueError("{} not {} {}".format(val1, self.do_name, val2))
ValueError: 100 not lt 22

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages