def test_dsl(): Sub = String.with_properties(abc=123) assert 'abc' not in String.properties assert Sub.properties['abc'] == 123 Disconnected = Sub.using(properties={'def': 456}) assert Disconnected.properties['def'] == 456 assert 'abc' not in Disconnected.properties assert 'def' not in Sub.properties assert 'def' not in String.properties Sub.properties['ghi'] = 789 assert Disconnected.properties == {'def': 456} Disconnected2 = Sub.using(properties=Properties(jkl=123)) assert Disconnected2.properties == {'jkl': 123}
from flatland import Form, String TextInput = String.with_properties(template='forms/text-input.html') CreoleInput = String.with_properties(template='forms/creole-input.html') CreoleArea = String.with_properties(template='forms/creole-area.html') class Page(Form): title = TextInput body = CreoleArea class Translation(Form): definition = CreoleInput notes = CreoleInput
elements become the valid values of the Enum. e.g. for choice_specs = [(v1, ...), (v2, ...), ... ], the valid values are v1, v2, ... :param sort_by: If not None, sort choice_specs by the sort_by'th element. """ if sort_by is not None: choice_specs = sorted(choice_specs, key=itemgetter(sort_by)) else: choice_specs = list(choice_specs) return cls.valued(*[e[0] for e in choice_specs]).with_properties( choice_specs=choice_specs) Text = String.with_properties(widget=WIDGET_TEXT) MultilineText = String.with_properties(widget=WIDGET_MULTILINE_TEXT) OptionalText = Text.using(optional=True) RequiredText = Text.validated_by(Present()) OptionalMultilineText = MultilineText.using(optional=True) RequiredMultilineText = MultilineText.validated_by(Present()) class NameNotValidError(ValueError): """ The name is not valid.
into the choice_specs property; the tuples' first elements become the valid values of the Enum. e.g. for choice_specs = [(v1, ...), (v2, ...), ... ], the valid values are v1, v2, ... :param sort_by: If not None, sort choice_specs by the sort_by'th element. """ if sort_by is not None: choice_specs = sorted(choice_specs, key=itemgetter(sort_by)) else: choice_specs = list(choice_specs) return cls.valued(*[e[0] for e in choice_specs]).with_properties(choice_specs=choice_specs) Text = String.with_properties(widget=WIDGET_TEXT) MultilineText = String.with_properties(widget=WIDGET_MULTILINE_TEXT) OptionalText = Text.using(optional=True) RequiredText = Text.validated_by(Present()) OptionalMultilineText = MultilineText.using(optional=True) RequiredMultilineText = MultilineText.validated_by(Present()) class NameNotValidError(ValueError): """ The name is not valid.