Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
d5045fd8
Commit
d5045fd8
authored
Feb 20, 2020
by
Lukas Burgey
Browse files
Rework get_service
parent
878b84e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
feudal/backend/models/__init__.py
View file @
d5045fd8
...
...
@@ -76,36 +76,25 @@ class Service(models.Model):
# default values or values to update are expected as kwargs
@
classmethod
def
get_service
(
cls
,
name
,
site
,
**
kwargs
):
description
=
kwargs
.
get
(
'description'
,
''
)
contact_email
=
kwargs
.
get
(
'contact_email'
,
''
)
contact_description
=
kwargs
.
get
(
'contact_description'
,
''
)
vos
=
kwargs
.
get
(
'vos'
,
None
)
# non essential args
defaults
=
{}
for
key
in
[
'description'
,
'contact_email'
,
'contact_description'
]:
if
key
in
kwargs
:
defaults
[
key
]
=
kwargs
[
key
]
service
,
created
=
cls
.
objects
.
get
_or_create
(
service
,
created
=
cls
.
objects
.
update
_or_create
(
name
=
name
,
site
=
site
,
defaults
=
{
'description'
:
description
,
'contact_email'
:
contact_email
,
'contact_description'
:
contact_description
,
},
defaults
=
defaults
,
)
if
created
:
service
.
save
()
if
vos
is
not
None
:
for
vo
in
vos
:
service
.
vos
.
add
(
vo
)
LOGGER
.
info
(
'Service created: %s'
,
service
)
else
:
if
service
.
description
!=
description
:
service
.
description
=
description
service
.
save
()
if
service
.
contact_email
!=
contact_email
:
service
.
contact_email
=
contact_email
service
.
save
()
if
service
.
contact_description
!=
contact_description
:
service
.
contact_description
=
contact_description
service
.
save
()
if
'vos'
in
kwargs
:
for
vo
in
kwargs
[
'vos'
]:
if
not
service
.
vos
.
contains
(
vo
):
LOGGER
.
info
(
'VO %s now permits use of service %s'
,
vo
,
service
)
service
.
vos
.
add
(
vo
)
return
service
...
...
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