Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
production
building-knowledge-centre
building-dao
Commits
c92d4e66
Commit
c92d4e66
authored
Oct 18, 2019
by
Marc-Andre Santune
Browse files
allow uid to be None when init
parent
140e6d96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
building_dao/building_generic.py
building_dao/building_generic.py
+11
-3
No files found.
building_dao/building_generic.py
View file @
c92d4e66
...
@@ -7,7 +7,6 @@ import requests
...
@@ -7,7 +7,6 @@ import requests
from
requests.exceptions
import
HTTPError
from
requests.exceptions
import
HTTPError
from
retrying
import
retry
from
retrying
import
retry
from
simplejson
import
JSONDecodeError
from
.settings
import
Settings
from
.settings
import
Settings
MAX_RETRIES
=
5
# max retries number
MAX_RETRIES
=
5
# max retries number
...
@@ -21,21 +20,30 @@ class BuildingGeneric:
...
@@ -21,21 +20,30 @@ class BuildingGeneric:
"""Stores the methods used to receive or update the building info from ES doc"""
"""Stores the methods used to receive or update the building info from ES doc"""
def
__init__
(
self
,
uid
:
str
,
**
kwargs
)
->
None
:
def
__init__
(
self
,
uid
:
str
=
None
,
**
kwargs
)
->
None
:
staging
=
kwargs
.
get
(
"staging"
,
False
)
staging
=
kwargs
.
get
(
"staging"
,
False
)
registry
=
kwargs
.
get
(
"registry"
)
registry
=
kwargs
.
get
(
"registry"
)
self
.
logger
=
logging
.
getLogger
(
self
.
__class__
.
__name__
)
self
.
logger
=
logging
.
getLogger
(
self
.
__class__
.
__name__
)
self
.
_uid
=
uid
self
.
_uid
=
uid
self
.
_building
=
None
self
.
settings
=
Settings
(
staging
=
staging
,
registry
=
registry
)
self
.
settings
=
Settings
(
staging
=
staging
,
registry
=
registry
)
self
.
fetch
()
if
self
.
_uid
:
self
.
fetch
()
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
return
self
.
_building
.
get
(
item
)
return
self
.
_building
.
get
(
item
)
# ----------------- Building level ---------------------
# ----------------- Building level ---------------------
def
post_building
(
self
,
payload
)
->
None
:
"""Post a new building"""
res
=
self
.
_req_with_retries
(
"post"
,
join
(
self
.
settings
.
base_url
),
json
=
payload
)
self
.
_uid
=
res
[
"id"
]
self
.
fetch
()
def
fetch
(
self
)
->
None
:
def
fetch
(
self
)
->
None
:
"""Fetch the building document"""
"""Fetch the building document"""
self
.
_building
=
self
.
_req_with_retries
(
"get"
,
join
(
self
.
settings
.
base_url
,
self
.
_uid
))
self
.
_building
=
self
.
_req_with_retries
(
"get"
,
join
(
self
.
settings
.
base_url
,
self
.
_uid
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment