Skip to content

Commit

Permalink
cz: 7 ++
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolsky committed Aug 5, 2015
1 parent c8cf4de commit 3b08f49
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 57 deletions.
109 changes: 52 additions & 57 deletions sources/40-web2py-czech-translation-in-progress/07.markmin
Original file line number Diff line number Diff line change
Expand Up @@ -1459,106 +1459,106 @@ Chyby se pak zobrazí takto:
Tento mechanismus bude fungovat i při použití form.custom.


### Validators
### Validátory
``validators``:inxx

Validators are classes used to validate input fields (including forms generated from database tables).
Validátory jsou třídy pro validování (ověření správnosti) hodnoty z HTML Input polí.

Here is an example of using a validator with a ``FORM``:
Příklad použití validátoru u prvku ``INPUT`` ve ``FORM``:
``
INPUT(_name='a', requires=IS_INT_IN_RANGE(0, 10))
``:code

Here is an example of how to require a validator for a table field:
Podobně při definici datového modelu můžeme přiřadit validátor k poli tabulky:
``
db.define_table('person', Field('name'))
db.person.name.requires = IS_NOT_EMPTY()
``:code

Validators are always assigned using the ``requires`` attribute of a field. A field can have a single validator or multiple validators. Multiple validators are made part of a list:
Validátory vždy připojujeme atributem ``requires``. Pole může mít nejen jeden validátor ale i více. V tom případě je uvedeme v seznamu (list):
``
db.person.name.requires = [IS_NOT_EMPTY(),
IS_NOT_IN_DB(db, 'person.name')]
``:code

Normally validators are called automatically by the function ``accepts`` and ``process`` of a ``FORM`` or other HTML helper object that contains a form. They are called in the order in which they are listed.
Normálně jsou validátory volány automaticky funkcemi formuláře ``accepts``/``process``. Zpracovávají se v pořadí, v jakém jsou uvedeny.

One can also call validators explicitly for a field:
Je také možné volat validátory určitého pole explicitně:

``
db.person.name.validate(value)
``

which returns a tuple ``(value,error)`` and ``error`` is ``None`` if no the value validates.
což vrátí dvojici (tuple) ``(value, error)``, ``error`` je ``None``, jestliže validace projde bez problému.

Built-in validators have constructors that take an optional argument:
Vestavěné validátory mají signaturu s volitelným parametrem:

``
IS_NOT_EMPTY(error_message='cannot be empty')
IS_NOT_EMPTY(error_message='musí být uvedeno')
``:code

``error_message`` allows you to override the default error message for any validator.
``error_message`` umožňuje přepsat defaultní chybové hlášení validátoru.

Here is an example of a validator on a database table:
Příklad:
``
db.person.name.requires = IS_NOT_EMPTY(error_message='fill this!')
db.person.name.requires = IS_NOT_EMPTY(error_message=T('vyplň to!'))
``:code

where we have used the translation operator ``T`` to allow for internationalization. Notice that default error messages are not translated.
Zde jsme použili operátor ``T`` pro překlad (internacionalizaci). Poznamenejme, že defaultní chybová hlášení nejsou do cílového jazyka překládána.

Mind that the only validators that can be used with ``list:`` type fields are:
Pro pole typu ``list:`` lze použít jedině tyto validátory:

- ``IS_IN_DB(...,multiple=True)``
- ``IS_IN_SET(...,multiple=True)``
- ``IS_NOT_EMPTY()``
- ``IS_LIST_OF(...)``

The latter can be used to apply any validator to the individual items in the list.
Poslední z nich lze použít pro aplikování jakéhokoli validátoru na jednotlivé prvky seznamu.

#### Validators
#### Přehled validátorů

##### ``IS_ALPHANUMERIC``
``IS_ALPHANUMERIC``:inxx

This validator checks that a field value contains only characters in the ranges a-z, A-Z, or 0-9.
Validátor ověří, že hodnota obsahuje jen znaky a-z, A-Z nebo 0-9.
``
requires = IS_ALPHANUMERIC(error_message='must be alphanumeric!')
``:code

##### ``IS_DATE``
``IS_DATE``:inxx

This validator checks that a field value contains a valid date in the specified format. It is good practice to specify the format using the translation operator, in order to support different formats in different locales.
Validátor ověří, že hodnota je platné datum v zadaném formátu. Je vhodné v argumentu ``format`` použít operátor pro překlad, čímž můžeme podporovat různé formáty data podle národních zvyklostí.
``
requires = IS_DATE(format=T('%Y-%m-%d'),
error_message='must be YYYY-MM-DD!')
``:code

For the full description on % directives look under the IS_DATETIME validator.
"%" direktivy popisujeme u IS_DATETIME validátoru.

##### ``IS_DATE_IN_RANGE``
``IS_DATE_IN_RANGE``:inxx

Works very much like the previous validator but allows to specify a range:
Pracuje jako předchozí validátor a navíc umožňuje omezit rozsah doby od-do:
``
requires = IS_DATE_IN_RANGE(format=T('%Y-%m-%d'),
minimum=datetime.date(2008,1,1),
maximum=datetime.date(2009,12,31),
error_message='must be YYYY-MM-DD!')
``:code

For the full description on % directives look under the IS_DATETIME validator.
"%" direktivy popisujeme u IS_DATETIME validátoru.

##### ``IS_DATETIME``
``IS_DATETIME``:inxx

This validator checks that a field value contains a valid datetime in the specified format. It is good practice to specify the format using the translation operator, in order to support different formats in different locales.
Validátor ověří, že hodnota je platné datum spolu s časem, v zadaném formátu. Je vhodné v argumentu ``format`` použít operátor pro překlad, čímž můžeme podporovat různé formáty data podle národních zvyklostí.
``
requires = IS_DATETIME(format=T('%Y-%m-%d %H:%M:%S'),
error_message='must be YYYY-MM-DD HH:MM:SS!')
``:code

The following symbols can be used for the format string (this shows the symbol and an example string):
Možné hodnoty operátoru/symbolu "%" si ukážeme na příkladu:
``
%Y '1963'
%y '63'
Expand All @@ -1576,15 +1576,15 @@ The following symbols can be used for the format string (this shows the symbol a
##### ``IS_DATETIME_IN_RANGE``
``IS_DATETIME_IN_RANGE``:inxx

Works very much like the previous validator but allows to specify a range:
Pracuje jako předchozí validátor a navíc umožňuje omezit rozsah doby od-do:
``
requires = IS_DATETIME_IN_RANGE(format=T('%Y-%m-%d %H:%M:%S'),
minimum=datetime.datetime(2008,1,1,10,30),
maximum=datetime.datetime(2009,12,31,11,45),
error_message='must be YYYY-MM-DD HH:MM::SS!')
``:code

For the full description on % directives look under the IS_DATETIME validator.
"%" direktivy popisujeme u IS_DATETIME validátoru.

##### ``IS_DECIMAL_IN_RANGE``
``IS_DECIMAL_IN_RANGE``:inxx
Expand All @@ -1593,28 +1593,26 @@ For the full description on % directives look under the IS_DATETIME validator.
INPUT(_type='text', _name='name', requires=IS_DECIMAL_IN_RANGE(0, 10, dot="."))
``:code

It converts the input into a Python Decimal or generates an error if
the decimal does not fall within the specified inclusive range.
The comparison is made with Python Decimal arithmetic.
Konvertuje vstup na Python typ Decimal a generuje chybu, není-li výsledek v daném rozsahu.
Porovnání se provádí pomocí Python aritmetiky pro Decimal.

The minimum and maximum limits can be None, meaning no lower or upper limit,
respectively.
Minimum a maximum omezení mohou být None, což znamená, že daný limit není nastaven.

The ``dot`` argument is optional and allows you to internationalize the symbol used to separate the decimals.
Argument ``dot`` je volitelný a umožňuje internacionalizovat znak pro oddělení desetinných míst.


##### ``IS_EMAIL``
``IS_EMAIL``:inxx

It checks that the field value looks like an email address. It does not try to send email to confirm.
Validátor ověří, že hodnota formálně vypadá jako správná emailová adresa.
``
requires = IS_EMAIL(error_message='invalid email!')
``:code

##### ``IS_EQUAL_TO``
``IS_EQUEL_TO``:inxx

Checks whether the validated value is equal to a given value (which can be a variable):
Validátor ověří, že hodnota je shodná s hodnotou argumentu, což může být proměnná:
``
requires = IS_EQUAL_TO(request.vars.password,
error_message='passwords do not match')
Expand All @@ -1623,34 +1621,33 @@ requires = IS_EQUAL_TO(request.vars.password,
##### ``IS_EXPR``
``IS_EXPR``:inxx

Its first argument is a string containing a logical expression in terms of a variable value. It validates a field value if the expression evaluates to ``True``. For example:
Prvním argumentem je řetězec s logickým výrazem nad hodnotou "value". Validace projde, jestliže vyčíslená hodnota výrazu je ``True``. Příklad:
``
requires = IS_EXPR('int(value)%3==0',
error_message='not divisible by 3')
``:code

One should first check that the value is an integer so that an exception will not occur.
Defaultní chybové hlášení je "Invalid expression" ("chybný výraz").
V uvedeném příkladu je vhodné v seznamu validátorů předřadit validátor, který nejprve otestuje, že předaná hodnota je typu Integer. Jinak dojde ve validátoru IS_EXPR() k výjimce.
``
requires = [IS_INT_IN_RANGE(0, 100), IS_EXPR('value%3==0')]
``:code

##### ``IS_FLOAT_IN_RANGE``
``IS_FLOAT_IN_RANGE``:inxx

Checks that the field value is a floating point number within a definite range, ``0 <= value <= 100`` in the following example:
Validátor ověří, že hodnota je float číslo v zadaném rozsahu od-do, v našem příkladu ``0 <= hodnota <= 100``:
``
requires = IS_FLOAT_IN_RANGE(0, 100, dot=".",
error_message='too small or too large!')
``:code

The ``dot`` argument is optional and allows you to internationalize the symbol used to separate the decimals.
Volitený argument ``dot`` umožňuje internacionalizaci symbolu pro oddělení desetinných míst.

##### ``IS_INT_IN_RANGE``
``IS_INT_IN_RANGE``:inxx

Checks that the field value is an integer number within a definite range,
``0 <= value < 100`` in the following example:

Validátor ověří, že hodnota je integer číslo v zadaném rozsahu od-do, v našem příkladu ``0 <= hodnota <= 100``:
``
requires = IS_INT_IN_RANGE(0, 100,
error_message='too small or too large!')
Expand All @@ -1660,42 +1657,40 @@ requires = IS_INT_IN_RANGE(0, 100,
``IS_IN_SET``:inxx
``multiple``:inxx

Checks that the field values are in a set:
Validátor ověří, že hodnota je rovna některé ze zadaných hodnot:
``
requires = IS_IN_SET(['a', 'b', 'c'],zero=T('choose one'),
requires = IS_IN_SET(['a', 'b', 'c'], zero=T('choose one'),
error_message='must be a or b or c')
``:code

The zero argument is optional and it determines the text of the option selected by default, an option which is not accepted by the ``IS_IN_SET`` validator itself. If you do not want a "choose one" option, set ``zero=None``.

The ``zero`` option was introduced in revision (1.67.1). It did not break backward compatibility in the sense that it did not break applications but it did change their behavior since, before, there was no ``zero`` option.
Argument zero je volitelný a uplatní se jako text volby (OPTION) SELECTu, která bude přednastavena. Tuto hodnotu ``IS_IN_SET`` validátor neakceptuje. Pokud toto chování chcete potlačit, nastavte ``zero=None``.

The elements of the set must always be strings unless this validator is preceded by ``IS_INT_IN_RANGE`` (which converts the value to int) or ``IS_FLOAT_IN_RANGE`` (which converts the value to float). For example:
Povolené hodnoty musí vždy být řetězce, pokud ovšem nepředřadíte validátor ``IS_INT_IN_RANGE`` nebo ``IS_FLOAT_IN_RANGE``, které konvertují vstup na číslo daného typu. Příklad:
``
requires = [IS_INT_IN_RANGE(0, 8), IS_IN_SET([2, 3, 5, 7],
error_message='must be prime and less than 10')]
error_message='Zadej prvočíslo menší než 10.')]
``:code

For a form checkbox, use this:
Pro validaci zaškrtnutí checkboxu lze použít toto:
``
requires=IS_IN_SET(['on'])
``:code

You may also use a dictionary or a list of tuples to make the drop down list more descriptive:
Můžete také použít slovník (dictionary) nebo seznam dvojic (tuples), takže nabízené volby budou více popisné:
``
#### Dictionary example:
requires = IS_IN_SET({'A':'Apple','B':'Banana','C':'Cherry'},zero=None)
#### List of tuples example:
requires = IS_IN_SET([('A','Apple'),('B','Banana'),('C','Cherry')])
# Příklad se slovníkem:
requires = IS_IN_SET({'J':'Jablka', 'T':'Třešně', 'B':'Banány'}, zero=None)
# Příklad se seznamem dvojic:
requires = IS_IN_SET([('J','Jablka'), ('T','Třešně'), ('B','Banány')])
``:code


##### ``IS_IN_SET`` and Tagging
##### ``IS_IN_SET`` a označování (tagging)

The ``IS_IN_SET`` validator has an optional attribute ``multiple=False``. If set to True, multiple values can be stored in one field. The field should be of type ``list:integer`` or ``list:string``. ``multiple`` references are handled automatically in create and update forms, but they are transparent to the DAL. We strongly suggest using the jQuery multiselect plugin to render multiple fields.
Validátor ``IS_IN_SET`` má volitelný atribut ``multiple=False``. Pokud jej nastavíme na True, do pole může být uloženo více hodnot. K tomu je potřeba použít pole typu ``list:integer`` nebo ``list:string``. Důrazně doporučujeme používat pro výběr možností jQuery multiselect plugin.

------
Note that when ``multiple=True``, ``IS_IN_SET`` will accept ``zero`` or more values, i.e. it will accept the field when nothing has been selected. ``multiple`` can also be a tuple of the form ``(a,b)`` where ``a`` and ``b`` are the minimum and (exclusive) maximum number of items that can be selected respectively.
Jestliže je nastaveno ``multiple=True``, ``IS_IN_SET`` akceptuje žádnou, jednu nebo několik hodnot, neboli validace projde, i když není nic vybráno. ``multiple`` můžete také nastavit jako dvojici (tuple) ``(a, b)``, kde ``a`` a ``b`` jsou minimální a maximální (ovšem exkluzivně zadáno, tj. testuje se po zmenšení o 1) počet voleb, které uživatel musí označit.
------

##### ``IS_LENGTH``
Expand Down
Binary file modified sources/40-web2py-czech-translation-in-progress/problems.ods
Binary file not shown.

0 comments on commit 3b08f49

Please sign in to comment.