[organization] Support Connector models via inheritance
@@ -25,7 +25,7 @@ from django.utils.translation import ugettext as _, ugettext_lazy as _t
from useradmin.organization import _fitered_queryset, get_user_request_organization
-from desktop.conf import CONNECTORS
+from desktop.conf import CONNECTORS, ENABLE_ORGANIZATIONS
from desktop.lib.connectors.types import get_connectors_types
from desktop.lib.exceptions_renderable import PopupException
@@ -33,6 +33,27 @@ from desktop.lib.exceptions_renderable import PopupException
LOG = logging.getLogger(__name__)
+class BaseConnector(models.Model):
+ """
+ Instance of a connector type pointing to an external service of a certain dialect.
+ """
+ name = models.CharField(default='', max_length=255)
+ description = models.TextField(default='')
+ dialect = models.CharField(max_length=32, db_index=True, help_text=_t('Type of connector, e.g. hive, mysql... '))
+ settings = models.TextField(default='{}')
+ last_modified = models.DateTimeField(auto_now=True, db_index=True, verbose_name=_t('Time last modified'))
+
+ class Meta:
+ abstract = True
+ verbose_name = _t('connector')
+ verbose_name_plural = _t('connectors')
+ unique_together = ('name',)
+
+ def __str__(self):
+ return '%s (%s)' % (self.name, self.dialect)
+
+
+if ENABLE_ORGANIZATIONS.get():
class ConnectorManager(models.Manager):
def get_queryset(self):
@@ -43,24 +64,12 @@ class ConnectorManager(models.Manager):
def natural_key(self):
return (self.organization, self.name,)
-
-class Connector(models.Model):
- """
- Instance of a connector type pointing to an external service of a certain dialect.
- """
- name = models.CharField(default='', max_length=255)
- description = models.TextField(default='')
- dialect = models.CharField(max_length=32, db_index=True, help_text=_t('Type of connector, e.g. hive, mysql... '))
- settings = models.TextField(default='{}')
- last_modified = models.DateTimeField(auto_now=True, db_index=True, verbose_name=_t('Time last modified'))
-
+ class Connector(BaseConnector):
organization = models.ForeignKey('useradmin.Organization', on_delete=models.CASCADE)
objects = ConnectorManager()
class Meta:
- verbose_name = _t('connector')
- verbose_name_plural = _t('connectors')
unique_together = ('name', 'organization',)
def __init__(self, *args, **kwargs):
@@ -71,6 +80,8 @@ class Connector(models.Model):
def __str__(self):
return '%s (%s) @ %s' % (self.name, self.dialect, self.organization)
+else:
+ class Connector(BaseConnector): pass
def _get_installed_connectors(category=None, categories=None, dialect=None, interface=None, user=None):
