Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaned up apps to not use import_module

  • Loading branch information...
commit b27a1286e40d866c86f3a9c26a3a9d7d61a2977a 1 parent 6ebe80c
David Winterbottom codeinthehole authored
4 oscar/apps/checkout/decorators.py
View
@@ -2,8 +2,8 @@
from django.contrib import messages
from django.core.urlresolvers import reverse
-from oscar.core.loading import import_module
-import_module('checkout.utils', ['ProgressChecker'], locals())
+from oscar.core.loading import get_class
+ProgressChecker = get_class('checkout.utils', 'ProgressChecker')
def prev_steps_must_be_complete(view_fn):
43 oscar/apps/checkout/views.py
View
@@ -5,30 +5,35 @@
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import login
+from django.db.models import get_model
from django.utils.translation import ugettext as _
from django.views.generic import DetailView, TemplateView, FormView, \
DeleteView, UpdateView, CreateView
from oscar.apps.shipping.methods import Free
-from oscar.core.loading import import_module
-import_module('checkout.forms', ['ShippingAddressForm', 'GatewayForm'], locals())
-import_module('checkout.calculators', ['OrderTotalCalculator'], locals())
-import_module('checkout.utils', ['CheckoutSessionData'], locals())
-import_module('checkout.signals', ['pre_payment', 'post_payment'], locals())
-import_module('order.models', ['Order', 'ShippingAddress',
- 'CommunicationEvent', 'PaymentEventType',
- 'PaymentEvent'], locals())
-import_module('order.utils', ['OrderNumberGenerator', 'OrderCreator'], locals())
-import_module('address.models', ['UserAddress'], locals())
-import_module('address.forms', ['UserAddressForm'], locals())
-import_module('shipping.repository', ['Repository'], locals())
-import_module('customer.models', ['Email', 'CommunicationEventType'], locals())
-import_module('customer.views', ['AccountAuthView'], locals())
-import_module('customer.utils', ['Dispatcher'], locals())
-import_module('payment.exceptions', ['RedirectRequired', 'UnableToTakePayment',
- 'PaymentError'], locals())
-import_module('order.exceptions', ['UnableToPlaceOrder'], locals())
-import_module('basket.models', ['Basket'], locals())
+from oscar.core.loading import get_class, get_classes
+ShippingAddressForm, GatewayForm = get_classes('checkout.forms', ['ShippingAddressForm', 'GatewayForm'])
+OrderTotalCalculator = get_class('checkout.calculators', 'OrderTotalCalculator')
+CheckoutSessionData = get_class('checkout.utils', 'CheckoutSessionData')
+pre_payment, post_payment = get_classes('checkout.signals', ['pre_payment', 'post_payment'])
+OrderNumberGenerator, OrderCreator = get_classes('order.utils', ['OrderNumberGenerator', 'OrderCreator'])
+UserAddressForm = get_class('address.forms', 'UserAddressForm')
+Repository = get_class('shipping.repository', 'Repository')
+AccountAuthView = get_class('customer.views', 'AccountAuthView')
+Dispatcher = get_class('customer.utils', 'Dispatcher')
+RedirectRequired, UnableToTakePayment, PaymentError = get_classes(
+ 'payment.exceptions', ['RedirectRequired', 'UnableToTakePayment', 'PaymentError'])
+UnableToPlaceOrder = get_class('order.exceptions', 'UnableToPlaceOrder')
+
+Order = get_model('order', 'Order')
+ShippingAddress = get_model('order', 'ShippingAddress')
+CommunicationEvent = get_model('order', 'CommunicationEvent')
+PaymentEventType = get_model('order', 'PaymentEventType')
+PaymentEvent = get_model('order', 'PaymentEvent')
+UserAddress = get_model('address', 'UserAddress')
+Basket = get_model('basket', 'Basket')
+Email = get_model('customer', 'Email')
+CommunicationEventType = get_model('customer', 'CommunicationEventType')
# Standard logger for checkout events
logger = logging.getLogger('oscar.checkout')
8 oscar/apps/dashboard/reports/forms.py
View
@@ -1,11 +1,11 @@
from django import forms
-from oscar.core.loading import import_module
-report_utils = import_module('dashboard.reports.utils', ['GeneratorRepository'])
+from oscar.core.loading import get_class
+GeneratorRepository = get_class('dashboard.reports.utils', 'GeneratorRepository')
+
class ReportForm(forms.Form):
-
- generators = report_utils.GeneratorRepository().get_report_generators()
+ generators = GeneratorRepository().get_report_generators()
type_choices = []
for generator in generators:
28 oscar/apps/dashboard/reports/utils.py
View
@@ -1,19 +1,21 @@
-from oscar.core.loading import import_module
-order_reports = import_module('order.reports', ['OrderReportGenerator'])
-analytics_reports = import_module('analytics.reports', ['ProductReportGenerator', 'UserReportGenerator'])
-basket_reports = import_module('basket.reports', ['OpenBasketReportGenerator', 'SubmittedBasketReportGenerator'])
-offer_reports = import_module('offer.reports', ['OfferReportGenerator'])
-voucher_reports = import_module('voucher.reports', ['VoucherReportGenerator'])
+from oscar.core.loading import get_class, get_classes
+OrderReportGenerator = get_class('order.reports', 'OrderReportGenerator')
+ProductReportGenerator, UserReportGenerator = get_classes('analytics.reports', ['ProductReportGenerator', 'UserReportGenerator'])
+OpenBasketReportGenerator, SubmittedBasketReportGenerator = get_classes(
+ 'basket.reports', ['OpenBasketReportGenerator', 'SubmittedBasketReportGenerator'])
+OfferReportGenerator = get_class('offer.reports', 'OfferReportGenerator')
+VoucherReportGenerator = get_class('voucher.reports', 'VoucherReportGenerator')
+
class GeneratorRepository(object):
- generators = [order_reports.OrderReportGenerator,
- analytics_reports.ProductReportGenerator,
- analytics_reports.UserReportGenerator,
- basket_reports.OpenBasketReportGenerator,
- basket_reports.SubmittedBasketReportGenerator,
- voucher_reports.VoucherReportGenerator,
- offer_reports.OfferReportGenerator]
+ generators = [OrderReportGenerator,
+ ProductReportGenerator,
+ UserReportGenerator,
+ OpenBasketReportGenerator,
+ SubmittedBasketReportGenerator,
+ VoucherReportGenerator,
+ OfferReportGenerator]
def get_report_generators(self):
return self.generators
7 oscar/apps/offer/admin.py
View
@@ -1,7 +1,10 @@
from django.contrib import admin
+from django.db.models import get_model
-from oscar.core.loading import import_module
-import_module('offer.models', ['ConditionalOffer', 'Condition', 'Benefit', 'Range'], locals())
+ConditionalOffer = get_model('offer', 'ConditionalOffer')
+Condition = get_model('offer', 'Condition')
+Benefit = get_model('offer', 'Benefit')
+Range = get_model('offer', 'Range')
class ConditionAdmin(admin.ModelAdmin):
8 oscar/apps/offer/reports.py
View
@@ -1,8 +1,10 @@
import csv
-from oscar.core.loading import import_module
-import_module('dashboard.reports.reports', ['ReportGenerator'], locals())
-import_module('offer.models', ['ConditionalOffer'], locals())
+from django.db.models import get_model
+
+from oscar.core.loading import get_class
+ReportGenerator = get_class('dashboard.reports.reports', 'ReportGenerator')
+ConditionalOffer = get_model('offer', 'ConditionalOffer')
class OfferReportGenerator(ReportGenerator):
4 oscar/apps/offer/utils.py
View
@@ -2,8 +2,8 @@
from itertools import chain
import logging
-from oscar.core.loading import import_module
-import_module('offer.models', ['ConditionalOffer'], locals())
+from django.db.models import get_model
+ConditionalOffer = get_model('offer', 'ConditionalOffer')
logger = logging.getLogger('oscar.offers')
11 oscar/apps/partner/admin.py
View
@@ -1,11 +1,14 @@
from django.contrib import admin
+from django.db.models import get_model
+
+Partner = get_model('partner', 'Partner')
+StockRecord = get_model('partner', 'StockRecord')
-from oscar.core.loading import import_module
-models = import_module('partner.models', ['Partner', 'StockRecord'])
class StockRecordAdmin(admin.ModelAdmin):
list_display = ('product', 'partner', 'partner_sku', 'price_excl_tax', 'cost_price', 'num_in_stock')
list_filter = ('partner',)
-admin.site.register(models.Partner)
-admin.site.register(models.StockRecord, StockRecordAdmin)
+
+admin.site.register(Partner)
+admin.site.register(StockRecord, StockRecordAdmin)
6 oscar/apps/voucher/admin.py
View
@@ -1,7 +1,8 @@
from django.contrib import admin
+from django.db.models import get_model
-from oscar.core.loading import import_module
-import_module('voucher.models', ['Voucher', 'VoucherApplication'], locals())
+Voucher = get_model('voucher', 'Voucher')
+VoucherApplication = get_model('voucher', 'VoucherApplication')
class VoucherAdmin(admin.ModelAdmin):
@@ -20,6 +21,7 @@ class VoucherAdmin(admin.ModelAdmin):
)
+
class VoucherApplicationAdmin(admin.ModelAdmin):
list_display = ('voucher', 'user', 'order', 'date_created')
readonly_fields = ('voucher', 'user', 'order')
Please sign in to comment.
Something went wrong with that request. Please try again.