Commit d5045fd8 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Rework get_service

parent 878b84e3
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment