def fields(self): return ( Field('uid', _("UID"), width=5, default=nextval('cms_users_uid_seq')), Field('login', _("Přihlašovací jméno"), width=16), Field('fullname', _("Celé jméno"), width=40), Field('passwd', _("Heslo"), type=pd.Password(not_null=True, minlen=4, md5=True)), )
def test_str(self): class BigString(pd.String, pd.Big): pass row = self._row(( pp.Field('x', type=pd.Integer(not_null=True)), pp.Field('y', type=pd.Integer(), default=88), pp.Field('passwd', type=pd.Password()), pp.Field('data', type=BigString()), ), new=True, prefill=dict(x=1, y=3, passwd='secret', data=1024 * 'x')) assert unistr( row ) == '<PresentedRow: x=1, y=3, passwd=***, data=<BigString 1 kB>>'
def _mega_row(self, new=False, row=None, singleline=False, **prefill): # TODO: This all-in-one row was historically used for all tests # but it proved to be problematic. You can not see the definition # of the fields from paticular tests so it is hard to guess the test # logic. Morover the specification is getting too complicated # and hard to maintain usable in all situations. Thus new tests should # Define their own fields directly just for their purpose. class BigString(pd.String, pd.Big): pass class SpecialEnumerator(pd.FixedEnumerator): # This class is overriden just to allow definition of runtime_filter # and runtime_arguments for the same field (which is only important # to improve test coverage) def values(self, a=None): # Accepts argument a as returned by runtime_arguments. return super(SpecialEnumerator, self).values() fields = ( pp.Field('a', type=pd.Integer(not_null=True)), pp.Field('b', type=pd.Integer(not_null=True, enumerator=SpecialEnumerator(range(101))), runtime_filter=pp.computer( lambda r, a: lambda x: x % a == 0, validate=True), runtime_arguments=pp.computer(lambda r, a: dict(a=a))), pp.Field('c', type=pd.Integer(not_null=True), default=lambda: 5), pp.Field('d', type=pd.Integer(), editable=pp.computer(lambda r, total: total > 5 if total else False), computer=pp.computer(lambda r, c: c * 2, validate=True)), pp.Field('fruit', type=pd.String(), codebook='Fruits', display='title', null_display='none'), pp.Field('fruit_code', virtual=True, computer=pp.CbComputer('fruit', 'code')), pp.Field('range', type=pd.IntegerRange(), visible=pp.computer(lambda r, a: a != 0)), pp.Field('total', type=pd.Integer(), virtual=True, editable=pp.Editable.NEVER, computer=pp.computer(lambda r, b, c: b + c, validate=True, fallback=0)), pp.Field('half_total', type=pd.Integer(), virtual=True, editable=pp.Editable.NEVER, computer=pp.computer(lambda r, total: total // 2 if total is not None else None)), pp.Field('x', type=pd.Integer(), virtual=True, default=88), pp.Field('password', type=pd.Password(), virtual=True), pp.Field('big', type=BigString(), virtual=True), pp.Field('array', type=pd.Array, inner_type=pd.String, codebook='Fruits', display='title', virtual=True), ) class Fruits(pytis.presentation.Specification): fields = ( pp.Field('id'), pp.Field('title'), pp.Field('code', type=pd.Integer()), pp.Field('tropical', type=pd.Boolean()), ) data_cls = pd.MemData data = (('apl', 'Apple', 123, False), ('ban', 'Banana', 234, True), ('str', 'Strawberry', 234, False), ('org', 'Orange', 456, True)) class TestResolver(pytis.util.Resolver): _specifications = {'Fruits': Fruits} def _get_object_by_name(self, name): try: return self._specifications[name] except KeyError: return super(TestResolver, self)._get_object_by_name(name) pytis.config.resolver = TestResolver() return self._row(fields, row=row, new=new, singleline=singleline, prefill=prefill)
def _customize_fields(self, fields): fields.modify('id', fixed=True, editable=Editable.NEVER, default=nextval('passwords_id_seq')) fields.modify('passwd', type=pd.Password(minlen=4, maxlen=16, verify=True), disable_column=True),
def fields(self): return ( # Basic fields Field('text', _("Text"), type=pd.String(maxlen=50), width=30, editable=computer(self._editable)), Field('completion', _("Completion"), type=pd.String(maxlen=20), editable=computer(self._editable), completer=('John', 'Jane', 'Joe', 'Judith', 'Jeremy', 'Peter', 'Paul', 'Paula', 'Richard', 'Samantha', 'Samuel', 'Steve', 'Sue'), descr=_("Text entry with autocompletion. The 'completer' provides " "available completions. As opposed to enumerator (which " "also provides autocompletion values), completer has no " "effect on validation. You can define a static (like here), " "dynamic or database connected list of completions.")), Field('multiline', _("Multiline"), type=pd.String(), width=30, height=4, editable=computer(self._editable)), Field('password', _("Password"), type=pd.Password(maxlen=20, verify=True), editable=computer(self._editable), width=14, descr=_("Password field doesn't display the current value. If 'verify' " "is set to True in field's type, the field requires the value to " "be entered twice and validation makes sure both values match.")), Field('number', _("Number"), type=pd.Integer(), default=0, editable=computer(self._editable), descr=_("A simple numeric field.")), Field('slider', _("Slider"), type=pd.Integer(minimum=20, maximum=50), default=30, slider=True, width=2, editable=computer(self._editable), descr=_("A simple numeric field.")), Field('float', _("Decimal"), type=pd.Float(precision=2), default=0, editable=computer(self._editable)), Field('date', _("Date"), default=pd.Date.datetime, type=pd.Date(), editable=computer(self._editable), descr=_("Date entry field with a calendar control and a default value.")), Field('time', _("Time"), type=pytis.data.Time(), editable=computer(self._editable)), Field('datetime', _("Date and time"), type=pytis.data.DateTime(), editable=computer(self._editable)), Field('file', _("File"), type=pytis.data.Binary(), editable=computer(self._editable)), Field('image', _("Image"), type=pytis.data.Image(), editable=computer(self._editable)), Field('color', _("Color"), type=pytis.data.Color(), editable=computer(self._editable)), # Enumeration fields Field('editable', _("Check box"), type=pd.Boolean(), default=True, descr=_("Check/uncheck this checkbox to enable/disable all other " "form fields. This field demonstrates a simple boolean " "checkbox field. It also demonstrates how to make fields " "editable based on the values of some other fields (any " "more complicated logic is possible in the 'computer' of " "the 'editable' property in field specification). " "Finally it demonstrates how all field types look in the " "editable and non-editable state.")), Field('choice', _("Choice"), type=pd.String(not_null=True, maxlen=2), codebook='cb.Continents', selection_type=SelectionType.CHOICE, editable=computer(self._editable), descr=_("Simple pull-down menu selection.")), Field('radio', _("Radio box"), not_null=True, enumerator=self._Fruits, editable=computer(self._editable), selection_type=SelectionType.RADIO, descr=_("Radio box selection. The enumeration is defined statically by " "an Enumeration class.")), Field('listbox', _("List box"), not_null=True, enumerator=self._Fruits, selection_type=SelectionType.LISTBOX, editable=computer(self._editable), descr=_("List selection which becomes scrollable when the number of " "items exceeds its height.")), Field('codebook', _("Codebook"), type=pd.String(not_null=True, maxlen=2), codebook='cb.Countries', width=2, # SelectionType.CODEBOOK is actually the default when 'codebook' is set. selection_type=SelectionType.CODEBOOK, post_process=PostProcess.UPPER, editable=computer(self._editable), descr=_( "This field provides a text entry for writing down the code directly. " "It most convenient when the codebook contains a relatively large number of " "items while their codes are short and simple. Then the user most often " "knows the codes without looking them up. Right from the text entry field, " "there is a codebook invocation button, which allows the user to select the " "item from a codebook form (when he doesn't remember the code or wants to " "see the full listing of all available items for some other reason). " "Further on the right, there is a gray field called `display'. It shows " "the description of the currently selected item (eg. the full name for the " "selected code). Thus it provides immediate feedback when the user " "modifies the value. It is empty when the entered code is invalid (not " "contained in the codebook). It is updated with any change of the field " "value.")), Field('listfield', _("List Field"), type=pd.String(not_null=True, maxlen=2), codebook='cb.Countries', compact=True, height=6, selection_type=SelectionType.LIST, editable=computer(self._editable), descr=_("This field also allows direct codebook manipulations through the row " "context menu.")), # Range fields Field('intrange', _("Numeric range"), type=pytis.data.IntegerRange(), editable=computer(self._editable)), Field('daterange', _("Date range"), type=pytis.data.DateRange(), editable=computer(self._editable)), )