Skip to content
This repository
Browse code

Cleaned up apps to not use import_module

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

0 notes on commit b27a128

Please sign in to comment.
Something went wrong with that request. Please try again.