Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mock-cheops
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chephren
mock-cheops
Commits
7303ffe6
Unverified
Commit
7303ffe6
authored
1 year ago
by
REIG Julien
Browse files
Options
Downloads
Patches
Plain Diff
add presence array in resource
parent
ccd5ac52
No related branches found
No related tags found
1 merge request
!16
Node knowledge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
models/resource.py
+25
-6
25 additions, 6 deletions
models/resource.py
with
25 additions
and
6 deletions
models/resource.py
+
25
−
6
View file @
7303ffe6
...
...
@@ -14,9 +14,10 @@ class Resource:
self
.
commands
=
[]
if
commands
is
None
else
commands
self
.
commands_count
=
len
(
self
.
commands
)
self
.
deleted
=
False
self
.
presences
=
[]
def
__str__
(
self
):
return
f
"
Resource(id=
{
self
.
id
}
, name=
{
self
.
name
}
, last_update=
{
self
.
last_update
}
, commands=
{
self
.
commands
}
, commands_count=
{
self
.
commands_count
}
, deleted=
{
self
.
deleted
}
)
"
return
f
"
Resource(id=
{
self
.
id
}
, name=
{
self
.
name
}
, last_update=
{
self
.
last_update
}
, commands=
{
self
.
commands
}
, commands_count=
{
self
.
commands_count
}
, deleted=
{
self
.
deleted
}
, presence=
{
self
.
presences
}
)
"
def
__repr__
(
self
):
return
self
.
__str__
()
...
...
@@ -28,11 +29,14 @@ class Resource:
self
.
commands_count
=
len
(
self
.
commands
)
@staticmethod
def
from_tuple
(
data
,
commands
:
list
[
Command
]
=
None
,
commands_count
:
int
=
None
,
deleted
:
bool
=
False
):
def
from_tuple
(
data
,
commands
:
list
[
Command
]
=
None
,
commands_count
:
int
=
None
,
deleted
:
bool
=
False
,
presence
:
list
[
str
]
=
None
):
resource
=
Resource
(
data
[
1
])
resource
.
id
=
data
[
0
]
resource
.
last_update
=
data
[
2
]
resource
.
deleted
=
deleted
if
presence
is
not
None
:
resource
.
presences
=
presence
if
(
commands
is
not
None
):
resource
.
commands
=
commands
resource
.
commands_count
=
len
(
resource
.
commands
)
...
...
@@ -49,25 +53,40 @@ class Resource:
resource
.
commands
=
[
Command
.
from_full_dict
(
command
)
for
command
in
data
[
"
commands
"
]]
resource
.
commands_count
=
len
(
resource
.
commands
)
resource
.
presences
=
data
.
get
(
"
presence
"
,
[])
return
resource
# This method returns a tuple with the following structure:
# (id, name, last_update)
# used to insert a resource into the database
def
to_tuple
(
self
):
return
(
self
.
id
,
self
.
name
,
self
.
last_update
)
def
to_presence_tuples
(
self
):
return
[(
self
.
id
,
presence
)
for
presence
in
self
.
presences
]
def
to_full_dict
(
self
):
return
{
def
to_full_dict
(
self
,
include_presence
:
bool
=
False
):
full_dict
=
{
"
id
"
:
self
.
id
,
"
name
"
:
self
.
name
,
"
lastUpdate
"
:
self
.
last_update
,
"
deleted
"
:
self
.
deleted
,
"
commands
"
:
[
command
.
to_dict
()
for
command
in
self
.
commands
]
}
if
include_presence
:
full_dict
[
"
presence
"
]
=
self
.
presences
return
full_dict
def
to_simple_dict
(
self
):
return
{
def
to_simple_dict
(
self
,
include_presence
:
bool
=
False
):
simple_dict
=
{
"
id
"
:
self
.
id
,
"
name
"
:
self
.
name
,
"
lastUpdate
"
:
self
.
last_update
,
"
deleted
"
:
self
.
deleted
,
"
commandsCount
"
:
self
.
commands_count
}
if
include_presence
:
simple_dict
[
"
presence
"
]
=
self
.
presences
return
simple_dict
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