Replace field.rel.to with field.remote_field.model
Field.rel and Field.remote_field.to are removed in Django 2.x
This commit is contained in:
parent
b6cf0c34f5
commit
97f1c7ef2b
|
@ -27,7 +27,7 @@ def create_local_address(sender, *args, **kwargs):
|
||||||
mbox = kwargs['instance']
|
mbox = kwargs['instance']
|
||||||
local_domain = settings.MAILBOXES_LOCAL_DOMAIN
|
local_domain = settings.MAILBOXES_LOCAL_DOMAIN
|
||||||
if not mbox.pk and local_domain:
|
if not mbox.pk and local_domain:
|
||||||
Domain = Address._meta.get_field('domain').rel.to
|
Domain = Address._meta.get_field('domain').remote_field.model
|
||||||
try:
|
try:
|
||||||
domain = Domain.objects.get(name=local_domain)
|
domain = Domain.objects.get(name=local_domain)
|
||||||
except Domain.DoesNotExist:
|
except Domain.DoesNotExist:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from orchestra.core import services
|
||||||
def get_related_object(origin, max_depth=2):
|
def get_related_object(origin, max_depth=2):
|
||||||
"""
|
"""
|
||||||
Introspects origin object and return the first related service object
|
Introspects origin object and return the first related service object
|
||||||
|
|
||||||
WARNING this is NOT an exhaustive search but a compromise between cost and
|
WARNING this is NOT an exhaustive search but a compromise between cost and
|
||||||
flexibility. A more comprehensive approach may be considered if
|
flexibility. A more comprehensive approach may be considered if
|
||||||
a use-case calls for it.
|
a use-case calls for it.
|
||||||
|
@ -16,12 +16,12 @@ def get_related_object(origin, max_depth=2):
|
||||||
if hasattr(field, 'ct_field'):
|
if hasattr(field, 'ct_field'):
|
||||||
yield getattr(node, field.name)
|
yield getattr(node, field.name)
|
||||||
for field in node._meta.fields:
|
for field in node._meta.fields:
|
||||||
if field.rel:
|
if field.remote_field:
|
||||||
try:
|
try:
|
||||||
yield getattr(node, field.name)
|
yield getattr(node, field.name)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# BFS model relation transversal
|
# BFS model relation transversal
|
||||||
queue = [[origin]]
|
queue = [[origin]]
|
||||||
while queue:
|
while queue:
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ResourceAdmin(ExtendedModelAdmin):
|
||||||
""" filter service content_types """
|
""" filter service content_types """
|
||||||
if db_field.name == 'content_type':
|
if db_field.name == 'content_type':
|
||||||
models = [ model._meta.model_name for model in services.get() ]
|
models = [ model._meta.model_name for model in services.get() ]
|
||||||
kwargs['queryset'] = db_field.rel.to.objects.filter(model__in=models)
|
kwargs['queryset'] = db_field.remote_field.model.objects.filter(model__in=models)
|
||||||
return super(ResourceAdmin, self).formfield_for_dbfield(db_field, **kwargs)
|
return super(ResourceAdmin, self).formfield_for_dbfield(db_field, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -342,7 +342,7 @@ def create_resource_relation():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
related._meta.private_fields = [
|
related._meta.private_fields = [
|
||||||
field for field in related._meta.private_fields if field.rel.to != ResourceData
|
field for field in related._meta.private_fields if field.remote_field.model != ResourceData
|
||||||
]
|
]
|
||||||
|
|
||||||
for ct, resources in Resource.objects.group_by('content_type').items():
|
for ct, resources in Resource.objects.group_by('content_type').items():
|
||||||
|
|
|
@ -11,5 +11,4 @@ class VirtualDatabaseRelation(GenericRelation):
|
||||||
pks.append(obj.database_id)
|
pks.append(obj.database_id)
|
||||||
if not pks:
|
if not pks:
|
||||||
return []
|
return []
|
||||||
# TODO renamed to self.remote_field in django 1.8
|
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
|
||||||
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
'http': (Website.HTTP, (Website.HTTP, Website.HTTP_AND_HTTPS)),
|
'http': (Website.HTTP, (Website.HTTP, Website.HTTP_AND_HTTPS)),
|
||||||
'https': (Website.HTTPS_ONLY, (Website.HTTPS, Website.HTTP_AND_HTTPS, Website.HTTPS_ONLY)),
|
'https': (Website.HTTPS_ONLY, (Website.HTTPS, Website.HTTP_AND_HTTPS, Website.HTTPS_ONLY)),
|
||||||
}
|
}
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
verbose_name = None
|
verbose_name = None
|
||||||
form = SaaSPasswordForm
|
form = SaaSPasswordForm
|
||||||
|
@ -34,7 +34,7 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
class_verbose_name = _("Software as a Service")
|
class_verbose_name = _("Software as a Service")
|
||||||
plugin_field = 'service'
|
plugin_field = 'service'
|
||||||
allow_custom_url = False
|
allow_custom_url = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def get_plugins(cls, all=False):
|
def get_plugins(cls, all=False):
|
||||||
|
@ -48,18 +48,18 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
for cls in settings.SAAS_ENABLED_SERVICES:
|
for cls in settings.SAAS_ENABLED_SERVICES:
|
||||||
plugins.append(import_class(cls))
|
plugins.append(import_class(cls))
|
||||||
return plugins
|
return plugins
|
||||||
|
|
||||||
def get_change_readonly_fields(cls):
|
def get_change_readonly_fields(cls):
|
||||||
fields = super(SoftwareService, cls).get_change_readonly_fields()
|
fields = super(SoftwareService, cls).get_change_readonly_fields()
|
||||||
return fields + ('name',)
|
return fields + ('name',)
|
||||||
|
|
||||||
def get_site_domain(self):
|
def get_site_domain(self):
|
||||||
context = {
|
context = {
|
||||||
'site_name': self.instance.name,
|
'site_name': self.instance.name,
|
||||||
'name': self.instance.name,
|
'name': self.instance.name,
|
||||||
}
|
}
|
||||||
return self.site_domain % context
|
return self.site_domain % context
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.allow_custom_url:
|
if self.allow_custom_url:
|
||||||
if self.instance.custom_url:
|
if self.instance.custom_url:
|
||||||
|
@ -69,7 +69,7 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'custom_url': _("Custom URL not allowed for this service."),
|
'custom_url': _("Custom URL not allowed for this service."),
|
||||||
})
|
})
|
||||||
|
|
||||||
def clean_data(self):
|
def clean_data(self):
|
||||||
data = super(SoftwareService, self).clean_data()
|
data = super(SoftwareService, self).clean_data()
|
||||||
if not self.instance.pk:
|
if not self.instance.pk:
|
||||||
|
@ -88,10 +88,10 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
if errors:
|
if errors:
|
||||||
raise ValidationError(errors)
|
raise ValidationError(errors)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_directive_name(self):
|
def get_directive_name(self):
|
||||||
return '%s-saas' % self.name
|
return '%s-saas' % self.name
|
||||||
|
|
||||||
def get_directive(self, *args):
|
def get_directive(self, *args):
|
||||||
if not args:
|
if not args:
|
||||||
instance = self.instance
|
instance = self.instance
|
||||||
|
@ -106,7 +106,7 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
website__domains__name=url.netloc,
|
website__domains__name=url.netloc,
|
||||||
website__account=account,
|
website__account=account,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_website(self):
|
def get_website(self):
|
||||||
url = urlparse(self.instance.custom_url)
|
url = urlparse(self.instance.custom_url)
|
||||||
account = self.instance.account
|
account = self.instance.account
|
||||||
|
@ -117,10 +117,10 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
directives__name=self.get_directive_name(),
|
directives__name=self.get_directive_name(),
|
||||||
directives__value=url.path,
|
directives__value=url.path,
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_or_update_directive(self):
|
def create_or_update_directive(self):
|
||||||
return helpers.create_or_update_directive(self)
|
return helpers.create_or_update_directive(self)
|
||||||
|
|
||||||
def delete_directive(self):
|
def delete_directive(self):
|
||||||
directive = None
|
directive = None
|
||||||
try:
|
try:
|
||||||
|
@ -131,7 +131,7 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
return
|
return
|
||||||
if directive is not None:
|
if directive is not None:
|
||||||
directive.delete()
|
directive.delete()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
# pre instance.save()
|
# pre instance.save()
|
||||||
if isinstalled('orchestra.contrib.websites'):
|
if isinstalled('orchestra.contrib.websites'):
|
||||||
|
@ -139,11 +139,11 @@ class SoftwareService(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
self.create_or_update_directive()
|
self.create_or_update_directive()
|
||||||
elif self.instance.pk:
|
elif self.instance.pk:
|
||||||
self.delete_directive()
|
self.delete_directive()
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
if isinstalled('orchestra.contrib.websites'):
|
if isinstalled('orchestra.contrib.websites'):
|
||||||
self.delete_directive()
|
self.delete_directive()
|
||||||
|
|
||||||
def get_related(self):
|
def get_related(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class DBSoftwareService(SoftwareService):
|
||||||
db_name = None
|
db_name = None
|
||||||
db_user = None
|
db_user = None
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def get_db_name(self):
|
def get_db_name(self):
|
||||||
context = {
|
context = {
|
||||||
'name': self.instance.name,
|
'name': self.instance.name,
|
||||||
|
@ -161,15 +161,15 @@ class DBSoftwareService(SoftwareService):
|
||||||
db_name = self.db_name % context
|
db_name = self.db_name % context
|
||||||
# Limit for mysql database names
|
# Limit for mysql database names
|
||||||
return db_name[:65]
|
return db_name[:65]
|
||||||
|
|
||||||
def get_db_user(self):
|
def get_db_user(self):
|
||||||
return self.db_user
|
return self.db_user
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
def get_account(self):
|
def get_account(self):
|
||||||
account_model = self.instance._meta.get_field('account')
|
account_model = self.instance._meta.get_field('account')
|
||||||
return account_model.rel.to.objects.get_main()
|
return account_model.remote_field.model.objects.get_main()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(DBSoftwareService, self).validate()
|
super(DBSoftwareService, self).validate()
|
||||||
create = not self.instance.pk
|
create = not self.instance.pk
|
||||||
|
@ -192,7 +192,7 @@ class DBSoftwareService(SoftwareService):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'name': e.messages,
|
'name': e.messages,
|
||||||
})
|
})
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
super(DBSoftwareService, self).save()
|
super(DBSoftwareService, self).save()
|
||||||
account = self.get_account()
|
account = self.get_account()
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ServiceAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
|
||||||
""" Improve performance of account field and filter by account """
|
""" Improve performance of account field and filter by account """
|
||||||
if db_field.name == 'content_type':
|
if db_field.name == 'content_type':
|
||||||
models = [model._meta.model_name for model in services.get()]
|
models = [model._meta.model_name for model in services.get()]
|
||||||
queryset = db_field.rel.to.objects
|
queryset = db_field.remote_field.model.objects
|
||||||
kwargs['queryset'] = queryset.filter(model__in=models)
|
kwargs['queryset'] = queryset.filter(model__in=models)
|
||||||
if db_field.name in ['match', 'metric', 'order_description']:
|
if db_field.name in ['match', 'metric', 'order_description']:
|
||||||
kwargs['widget'] = forms.TextInput(attrs={'size':'160'})
|
kwargs['widget'] = forms.TextInput(attrs={'size':'160'})
|
||||||
|
|
|
@ -12,8 +12,7 @@ class VirtualDatabaseRelation(GenericRelation):
|
||||||
pks.append(db_id)
|
pks.append(db_id)
|
||||||
if not pks:
|
if not pks:
|
||||||
return []
|
return []
|
||||||
# TODO renamed to self.remote_field in django 1.8
|
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
|
||||||
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)
|
|
||||||
|
|
||||||
|
|
||||||
class VirtualDatabaseUserRelation(GenericRelation):
|
class VirtualDatabaseUserRelation(GenericRelation):
|
||||||
|
@ -26,5 +25,4 @@ class VirtualDatabaseUserRelation(GenericRelation):
|
||||||
pks.append(db_id)
|
pks.append(db_id)
|
||||||
if not pks:
|
if not pks:
|
||||||
return []
|
return []
|
||||||
# TODO renamed to self.remote_field in django 1.8
|
return self.remote_field.model._base_manager.db_manager(using).filter(pk__in=pks)
|
||||||
return self.rel.to._base_manager.db_manager(using).filter(pk__in=pks)
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ def get_model_field_path(origin, target):
|
||||||
if node == target:
|
if node == target:
|
||||||
return path
|
return path
|
||||||
for field in node._meta.fields:
|
for field in node._meta.fields:
|
||||||
if field.rel:
|
if field.remote_field:
|
||||||
new_model = list(model)
|
new_model = list(model)
|
||||||
new_model.append(field.rel.to)
|
new_model.append(field.remote_field.model)
|
||||||
new_path = list(path)
|
new_path = list(path)
|
||||||
new_path.append(field.name)
|
new_path.append(field.name)
|
||||||
queue.append((new_model, new_path))
|
queue.append((new_model, new_path))
|
||||||
|
|
Loading…
Reference in New Issue