def pre_mailinglist_save(instance, **kwargs): sync_service = GSuiteSyncService() group = sync_service.mailinglist_to_group(instance) old_list = MailingList.objects.filter(pk=instance.pk).first() try: if old_list is None: sync_service.create_group(group) else: sync_service.update_group(old_list.name, group) except HttpError: # Cannot do direct create or update, do full sync for list sync_service.sync_mailinglists([group])
def pre_mailinglist_save(instance, **kwargs): if settings.GSUITE_ADMIN_CREDENTIALS == {}: logger.warning( "Cannot sync mailinglists because there are no GSuite credentials available" ) return sync_service = GSuiteSyncService() group = sync_service.mailinglist_to_group(instance) old_list = MailingList.objects.filter(pk=instance.pk).first() try: if old_list is None: sync_service.create_group(group) else: sync_service.update_group(old_list.name, group) except HttpError: # Cannot do direct create or update, do full sync for list sync_service.sync_mailinglists([group])
def handle(self, *args, **options): """Sync all mailing lists""" sync_service = GSuiteSyncService() sync_service.sync_mailinglists()