Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Tryton
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tryton
Tryton
Commits
6c1469e8
Commit
6c1469e8
authored
6 years ago
by
Cédric Krier
Browse files
Options
Downloads
Patches
Plain Diff
Validate selection format in Dict schema
issue7947 review257131002
parent
f0306c17
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG
+1
-0
1 addition, 0 deletions
CHANGELOG
trytond/ir/message.xml
+3
-0
3 additions, 0 deletions
trytond/ir/message.xml
trytond/model/dictschema.py
+18
-1
18 additions, 1 deletion
trytond/model/dictschema.py
trytond/tests/test_field_dict.py
+15
-0
15 additions, 0 deletions
trytond/tests/test_field_dict.py
with
37 additions
and
1 deletion
CHANGELOG
+
1
−
0
View file @
6c1469e8
* Validate selection format in Dict schema
* Allow to extend Field's string and help
* Add console
* Add Model.__names__ to retrieve model and field names
...
...
This diff is collapsed.
Click to expand it.
trytond/ir/message.xml
+
3
−
0
View file @
6c1469e8
...
...
@@ -109,6 +109,9 @@
<record
model=
"ir.message"
id=
"msg_dict_schema_invalid_domain"
>
<field
name=
"text"
>
Invalid domain in schema "%(schema)s".
</field>
</record>
<record
model=
"ir.message"
id=
"msg_dict_schema_invalid_selection"
>
<field
name=
"text"
>
Invalid selection in schema "%(schema)s".
</field>
</record>
<record
model=
"ir.message"
id=
"msg_recursion_error"
>
<field
name=
"text"
>
Recursion error: Record "%(rec_name)s" with parent "%(parent_rec_name)s" was configured as ancestor of itself.
</field>
</record>
...
...
This diff is collapsed.
Click to expand it.
trytond/model/dictschema.py
+
18
−
1
View file @
6c1469e8
...
...
@@ -16,6 +16,10 @@
pass
class
SelectionError
(
ValidationError
):
pass
class
DictSchemaMixin
(
object
):
_rec_name
=
'
string
'
name
=
fields
.
Char
(
'
Name
'
,
required
=
True
)
...
...
@@ -67,6 +71,7 @@
def
validate
(
cls
,
schemas
):
super
(
DictSchemaMixin
,
cls
).
validate
(
schemas
)
cls
.
check_domain
(
schemas
)
cls
.
check_selection
(
schemas
)
@classmethod
def
check_domain
(
cls
,
schemas
):
...
...
@@ -84,7 +89,19 @@
gettext
(
'
ir.msg_dict_schema_invalid_domain
'
,
schema
=
schema
.
rec_name
))
def
get_selection_json
(
self
,
name
):
@classmethod
def
check_selection
(
cls
,
schemas
):
for
schema
in
schemas
:
if
schema
.
type_
!=
'
selection
'
:
continue
try
:
dict
(
json
.
loads
(
schema
.
get_selection_json
()))
except
Exception
:
raise
SelectionError
(
gettext
(
'
ir.msg_dict_schema_invalid_selection
'
,
schema
=
schema
.
rec_name
))
def
get_selection_json
(
self
,
name
=
None
):
db_selection
=
self
.
selection
or
''
selection
=
[[
w
.
strip
()
for
w
in
v
.
split
(
'
:
'
,
1
)]
for
v
in
db_selection
.
splitlines
()
if
v
]
...
...
This diff is collapsed.
Click to expand it.
trytond/tests/test_field_dict.py
+
15
−
0
View file @
6c1469e8
...
...
@@ -3,6 +3,7 @@
import
unittest
from
trytond
import
backend
from
trytond.model.dictschema
import
SelectionError
from
trytond.model.exceptions
import
RequiredValidationError
from
trytond.pool
import
Pool
from
trytond.tests.test_tryton
import
activate_module
,
with_transaction
...
...
@@ -130,6 +131,20 @@
self
.
assertDictEqual
(
dict_
.
dico
,
{
'
type
'
:
'
arabic
'
})
@with_transaction
()
def
test_invalid_selection_schema
(
self
):
"
Test invalid selection schema
"
pool
=
Pool
()
DictSchema
=
pool
.
get
(
'
test.dict.schema
'
)
with
self
.
assertRaises
(
SelectionError
):
DictSchema
.
create
([{
'
name
'
:
'
selection
'
,
'
string
'
:
"
Selection
"
,
'
type_
'
:
'
selection
'
,
'
selection
'
:
'
foo
'
,
}])
@with_transaction
()
@unittest.skipIf
(
backend
.
name
()
!=
'
postgresql
'
,
'
jsonb only supported by postgresql
'
)
def
test_create_jsonb
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment