removed some django warnings

This commit is contained in:
amon-ra 2015-05-01 19:23:22 +02:00
parent 33ff8f87af
commit 9a836f6e25
12 changed files with 28 additions and 30 deletions

View file

@ -8,7 +8,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db import models
from django.shortcuts import redirect
from django.utils import importlib
import importlib
from django.utils.html import escape
from django.utils.safestring import mark_safe

View file

@ -5,7 +5,7 @@ from urllib.parse import parse_qsl
from django import forms
from django.conf.urls import patterns, url
from django.contrib import admin, messages
from django.contrib.admin.util import unquote
from django.contrib.admin.utils import unquote
from django.contrib.auth import admin as auth
from django.http import HttpResponseRedirect
from django.utils.safestring import mark_safe

View file

@ -2,7 +2,7 @@ from collections import OrderedDict
from django import forms
from django.core.exceptions import ValidationError
from django.db.models.loading import get_model
from django.apps import apps
from django.utils.translation import ugettext_lazy as _
from orchestra.forms import UserCreationForm
@ -19,7 +19,7 @@ def create_account_creation_form():
"Notice that a related system user will be always created."))
})
for model, __, kwargs, help_text in settings.ACCOUNTS_CREATE_RELATED:
model = get_model(model)
model = apps.get_model(model)
field_name = 'create_%s' % model._meta.model_name
label = _("Create %s") % model._meta.verbose_name
fields[field_name] = forms.BooleanField(initial=True, required=False, label=label,
@ -41,7 +41,7 @@ def create_account_creation_form():
if systemuser_model.objects.filter(username=account.username).exists():
errors['username'] = _("A system user with this name already exists.")
for model, key, related_kwargs, __ in settings.ACCOUNTS_CREATE_RELATED:
model = get_model(model)
model = apps.get_model(model)
kwargs = {
key: eval(related_kwargs[key], {'account': account})
}
@ -59,7 +59,7 @@ def create_account_creation_form():
def save_related(self, account):
for model, key, related_kwargs, __ in settings.ACCOUNTS_CREATE_RELATED:
model = get_model(model)
model = apps.get_model(model)
field_name = 'create_%s' % model._meta.model_name
if self.cleaned_data[field_name]:
kwargs = {

View file

@ -1,7 +1,7 @@
from django.contrib.auth import models as auth
from django.core import validators
from django.db import models
from django.db.models.loading import get_model
from django.apps import apps
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@ -146,7 +146,7 @@ class Account(auth.AbstractBaseUser):
for model, key, related_kwargs, __ in settings.ACCOUNTS_CREATE_RELATED:
if 'password' not in related_kwargs:
continue
model = get_model(model)
model = apps.get_model(model)
kwargs = {
key: eval(related_kwargs[key], {'account': self})
}

View file

@ -1,7 +1,7 @@
import sys
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import get_model
from django.apps import apps
from orchestra.contrib.orchestration import manager, Operation
from orchestra.contrib.orchestration.models import Server
@ -36,7 +36,7 @@ class Command(BaseCommand):
for backend in ServiceBackend.get_backends():
self.stdout.write(str(backend).split("'")[1])
return
model = get_model(*options['model'].split('.'))
model = apps.get_model(*options['model'].split('.'))
action = options.get('action')
interactive = options.get('interactive')
servers = options.get('servers')

View file

@ -1,6 +1,6 @@
import socket
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.functional import cached_property
@ -106,7 +106,7 @@ class BackendOperation(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
instance = generic.GenericForeignKey('content_type', 'object_id')
instance = GenericForeignKey('content_type', 'object_id')
class Meta:
verbose_name = _("Operation")

View file

@ -4,10 +4,10 @@ import logging
from django.db import models
from django.db.models import F, Q
from django.db.models.loading import get_model
from django.apps import apps
from django.db.models.signals import post_delete, post_save, pre_delete
from django.dispatch import receiver
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@ -61,7 +61,7 @@ class OrderQuerySet(models.QuerySet):
def get_related(self, **options):
""" returns related orders that could have a pricing effect """
Service = get_model(settings.ORDERS_SERVICE_MODEL)
Service = apps.get_model(settings.ORDERS_SERVICE_MODEL)
conflictive = self.filter(service__metric='')
conflictive = conflictive.exclude(service__billing_period=Service.NEVER)
conflictive = conflictive.select_related('service').group_by('account_id', 'service')
@ -122,7 +122,7 @@ class Order(models.Model):
ignore = models.BooleanField(_("ignore"), default=False)
description = models.TextField(_("description"), blank=True)
content_object = generic.GenericForeignKey()
content_object = GenericForeignKey()
objects = OrderQuerySet.as_manager()
class Meta:
@ -135,7 +135,7 @@ class Order(models.Model):
def update_orders(cls, instance, service=None, commit=True):
updates = []
if service is None:
Service = get_model(settings.ORDERS_SERVICE_MODEL)
Service = apps.get_model(settings.ORDERS_SERVICE_MODEL)
services = Service.get_services(instance)
else:
services = [service]

View file

@ -1,7 +1,7 @@
from django.conf.urls import patterns, url
from django.contrib import admin, messages
from django.contrib.admin.utils import unquote
from django.contrib.contenttypes import generic
from django.contrib import contenttypes
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.utils.functional import cached_property
@ -180,7 +180,7 @@ admin.site.register(MonitorData, MonitorDataAdmin)
# Mokey-patching
def resource_inline_factory(resources):
class ResourceInlineFormSet(generic.BaseGenericInlineFormSet):
class ResourceInlineFormSet(contenttype.forms.BaseGenericInlineFormSet):
def total_form_count(self, resources=resources):
return len(resources)
@ -220,7 +220,7 @@ def resource_inline_factory(resources):
forms.append(self._construct_form(i, resource=resource))
return forms
class ResourceInline(generic.GenericTabularInline):
class ResourceInline(contenttype.admin.GenericTabularInline):
model = ResourceData
verbose_name_plural = _("resources")
form = ResourceForm

View file

@ -2,7 +2,6 @@ from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelatio
from django.contrib.contenttypes.models import ContentType
from django.apps import apps
from django.db import models
from django.db.models.loading import get_model
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
@ -106,7 +105,7 @@ class Resource(models.Model):
try:
self.get_model_path(monitor)
except (RuntimeError, LookupError):
model = get_model(ServiceMonitor.get_backend(monitor).model)
model = apps.get_model(ServiceMonitor.get_backend(monitor).model)
monitor_errors.append(model._meta.model_name)
if monitor_errors:
model_name = self.content_type.model_class()._meta.model_name

View file

@ -2,7 +2,7 @@ import decimal
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.loading import get_model
from django.apps import apps
from django.utils.functional import cached_property
from django.utils.module_loading import autodiscover_modules
from django.utils.translation import string_concat, ugettext_lazy as _
@ -236,7 +236,7 @@ class Service(models.Model):
return rate_class.get_methods()[self.rate_algorithm]
def update_orders(self, commit=True):
order_model = get_model(settings.SERVICES_ORDER_MODEL)
order_model = apps.get_model(settings.SERVICES_ORDER_MODEL)
related_model = self.content_type.model_class()
updates = []
queryset = related_model.objects.all()

View file

@ -1,6 +1,6 @@
from django.conf import settings
from django.db.models import loading
from django.utils import importlib
import importlib
def get_model(label, import_module=True):

View file

@ -1,6 +1,5 @@
from django.contrib.auth.backends import ModelBackend
from django.db.models.loading import get_model, get_app, get_models
from django.apps import apps
class OrchestraPermissionBackend(ModelBackend):
supports_object_permissions = True
@ -16,7 +15,7 @@ class OrchestraPermissionBackend(ModelBackend):
if obj is None:
app_label = perm.split('.')[0]
model_label = perm.split('_')[1]
model = get_model(app_label, model_label)
model = apps.get_model(app_label, model_label)
perm_manager = model
else:
perm_manager = obj
@ -34,8 +33,8 @@ class OrchestraPermissionBackend(ModelBackend):
"""
if not user.is_active:
return False
app = get_app(app_label)
for model in get_models(app):
app = apps.get_app_config(app_label)
for model in apps.get_models(app):
try:
has_perm = model.has_permission.view(user)
except AttributeError: