Skip to content
This repository
Browse code

Tidy-up of a few modules

  • Loading branch information...
commit 285e4232cecec1369816f0dc0086a7c68a3f1af2 1 parent e4e5b45
David Winterbottom authored April 30, 2012
2  README.rst
Source Rendered
@@ -21,7 +21,7 @@ information:
21 21
 .. image:: https://secure.travis-ci.org/tangentlabs/django-oscar.png
22 22
 
23 23
 .. _`Official homepage`: http://tangentlabs.github.com/django-oscar/
24  
-.. _`Demo site`: http://sanbod.oscar.tangentlabs.co.uk
  24
+.. _`Demo site`: http://sandbox.oscar.tangentlabs.co.uk
25 25
 .. _`Documentation`: http://django-oscar.readthedocs.org/en/latest/
26 26
 .. _`readthedocs.org`: http://readthedocs.org
27 27
 .. _`Continuous integration homepage`: http://travis-ci.org/#!/tangentlabs/django-oscar 
14  oscar/apps/analytics/receivers.py
@@ -2,11 +2,15 @@
2 2
 from django.db import IntegrityError
3 3
 import logging
4 4
 
5  
-from oscar.core.loading import import_module
6  
-import_module('analytics.models', ['UserSearch', 'UserRecord', 'ProductRecord', 'UserProductView'], locals())
7  
-import_module('catalogue.signals', ['product_viewed', 'product_search'], locals())
8  
-import_module('basket.signals', ['basket_addition'], locals())
9  
-import_module('order.signals', ['order_placed'], locals())
  5
+from oscar.core.loading import get_class, get_classes
  6
+UserSearch, UserRecord, ProductRecord, UserProductView = get_classes(
  7
+    'analytics.models', ['UserSearch', 'UserRecord', 'ProductRecord',
  8
+                         'UserProductView'])
  9
+product_viewed, product_search = get_classes('catalogue.signals',
  10
+                                             ['product_viewed',
  11
+                                              'product_search'])
  12
+basket_addition = get_class('basket.signals', 'basket_addition')
  13
+order_placed = get_class('order.signals', 'order_placed')
10 14
 
11 15
 # Helpers
12 16
 
18  oscar/apps/analytics/reports.py
... ...
@@ -1,11 +1,15 @@
1 1
 import csv
2 2
 
3  
-from oscar.core.loading import import_module
4  
-report_classes = import_module('dashboard.reports.reports', ['ReportGenerator'])
5  
-analytics_models = import_module('analytics.models', ['ProductRecord', 'UserRecord'])
  3
+from django.db.models import get_model
6 4
 
  5
+from oscar.core.loading import get_class
7 6
 
8  
-class ProductReportGenerator(report_classes.ReportGenerator):
  7
+ReportGenerator = get_class('dashboard.reports.reports', 'ReportGenerator')
  8
+ProductRecord = get_model('analytics', 'ProductRecord')
  9
+UserRecord = get_model('analytics', 'UserRecord')
  10
+
  11
+
  12
+class ProductReportGenerator(ReportGenerator):
9 13
     
10 14
     filename_template = 'product-analytics.csv'
11 15
     code = 'product_analytics'
@@ -19,7 +23,7 @@ def generate(self, response):
19 23
                       'Purchases',]
20 24
         writer.writerow(header_row)
21 25
         
22  
-        records = analytics_models.ProductRecord._default_manager.all()
  26
+        records = ProductRecord._default_manager.all()
23 27
         for record in records:
24 28
             row = [record.product, record.num_views, record.num_basket_additions, record.num_purchases]
25 29
             writer.writerow(row)
@@ -31,7 +35,7 @@ def filename(self):
31 35
         return self.filename_template
32 36
     
33 37
 
34  
-class UserReportGenerator(report_classes.ReportGenerator):
  38
+class UserReportGenerator(ReportGenerator):
35 39
     
36 40
     filename_template = 'user-analytics.csv'
37 41
     code = 'user_analytics'
@@ -52,7 +56,7 @@ def generate(self, response):
52 56
                       ]
53 57
         writer.writerow(header_row)
54 58
         
55  
-        records = analytics_models.UserRecord._default_manager.select_related().all()
  59
+        records = UserRecord._default_manager.select_related().all()
56 60
         for record in records:
57 61
             row = [record.user.username, record.user.get_full_name(), record.user.date_joined, 
58 62
                    record.num_product_views, record.num_basket_additions, record.num_orders,
6  oscar/apps/analytics/utils.py
... ...
@@ -1,8 +1,8 @@
1 1
 from django.db import connection, transaction
  2
+from django.db.models import get_model
2 3
 
3  
-from oscar.core.loading import import_module
4  
-import_module('analytics.models', ['ProductRecord'], locals())
5  
-import_module('catalogue.models', ['Product'], locals())
  4
+ProductRecord = get_model('analytics', 'ProductRecord')
  5
+Product = get_model('catalogue', 'Product')
6 6
 
7 7
 
8 8
 class ScoreCalculator(object):
50  oscar/apps/catalogue/admin.py
... ...
@@ -1,20 +1,30 @@
1 1
 from django.contrib import admin
  2
+from django.db.models import get_model
  3
+
  4
+Product = get_model('catalogue', 'Product')
  5
+ProductClass = get_model('catalogue', 'ProductClass')
  6
+ProductAttribute = get_model('catalogue', 'ProductAttribute')
  7
+ProductAttributeValue = get_model('catalogue', 'ProductAttributeValue')
  8
+Option = get_model('catalogue', 'Option')
  9
+ProductRecommendation = get_model('catalogue', 'ProductRecommendation')
  10
+AttributeOption = get_model('catalogue', 'AttributeOption')
  11
+AttributeOptionGroup = get_model('catalogue', 'AttributeOptionGroup')
  12
+AttributeEntity = get_model('catalogue', 'AttributeEntity')
  13
+AttributeEntityType = get_model('catalogue', 'AttributeEntityType')
  14
+ProductImage = get_model('catalogue', 'ProductImage')
  15
+Category = get_model('catalogue', 'Category')
  16
+ProductCategory = get_model('catalogue', 'ProductCategory')
2 17
 
3  
-from oscar.core.loading import import_module
4  
-product_models = import_module('catalogue.models', ['Product', 'ProductClass', 'ProductAttribute', 'ProductAttributeValue', 
5  
-                                                    'Option', 'ProductRecommendation', 'AttributeOption', 'AttributeOptionGroup',
6  
-                                                    'AttributeEntity', 'AttributeEntityType', 'ProductImage', 'Category', 
7  
-                                                    'ProductCategory'])
8 18
 
9 19
 class AttributeInline(admin.TabularInline):
10  
-    model = product_models.ProductAttributeValue
  20
+    model = ProductAttributeValue
11 21
 
12 22
 class ProductRecommendationInline(admin.TabularInline):
13  
-    model = product_models.ProductRecommendation
  23
+    model = ProductRecommendation
14 24
     fk_name = 'primary'
15 25
     
16 26
 class CategoryInline(admin.TabularInline):
17  
-    model = product_models.ProductCategory
  27
+    model = ProductCategory
18 28
     extra = 1
19 29
 
20 30
 class ProductClassAdmin(admin.ModelAdmin):
@@ -35,7 +45,7 @@ class ProductAttributeValueAdmin(admin.ModelAdmin):
35 45
     list_display = ('product', 'attribute', 'value')
36 46
 
37 47
 class AttributeOptionInline(admin.TabularInline):
38  
-    model = product_models.AttributeOption
  48
+    model = AttributeOption
39 49
     
40 50
 class AttributeOptionGroupAdmin(admin.ModelAdmin):
41 51
     inlines = [AttributeOptionInline, ]
@@ -44,14 +54,14 @@ class AttributeEntityAdmin(admin.ModelAdmin):
44 54
     list_display = ('name', )
45 55
                  
46 56
 
47  
-admin.site.register(product_models.ProductClass, ProductClassAdmin)
48  
-admin.site.register(product_models.Product, ProductAdmin)
49  
-admin.site.register(product_models.ProductAttribute, ProductAttributeAdmin)
50  
-admin.site.register(product_models.ProductAttributeValue, ProductAttributeValueAdmin)
51  
-admin.site.register(product_models.AttributeOptionGroup, AttributeOptionGroupAdmin)
52  
-admin.site.register(product_models.AttributeEntity, AttributeEntityAdmin)
53  
-admin.site.register(product_models.AttributeEntityType)
54  
-admin.site.register(product_models.Option, OptionAdmin)
55  
-admin.site.register(product_models.ProductImage)
56  
-admin.site.register(product_models.Category)
57  
-admin.site.register(product_models.ProductCategory)
  57
+admin.site.register(ProductClass, ProductClassAdmin)
  58
+admin.site.register(Product, ProductAdmin)
  59
+admin.site.register(ProductAttribute, ProductAttributeAdmin)
  60
+admin.site.register(ProductAttributeValue, ProductAttributeValueAdmin)
  61
+admin.site.register(AttributeOptionGroup, AttributeOptionGroupAdmin)
  62
+admin.site.register(AttributeEntity, AttributeEntityAdmin)
  63
+admin.site.register(AttributeEntityType)
  64
+admin.site.register(Option, OptionAdmin)
  65
+admin.site.register(ProductImage)
  66
+admin.site.register(Category)
  67
+admin.site.register(ProductCategory)
3  oscar/apps/catalogue/utils.py
@@ -10,8 +10,7 @@
10 10
 from django.core.exceptions import FieldError
11 11
 from django.db.models import get_model
12 12
 
13  
-from oscar.core.loading import import_module
14  
-import_module('catalogue.exceptions', ['ImageImportError', 'IdenticalImageError', 'InvalidImageArchive'], locals())
  13
+from oscar.apps.catalogue.exceptions import ImageImportError, IdenticalImageError, InvalidImageArchive
15 14
 
16 15
 Category = get_model('catalogue', 'category')
17 16
 Product = get_model('catalogue', 'product')
8  oscar/apps/customer/admin.py
... ...
@@ -1,9 +1,9 @@
1 1
 from django.contrib import admin
  2
+from django.db.models import get_model
  3
+
  4
+CommunicationEventType = get_model('customer', 'CommunicationEventType')
  5
+Email = get_model('customer', 'Email')
2 6
 
3  
-from oscar.core.loading import import_module
4  
-import_module('customer.models', ['Email', 'CommunicationEventType'], locals())
5 7
 
6 8
 admin.site.register(Email)
7 9
 admin.site.register(CommunicationEventType)
8  
-
9  
-
5  oscar/apps/customer/history_helpers.py
@@ -3,8 +3,9 @@
3 3
 from django.dispatch import receiver
4 4
 from django.conf import settings
5 5
 
6  
-from oscar.core.loading import import_module
7  
-import_module('catalogue.signals', ['product_viewed'], locals())
  6
+from oscar.core.loading import get_class
  7
+
  8
+product_viewed = get_class('catalogue.signals', 'product_viewed')
8 9
 
9 10
 MAX_PRODUCTS = settings.OSCAR_RECENTLY_VIEWED_PRODUCTS
10 11
 
6  oscar/apps/customer/utils.py
@@ -2,10 +2,10 @@
2 2
 
3 3
 from django.core.mail import EmailMessage, EmailMultiAlternatives
4 4
 from django.conf import settings
  5
+from django.db.models import get_model
5 6
 
6  
-from oscar.core.loading import import_module
7  
-import_module('order.models', ['CommunicationEvent',], locals())
8  
-import_module('customer.models', ['Email'], locals())
  7
+CommunicationEvent = get_model('order', 'CommunicationEvent')
  8
+Email = get_model('customer', 'Email')
9 9
 
10 10
 
11 11
 class Dispatcher(object):
48  oscar/apps/customer/views.py
@@ -14,20 +14,20 @@
14 14
 from django.db.models import get_model
15 15
 
16 16
 from oscar.views.generic import PostActionMixin
17  
-from oscar.apps.customer.forms import EmailAuthenticationForm, EmailUserCreationForm, SearchByDateRangeForm
18  
-from oscar.core.loading import import_module, get_class, get_profile_class
19  
-import_module('customer.utils', ['Dispatcher'], locals())
20  
-
  17
+from oscar.core.loading import get_class, get_profile_class, get_classes
  18
+Dispatcher = get_class('customer.utils', 'Dispatcher')
  19
+EmailAuthenticationForm, EmailUserCreationForm, SearchByDateRangeForm = get_classes(
  20
+    'customer.forms', ['EmailAuthenticationForm', 'EmailUserCreationForm',
  21
+                       'SearchByDateRangeForm'])
21 22
 ProfileForm = get_class('customer.forms', 'ProfileForm')
22 23
 UserAddressForm = get_class('address.forms', 'UserAddressForm')
23  
-
24  
-order_model = get_model('order', 'Order')
25  
-order_line_model = get_model('order', 'Line')
26  
-basket_model = get_model('basket', 'Basket')
27  
-user_address_model = get_model('address', 'UserAddress')
  24
+Order = get_model('order', 'Order')
  25
+Line = get_model('order', 'Line')
  26
+Basket = get_model('basket', 'Basket')
  27
+UserAddress = get_model('address', 'UserAddress')
28 28
 Email = get_model('customer', 'email')
29 29
 UserAddress = get_model('address', 'UserAddress')
30  
-communicationtype_model = get_model('customer', 'communicationeventtype')
  30
+CommunicationEventType = get_model('customer', 'communicationeventtype')
31 31
 
32 32
 
33 33
 class ProfileUpdateView(FormView):
@@ -55,7 +55,7 @@ class AccountSummaryView(ListView):
55 55
     context_object_name = "orders"
56 56
     template_name = 'customer/profile.html'
57 57
     paginate_by = 20
58  
-    model = order_model
  58
+    model = Order
59 59
 
60 60
     def get_queryset(self):
61 61
         return self.model._default_manager.filter(user=self.request.user)[0:5]
@@ -138,10 +138,10 @@ def send_registration_email(self, user):
138 138
         ctx = {'user': user,
139 139
                'site': get_current_site(self.request)}
140 140
         try:
141  
-            event_type = communicationtype_model.objects.get(code=code)
142  
-        except communicationtype_model.DoesNotExist:
  141
+            event_type = CommunicationEventType.objects.get(code=code)
  142
+        except CommunicationEventType.DoesNotExist:
143 143
             # No event in database, attempt to find templates for this type
144  
-            messages = communicationtype_model.objects.get_and_render(code, ctx)
  144
+            messages = CommunicationEventType.objects.get_and_render(code, ctx)
145 145
         else:
146 146
             # Create order event
147 147
             messages = event_type.get_messages(ctx)
@@ -219,7 +219,7 @@ class OrderHistoryView(ListView):
219 219
     context_object_name = "orders"
220 220
     template_name = 'customer/order-history.html'
221 221
     paginate_by = 20
222  
-    model = order_model
  222
+    model = Order
223 223
     form_class = SearchByDateRangeForm
224 224
 
225 225
     def get(self, request, *args, **kwargs):
@@ -246,7 +246,7 @@ def get_context_data(self, *args, **kwargs):
246 246
 
247 247
 class OrderDetailView(DetailView, PostActionMixin):
248 248
     """Customer order details"""
249  
-    model = order_model
  249
+    model = Order
250 250
 
251 251
     def get_template_names(self):
252 252
         return ["customer/order.html"]
@@ -276,7 +276,7 @@ class OrderLineView(DetailView, PostActionMixin):
276 276
 
277 277
     def get_object(self):
278 278
         """Return an order object or 404"""
279  
-        order = get_object_or_404(order_model, user=self.request.user, number=self.kwargs['order_number'])
  279
+        order = get_object_or_404(Order, user=self.request.user, number=self.kwargs['order_number'])
280 280
         return order.lines.get(id=self.kwargs['line_id'])
281 281
 
282 282
     def do_reorder(self, line):
@@ -306,12 +306,12 @@ class AddressListView(ListView):
306 306
 
307 307
     def get_queryset(self):
308 308
         """Return a customer's addresses"""
309  
-        return user_address_model._default_manager.filter(user=self.request.user)
  309
+        return UserAddress._default_manager.filter(user=self.request.user)
310 310
 
311 311
 
312 312
 class AddressCreateView(CreateView):
313 313
     form_class = UserAddressForm
314  
-    mode = user_address_model
  314
+    mode = UserAddress
315 315
     template_name = 'customer/address-form.html'
316 316
 
317 317
     def get_context_data(self, **kwargs):
@@ -332,7 +332,7 @@ def get_success_url(self):
332 332
 
333 333
 class AddressUpdateView(UpdateView):
334 334
     form_class = UserAddressForm
335  
-    model = user_address_model
  335
+    model = UserAddress
336 336
     template_name = 'customer/address-form.html'
337 337
 
338 338
     def get_context_data(self, **kwargs):
@@ -341,7 +341,7 @@ def get_context_data(self, **kwargs):
341 341
         return ctx
342 342
 
343 343
     def get_queryset(self):
344  
-        return user_address_model._default_manager.filter(user=self.request.user)
  344
+        return UserAddress._default_manager.filter(user=self.request.user)
345 345
 
346 346
     def get_success_url(self):
347 347
         messages.success(self.request, _("Address saved"))
@@ -349,11 +349,11 @@ def get_success_url(self):
349 349
 
350 350
 
351 351
 class AddressDeleteView(DeleteView):
352  
-    model = user_address_model
  352
+    model = UserAddress
353 353
 
354 354
     def get_queryset(self):
355 355
         """Return a customer's addresses"""
356  
-        return user_address_model._default_manager.filter(user=self.request.user)
  356
+        return UserAddress._default_manager.filter(user=self.request.user)
357 357
 
358 358
     def get_success_url(self):
359 359
         return reverse('customer:address-list')
@@ -364,7 +364,7 @@ def get_template_names(self):
364 364
 
365 365
 class AnonymousOrderDetailView(DetailView):
366 366
 
367  
-    model = order_model
  367
+    model = Order
368 368
 
369 369
     def get_template_names(self):
370 370
         return ["customer/anon-order.html"]

0 notes on commit 285e423

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