Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
72192551
Commit
72192551
authored
6 years ago
by
Swen Vermeul
Browse files
Options
Downloads
Patches
Plain Diff
added .props[property-name] to support properties containing a dash or a dot
parent
41ccfcb7
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pybis/src/python/pybis/property.py
+33
-8
33 additions, 8 deletions
pybis/src/python/pybis/property.py
with
33 additions
and
8 deletions
pybis/src/python/pybis/property.py
+
33
−
8
View file @
72192551
...
@@ -10,7 +10,10 @@ class PropertyHolder():
...
@@ -10,7 +10,10 @@ class PropertyHolder():
if
type
is
not
None
:
if
type
is
not
None
:
self
.
__dict__
[
'
_type
'
]
=
type
self
.
__dict__
[
'
_type
'
]
=
type
for
prop
in
type
.
data
[
'
propertyAssignments
'
]:
for
prop
in
type
.
data
[
'
propertyAssignments
'
]:
self
.
_property_names
[
prop
[
'
propertyType
'
][
'
code
'
].
lower
()]
=
prop
[
'
propertyType
'
]
property_name
=
prop
[
'
propertyType
'
][
'
code
'
].
lower
()
self
.
_property_names
[
property_name
]
=
prop
[
'
propertyType
'
]
self
.
_property_names
[
property_name
][
'
mandatory
'
]
=
prop
[
'
mandatory
'
]
self
.
_property_names
[
property_name
][
'
showInEditView
'
]
=
prop
[
'
showInEditView
'
]
def
_get_terms
(
self
,
vocabulary
):
def
_get_terms
(
self
,
vocabulary
):
return
self
.
_openbis
.
get_terms
(
vocabulary
)
return
self
.
_openbis
.
get_terms
(
vocabulary
)
...
@@ -22,6 +25,8 @@ class PropertyHolder():
...
@@ -22,6 +25,8 @@ class PropertyHolder():
return
props
return
props
def
all
(
self
):
def
all
(
self
):
"""
Returns the properties as an array
"""
props
=
{}
props
=
{}
for
code
in
self
.
_type
.
codes
():
for
code
in
self
.
_type
.
codes
():
props
[
code
]
=
getattr
(
self
,
code
)
props
[
code
]
=
getattr
(
self
,
code
)
...
@@ -35,6 +40,12 @@ class PropertyHolder():
...
@@ -35,6 +40,12 @@ class PropertyHolder():
props
[
code
]
=
value
props
[
code
]
=
value
return
props
return
props
def
__getitem__
(
self
,
key
):
"""
For properties that contain either a dot or a dash or any other non-valid method character,
a user can use a key-lookup instead, e.g. sample.props[
'
my-weird.property-name
'
]
"""
return
getattr
(
self
,
key
)
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
"""
attribute syntax can be found out by
"""
attribute syntax can be found out by
adding an underscore at the end of the property name
adding an underscore at the end of the property name
...
@@ -44,8 +55,8 @@ class PropertyHolder():
...
@@ -44,8 +55,8 @@ class PropertyHolder():
return
return
if
name
.
endswith
(
'
_
'
):
if
name
.
endswith
(
'
_
'
):
name
=
name
.
rstrip
(
'
_
'
)
name
=
name
.
rstrip
(
'
_
'
)
if
name
in
self
.
_
type
.
prop
:
if
name
in
self
.
_
property_names
:
property_type
=
self
.
_
type
.
prop
[
name
][
'
propertyType
'
]
property_type
=
self
.
_
property_names
[
name
]
if
property_type
[
'
dataType
'
]
==
'
CONTROLLEDVOCABULARY
'
:
if
property_type
[
'
dataType
'
]
==
'
CONTROLLEDVOCABULARY
'
:
return
self
.
_get_terms
(
property_type
[
'
vocabulary
'
][
'
code
'
])
return
self
.
_get_terms
(
property_type
[
'
vocabulary
'
][
'
code
'
])
else
:
else
:
...
@@ -56,8 +67,10 @@ class PropertyHolder():
...
@@ -56,8 +67,10 @@ class PropertyHolder():
else
:
else
:
return
return
def
__setattr__
(
self
,
name
,
value
):
def
__setattr__
(
self
,
name
,
value
):
"""
This special method allows a PropertyHolder object
to check the attributes that are assigned to that object
"""
if
name
not
in
self
.
_property_names
:
if
name
not
in
self
.
_property_names
:
raise
KeyError
(
raise
KeyError
(
"
No such property:
'
{}
'
. Allowed properties are: {}
"
.
format
(
"
No such property:
'
{}
'
. Allowed properties are: {}
"
.
format
(
...
@@ -78,6 +91,12 @@ class PropertyHolder():
...
@@ -78,6 +91,12 @@ class PropertyHolder():
raise
ValueError
(
"
Value must be of type {}
"
.
format
(
data_type
))
raise
ValueError
(
"
Value must be of type {}
"
.
format
(
data_type
))
self
.
__dict__
[
name
]
=
value
self
.
__dict__
[
name
]
=
value
def
__setitem__
(
self
,
key
,
value
):
"""
For properties that contain either a dot or a dash or any other non-valid method character,
a user can use a key instead, e.g. sample.props[
'
my-weird.property-name
'
]
"""
return
setattr
(
self
,
key
,
value
)
def
__dir__
(
self
):
def
__dir__
(
self
):
return
self
.
_property_names
return
self
.
_property_names
...
@@ -96,14 +115,20 @@ class PropertyHolder():
...
@@ -96,14 +115,20 @@ class PropertyHolder():
<tr style=
"
text-align: right;
"
>
<tr style=
"
text-align: right;
"
>
<th>property</th>
<th>property</th>
<th>value</th>
<th>value</th>
<th>description</th>
<th>type</th>
<th>mandatory</th>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody>
"""
"""
for
prop
in
self
.
_property_names
:
for
prop_name
,
prop
in
self
.
_property_names
.
items
():
html
+=
"
<tr> <td>{}</td> <td>{}</td> </tr>
"
.
format
(
html
+=
"
<tr> <td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td> </tr>
"
.
format
(
prop
,
nvl
(
getattr
(
self
,
prop
,
''
),
''
)
prop_name
,
nvl
(
getattr
(
self
,
prop_name
,
''
),
''
),
prop
.
get
(
'
description
'
),
prop
.
get
(
'
dataType
'
),
prop
.
get
(
'
mandatory
'
),
)
)
html
+=
"""
html
+=
"""
...
@@ -122,7 +147,7 @@ class PropertyHolder():
...
@@ -122,7 +147,7 @@ class PropertyHolder():
return
False
return
False
return
str
(
val
)
return
str
(
val
)
headers
=
[
'
property
'
,
'
value
'
]
headers
=
[
'
property
'
,
'
value
'
,
'
mandatory
'
]
lines
=
[]
lines
=
[]
for
prop_name
in
self
.
_property_names
:
for
prop_name
in
self
.
_property_names
:
...
...
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