Просмотр исходного кода

Yey, another massive set of docstrings even if David says I'm not important. =P

master
Kura 15 лет назад
Родитель
Сommit
048673f8e6

+ 4
- 0
docs/source/conf.py Просмотреть файл

214
     ('index', 'django-oscar', u'django-oscar Documentation',
214
     ('index', 'django-oscar', u'django-oscar Documentation',
215
      [u'David Winterbottom'], 1)
215
      [u'David Winterbottom'], 1)
216
 ]
216
 ]
217
+
218
+from django-oscar import settings
219
+from django.core.management import setup_environ
220
+setup_environ(settings)

+ 7
- 5
oscar/address/abstract_models.py Просмотреть файл

10
 class AbstractAddress(models.Model):
10
 class AbstractAddress(models.Model):
11
     u"""
11
     u"""
12
     Superclass address object
12
     Superclass address object
13
-    
13
+
14
     This is subclassed and extended to provide models for 
14
     This is subclassed and extended to provide models for 
15
     user, shipping and billing addresses.
15
     user, shipping and billing addresses.
16
-    
16
+
17
     The only required fields are last_name, line1 and postcode.
17
     The only required fields are last_name, line1 and postcode.
18
     """
18
     """
19
     # @todo: Need a way of making these choice lists configurable 
19
     # @todo: Need a way of making these choice lists configurable 
38
     
38
     
39
     class Meta:
39
     class Meta:
40
         abstract = True
40
         abstract = True
41
-        
41
+
42
     def save(self, *args, **kwargs):
42
     def save(self, *args, **kwargs):
43
+        u"""Clean fields and save"""
43
         self._clean_fields()
44
         self._clean_fields()
44
-        super(AbstractAddress, self).save(*args, **kwargs)    
45
+        super(AbstractAddress, self).save(*args, **kwargs)
45
         
46
         
46
     def _clean_fields(self):
47
     def _clean_fields(self):
47
         u"""Clean up fields"""
48
         u"""Clean up fields"""
51
         
52
         
52
         # Ensure postcodes are always uppercase
53
         # Ensure postcodes are always uppercase
53
         if self.postcode:
54
         if self.postcode:
54
-            self.postcode = self.postcode.upper()    
55
+            self.postcode = self.postcode.upper()
55
         
56
         
56
     @property    
57
     @property    
57
     def summary(self):
58
     def summary(self):
154
         return zlib.crc32(self.summary.strip().upper())
155
         return zlib.crc32(self.summary.strip().upper())
155
 
156
 
156
     def save(self, *args, **kwargs):
157
     def save(self, *args, **kwargs):
158
+        u"""Save a hash of the address fields"""
157
         # Save a hash of the address fields so we can check whether two 
159
         # Save a hash of the address fields so we can check whether two 
158
         # addresses are the same to avoid saving duplicates
160
         # addresses are the same to avoid saving duplicates
159
         self.hash = self.generate_hash()
161
         self.hash = self.generate_hash()

+ 15
- 1
oscar/basket/abstract_models.py Просмотреть файл

124
     
124
     
125
     @property
125
     @property
126
     def is_empty(self):
126
     def is_empty(self):
127
+        u"""Return bool based on basket having 0 lines"""
127
         return self.num_lines == 0
128
         return self.num_lines == 0
128
     
129
     
129
     @property
130
     @property
130
     def total_excl_tax(self):
131
     def total_excl_tax(self):
132
+        u"""Return total line price excluding tax"""
131
         return self._get_total('line_price_excl_tax')
133
         return self._get_total('line_price_excl_tax')
132
     
134
     
133
     @property
135
     @property
134
     def total_tax(self):
136
     def total_tax(self):
137
+        u"""Return total tax for a line"""
135
         return self._get_total('line_tax')
138
         return self._get_total('line_tax')
136
     
139
     
137
     @property
140
     @property
138
     def total_incl_tax(self):
141
     def total_incl_tax(self):
142
+        u"""Return total price for a line including tax"""
139
         return self._get_total('line_price_incl_tax')
143
         return self._get_total('line_price_incl_tax')
140
     
144
     
141
     @property
145
     @property
142
     def num_lines(self):
146
     def num_lines(self):
147
+        u"""Return number of lines"""
143
         return self.lines.all().count()
148
         return self.lines.all().count()
144
     
149
     
145
     @property
150
     @property
146
     def num_items(self):
151
     def num_items(self):
152
+        u"""Return number of items"""
147
         return reduce(lambda num,line: num+line.quantity, self.lines.all(), 0)
153
         return reduce(lambda num,line: num+line.quantity, self.lines.all(), 0)
148
     
154
     
149
     
155
     
166
         return u"%s, Product '%s', quantity %d" % (self.basket, self.product, self.quantity)
172
         return u"%s, Product '%s', quantity %d" % (self.basket, self.product, self.quantity)
167
     
173
     
168
     def save(self, *args, **kwargs):
174
     def save(self, *args, **kwargs):
175
+        u"""Saves a line or deletes if it's quanity is 0"""
169
         if self.quantity == 0:
176
         if self.quantity == 0:
170
             return self.delete(*args, **kwargs)
177
             return self.delete(*args, **kwargs)
171
         super(AbstractLine, self).save(*args, **kwargs)
178
         super(AbstractLine, self).save(*args, **kwargs)
186
     
193
     
187
     @property
194
     @property
188
     def unit_price_excl_tax(self):
195
     def unit_price_excl_tax(self):
196
+        u"""Return unit price excluding tax"""
189
         return self._get_stockrecord_property('price_excl_tax')
197
         return self._get_stockrecord_property('price_excl_tax')
190
     
198
     
191
     @property
199
     @property
192
     def unit_tax(self):
200
     def unit_tax(self):
201
+        u"""Return tax of a unit"""
193
         return self._get_stockrecord_property('price_tax')
202
         return self._get_stockrecord_property('price_tax')
194
     
203
     
195
     @property
204
     @property
196
     def unit_price_incl_tax(self):
205
     def unit_price_incl_tax(self):
206
+        u"""Return unit price including tax"""
197
         return self._get_stockrecord_property('price_incl_tax')
207
         return self._get_stockrecord_property('price_incl_tax')
198
     
208
     
199
     @property
209
     @property
200
     def line_price_excl_tax(self):
210
     def line_price_excl_tax(self):
201
-       return self.quantity * self.unit_price_excl_tax
211
+        u"""Return line price excluding tax"""
212
+        return self.quantity * self.unit_price_excl_tax
202
        
213
        
203
     @property    
214
     @property    
204
     def line_tax(self):
215
     def line_tax(self):
216
+        u"""Return line tax"""
205
         return self.quantity * self.unit_tax
217
         return self.quantity * self.unit_tax
206
     
218
     
207
     @property
219
     @property
208
     def line_price_incl_tax(self):
220
     def line_price_incl_tax(self):
221
+        u"""Return line price including tax"""
209
         return self.quantity * self.unit_price_incl_tax
222
         return self.quantity * self.unit_price_incl_tax
210
     
223
     
211
     @property
224
     @property
212
     def description(self):
225
     def description(self):
226
+        u"""Return product description"""
213
         d = str(self.product)
227
         d = str(self.product)
214
         ops = []
228
         ops = []
215
         for attribute in self.attributes.all():
229
         for attribute in self.attributes.all():

+ 2
- 0
oscar/checkout/calculators.py Просмотреть файл

11
         self.request = request
11
         self.request = request
12
     
12
     
13
     def order_total_incl_tax(self, basket, shipping_method=None):
13
     def order_total_incl_tax(self, basket, shipping_method=None):
14
+        u"""Return order total including tax"""
14
         # Default to returning the total including tax - use
15
         # Default to returning the total including tax - use
15
         # the request.user object if you want to not charge tax
16
         # the request.user object if you want to not charge tax
16
         # to particular customers.  
17
         # to particular customers.  
20
         return total
21
         return total
21
     
22
     
22
     def order_total_excl_tax(self, basket, shipping_method=None):
23
     def order_total_excl_tax(self, basket, shipping_method=None):
24
+        u"""Return order total excluding tax"""
23
         total = basket.total_excl_tax
25
         total = basket.total_excl_tax
24
         if shipping_method:
26
         if shipping_method:
25
             total += shipping_method.basket_charge_excl_tax()
27
             total += shipping_method.basket_charge_excl_tax()

+ 1
- 0
oscar/checkout/signals.py Просмотреть файл

4
 
4
 
5
 @receiver(order_placed)
5
 @receiver(order_placed)
6
 def update_stock_levels(sender, **kwargs):
6
 def update_stock_levels(sender, **kwargs):
7
+    u"""Updated a line item's stock level"""
7
     order = kwargs['order']
8
     order = kwargs['order']
8
     for line in order.lines.all():
9
     for line in order.lines.all():
9
         sr = line.product.stockrecord
10
         sr = line.product.stockrecord

+ 11
- 1
oscar/checkout/utils.py Просмотреть файл

65
         """
65
         """
66
         request.session['checkout_complete_steps'] = []
66
         request.session['checkout_complete_steps'] = []
67
         
67
         
68
-    def _get_url_name(self, request):    
68
+    def _get_url_name(self, request):
69
         return resolve(request.path).url_name
69
         return resolve(request.path).url_name
70
         
70
         
71
     def _get_completed_steps(self, request):
71
     def _get_completed_steps(self, request):
87
             self.request.session[self.SESSION_KEY][namespace] = {}
87
             self.request.session[self.SESSION_KEY][namespace] = {}
88
           
88
           
89
     def _get(self, namespace, key):
89
     def _get(self, namespace, key):
90
+        u"""Return session value or None"""
90
         self._check_namespace(namespace)
91
         self._check_namespace(namespace)
91
         if key in self.request.session[self.SESSION_KEY][namespace]:
92
         if key in self.request.session[self.SESSION_KEY][namespace]:
92
             return self.request.session[self.SESSION_KEY][namespace][key]
93
             return self.request.session[self.SESSION_KEY][namespace][key]
93
         return None
94
         return None
94
             
95
             
95
     def _set(self, namespace, key, value):
96
     def _set(self, namespace, key, value):
97
+        u"""Set session value"""
96
         self._check_namespace(namespace)
98
         self._check_namespace(namespace)
97
         self.request.session[self.SESSION_KEY][namespace][key] = value
99
         self.request.session[self.SESSION_KEY][namespace][key] = value
98
         self.request.session.modified = True
100
         self.request.session.modified = True
99
         
101
         
100
     def _unset(self, namespace, key):
102
     def _unset(self, namespace, key):
103
+        u"""Unset session value"""
101
         self._check_namespace(namespace)
104
         self._check_namespace(namespace)
102
         if key in self.request.session[self.SESSION_KEY][namespace]:
105
         if key in self.request.session[self.SESSION_KEY][namespace]:
103
             del self.request.session[self.SESSION_KEY][namespace][key]
106
             del self.request.session[self.SESSION_KEY][namespace][key]
104
             self.request.session.modified = True
107
             self.request.session.modified = True
105
             
108
             
106
     def flush(self):
109
     def flush(self):
110
+        u"""Delete session key"""
107
         self.request.session[self.SESSION_KEY] = {}
111
         self.request.session[self.SESSION_KEY] = {}
108
         
112
         
109
     # Shipping methods    
113
     # Shipping methods    
110
         
114
         
111
     def ship_to_user_address(self, address):
115
     def ship_to_user_address(self, address):
116
+        u"""Set existing shipping address id to session and unset address fields from session"""
112
         self._set('shipping', 'user_address_id', address.id)
117
         self._set('shipping', 'user_address_id', address.id)
113
         self._unset('shipping', 'new_address_fields')
118
         self._unset('shipping', 'new_address_fields')
114
         
119
         
115
     def ship_to_new_address(self, address_fields):
120
     def ship_to_new_address(self, address_fields):
121
+        u"""Set new shipping address details to session and unset shipping address id"""
116
         self._set('shipping', 'new_address_fields', address_fields)
122
         self._set('shipping', 'new_address_fields', address_fields)
117
         self._unset('shipping', 'user_address_id')
123
         self._unset('shipping', 'user_address_id')
118
         
124
         
119
     def new_address_fields(self):
125
     def new_address_fields(self):
126
+        u"""Get shipping address fields from session"""
120
         return self._get('shipping', 'new_address_fields')
127
         return self._get('shipping', 'new_address_fields')
121
         
128
         
122
     def user_address_id(self):
129
     def user_address_id(self):
130
+        u"""Get user address id from session"""
123
         return self._get('shipping', 'user_address_id')
131
         return self._get('shipping', 'user_address_id')
124
     
132
     
125
     def use_free_shipping(self):
133
     def use_free_shipping(self):
134
+        u"""Set "free shipping" code to session"""
126
         self._set('shipping', 'method_code', '__free__')
135
         self._set('shipping', 'method_code', '__free__')
127
     
136
     
128
     def use_shipping_method(self, code):
137
     def use_shipping_method(self, code):
138
+        u"""Set shipping method code to session"""
129
         self._set('shipping', 'method_code', code)
139
         self._set('shipping', 'method_code', code)
130
         
140
         
131
     def shipping_method(self):
141
     def shipping_method(self):

+ 1
- 1
oscar/checkout/views.py Просмотреть файл

199
         return render(self.request, self.template_file, locals())
199
         return render(self.request, self.template_file, locals())
200
     
200
     
201
     def get_shipping_methods_for_basket(self, basket):
201
     def get_shipping_methods_for_basket(self, basket):
202
+        u"""Return available shipping methods for a basket"""
202
         return shipping_models.Method.objects.all()
203
         return shipping_models.Method.objects.all()
203
     
204
     
204
     def handle_POST(self):
205
     def handle_POST(self):
300
     
301
     
301
     def _place_order(self, basket):
302
     def _place_order(self, basket):
302
         u"""Writes the order out to the DB"""
303
         u"""Writes the order out to the DB"""
303
-        
304
         calc = checkout_calculators.OrderTotalCalculator(self.request)
304
         calc = checkout_calculators.OrderTotalCalculator(self.request)
305
         shipping_address = self._get_shipping_address()
305
         shipping_address = self._get_shipping_address()
306
         shipping_method = self._get_shipping_method(basket)
306
         shipping_method = self._get_shipping_method(basket)

+ 11
- 0
oscar/customer/views.py Просмотреть файл

12
 
12
 
13
 @login_required
13
 @login_required
14
 def profile(request):
14
 def profile(request):
15
+    u"""Return a customers's profile"""
15
     # Load last 5 orders as preview
16
     # Load last 5 orders as preview
16
     orders = order_models.Order.objects.filter(user=request.user)[0:5]
17
     orders = order_models.Order.objects.filter(user=request.user)[0:5]
17
     return render(request, 'customer/profile.html', locals())
18
     return render(request, 'customer/profile.html', locals())
18
     
19
     
19
         
20
         
20
 class OrderHistoryView(ListView):
21
 class OrderHistoryView(ListView):
22
+    u"""Customer order history"""
21
     context_object_name = "orders"
23
     context_object_name = "orders"
22
     template_name = 'customer/order-history.html'
24
     template_name = 'customer/order-history.html'
23
     paginate_by = 20
25
     paginate_by = 20
24
 
26
 
25
     def get_queryset(self):
27
     def get_queryset(self):
28
+        u"""Return a customer's orders"""
26
         return order_models.Order.objects.filter(user=self.request.user)
29
         return order_models.Order.objects.filter(user=self.request.user)
27
 
30
 
28
 
31
 
29
 class OrderDetailView(ModelView):
32
 class OrderDetailView(ModelView):
33
+    u"""Customer order details"""
30
     template_file = "customer/order.html"
34
     template_file = "customer/order.html"
31
     
35
     
32
     def get_model(self):
36
     def get_model(self):
37
+        u"""Return an order object or 404"""
33
         return get_object_or_404(order_models.Order, user=self.request.user, number=self.kwargs['order_number'])
38
         return get_object_or_404(order_models.Order, user=self.request.user, number=self.kwargs['order_number'])
34
     
39
     
35
     def handle_GET(self, order):
40
     def handle_GET(self, order):
37
         
42
         
38
 
43
 
39
 class AddressBookView(ListView):
44
 class AddressBookView(ListView):
45
+    u"""Customer address book"""
40
     context_object_name = "addresses"
46
     context_object_name = "addresses"
41
     template_name = 'customer/address-book.html'
47
     template_name = 'customer/address-book.html'
42
     paginate_by = 40
48
     paginate_by = 40
43
         
49
         
44
     def get_queryset(self):
50
     def get_queryset(self):
51
+        u"""Return a customer's addresses"""
45
         return address_models.UserAddress.objects.filter(user=self.request.user)
52
         return address_models.UserAddress.objects.filter(user=self.request.user)
46
     
53
     
47
     
54
     
48
 class AddressView(ModelView):
55
 class AddressView(ModelView):
56
+    u"""Customer address view"""
49
     template_file = "customer/address-form.html"
57
     template_file = "customer/address-form.html"
50
     
58
     
51
     def get_model(self):
59
     def get_model(self):
60
+        u"""Return an address object or a 404"""
52
         return get_object_or_404(address_models.UserAddress, user=self.request.user, pk=self.kwargs['address_id'])
61
         return get_object_or_404(address_models.UserAddress, user=self.request.user, pk=self.kwargs['address_id'])
53
     
62
     
54
     def handle_GET(self, address):
63
     def handle_GET(self, address):
56
         self.response = render(self.request, self.template_file, locals())
65
         self.response = render(self.request, self.template_file, locals())
57
         
66
         
58
     def do_save(self, address):
67
     def do_save(self, address):
68
+        u"""Save an address"""
59
         form = UserAddressForm(self.request.POST, instance=address)
69
         form = UserAddressForm(self.request.POST, instance=address)
60
         if form.is_valid():
70
         if form.is_valid():
61
             a = form.save()
71
             a = form.save()
64
             self.response = render(self.request, self.template_file, locals())
74
             self.response = render(self.request, self.template_file, locals())
65
             
75
             
66
     def do_delete(self, address):
76
     def do_delete(self, address):
77
+        u"""Delete an address"""
67
         address.delete()
78
         address.delete()
68
         self.response = HttpResponseRedirect(reverse('oscar-customer-address-book'))
79
         self.response = HttpResponseRedirect(reverse('oscar-customer-address-book'))
69
             
80
             

+ 1
- 0
oscar/image/abstract_models.py Просмотреть файл

17
     date_created = models.DateTimeField(auto_now_add=True)
17
     date_created = models.DateTimeField(auto_now_add=True)
18
     
18
     
19
     def is_primary(self):
19
     def is_primary(self):
20
+        u"""Return bool if image display order is 0"""
20
         return self.display_order == 0
21
         return self.display_order == 0
21
     
22
     
22
     class Meta:
23
     class Meta:

+ 22
- 42
oscar/order/abstract_models.py Просмотреть файл

5
 from django.db.models import Sum
5
 from django.db.models import Sum
6
 
6
 
7
 class AbstractOrder(models.Model):
7
 class AbstractOrder(models.Model):
8
-    """
9
-    An order
10
-    """
8
+    u"""An order"""
11
     number = models.CharField(_("Order number"), max_length=128, db_index=True)
9
     number = models.CharField(_("Order number"), max_length=128, db_index=True)
12
     # We track the site that each order is placed within
10
     # We track the site that each order is placed within
13
     site = models.ForeignKey('sites.Site')
11
     site = models.ForeignKey('sites.Site')
32
     
30
     
33
     @property
31
     @property
34
     def basket_total_incl_tax(self):
32
     def basket_total_incl_tax(self):
33
+        u"""Return basket total including tax"""
35
         return self.total_incl_tax - self.shipping_incl_tax
34
         return self.total_incl_tax - self.shipping_incl_tax
36
     
35
     
37
     @property
36
     @property
38
     def basket_total_excl_tax(self):
37
     def basket_total_excl_tax(self):
38
+        u"""Return basket total excluding tax"""
39
         return self.total_excl_tax - self.shipping_excl_tax
39
         return self.total_excl_tax - self.shipping_excl_tax
40
     
40
     
41
     class Meta:
41
     class Meta:
52
 
52
 
53
 
53
 
54
 class AbstractOrderNote(models.Model):
54
 class AbstractOrderNote(models.Model):
55
-    """
56
-    A note against an order.
57
-    """
55
+    u"""A note against an order."""
58
     order = models.ForeignKey('order.Order', related_name="notes")
56
     order = models.ForeignKey('order.Order', related_name="notes")
59
     user = models.ForeignKey('auth.User')
57
     user = models.ForeignKey('auth.User')
60
     message = models.TextField()
58
     message = models.TextField()
68
 
66
 
69
 
67
 
70
 class AbstractCommunicationEvent(models.Model):
68
 class AbstractCommunicationEvent(models.Model):
71
-    """
69
+    u"""
72
     An order-level event involving a communication to the customer, such
70
     An order-level event involving a communication to the customer, such
73
-    as an confirmation email being sent.
74
-    """
71
+    as an confirmation email being sent."""
75
     order = models.ForeignKey('order.Order', related_name="events")
72
     order = models.ForeignKey('order.Order', related_name="events")
76
     type = models.ForeignKey('order.CommunicationEventType')
73
     type = models.ForeignKey('order.CommunicationEventType')
77
     date = models.DateTimeField(auto_now_add=True)
74
     date = models.DateTimeField(auto_now_add=True)
81
     
78
     
82
     
79
     
83
 class AbstractCommunicationEventType(models.Model):
80
 class AbstractCommunicationEventType(models.Model):
84
-    """ 
85
-    Communication events are things like 'OrderConfirmationEmailSent'
86
-    """
81
+    u"""Communication events are things like 'OrderConfirmationEmailSent'"""
87
     # Code is used in forms
82
     # Code is used in forms
88
     code = models.CharField(max_length=128)
83
     code = models.CharField(max_length=128)
89
     # Name is the friendly description of an event
84
     # Name is the friendly description of an event
103
     
98
     
104
 
99
 
105
 class AbstractBatch(models.Model):
100
 class AbstractBatch(models.Model):
106
-    """
101
+    u"""
107
     A batch of items from a single fulfillment partner
102
     A batch of items from a single fulfillment partner
108
     
103
     
109
     This is a set of order lines which are fulfilled by a single partner
104
     This is a set of order lines which are fulfilled by a single partner
123
         
118
         
124
         
119
         
125
 class AbstractBatchLine(models.Model):
120
 class AbstractBatchLine(models.Model):
126
-    """
121
+    u"""
127
     A line within a batch.
122
     A line within a batch.
128
     
123
     
129
     Not using a line model as it's difficult to capture and payment 
124
     Not using a line model as it's difficult to capture and payment 
145
     
140
     
146
     @property
141
     @property
147
     def description(self):
142
     def description(self):
148
-        """
143
+        u"""
149
         Returns a description of this line including details of any 
144
         Returns a description of this line including details of any 
150
         line attributes.
145
         line attributes.
151
         """
146
         """
159
     
154
     
160
     @property
155
     @property
161
     def shipping_status(self):
156
     def shipping_status(self):
162
-        """
163
-        Returns a string summary of the shipping status of this line
164
-        """
157
+        u"""Returns a string summary of the shipping status of this line"""
165
         status_map = self._shipping_event_history()
158
         status_map = self._shipping_event_history()
166
         
159
         
167
         events = []    
160
         events = []    
173
         return ', '.join(events)
166
         return ', '.join(events)
174
     
167
     
175
     def has_shipping_event_occurred(self, event_type):
168
     def has_shipping_event_occurred(self, event_type):
176
-        """
177
-        Checks whether this line has passed a given shipping event
178
-        """
169
+        u"""Checks whether this line has passed a given shipping event"""
179
         for name, quantity in self._shipping_event_history().items():
170
         for name, quantity in self._shipping_event_history().items():
180
             if name == event_type.name and quantity == self.quantity:
171
             if name == event_type.name and quantity == self.quantity:
181
                 return True
172
                 return True
182
         return False
173
         return False
183
     
174
     
184
     def _shipping_event_history(self):
175
     def _shipping_event_history(self):
185
-        """
176
+        u"""
186
         Returns a dict of shipping event name -> quantity that have been
177
         Returns a dict of shipping event name -> quantity that have been
187
-        through this state
188
-        """
178
+        through this state"""
189
         status_map = {}
179
         status_map = {}
190
         for event in self.shippingevent_set.all():
180
         for event in self.shippingevent_set.all():
191
             event_name = event.event_type.name
181
             event_name = event.event_type.name
203
     
193
     
204
     
194
     
205
 class AbstractBatchLineAttribute(models.Model):
195
 class AbstractBatchLineAttribute(models.Model):
206
-    """
207
-    An attribute of a batch line.
208
-    """
196
+    u"""An attribute of a batch line."""
209
     line = models.ForeignKey('order.BatchLine', related_name='attributes')
197
     line = models.ForeignKey('order.BatchLine', related_name='attributes')
210
     type = models.CharField(_("Type"), max_length=128)
198
     type = models.CharField(_("Type"), max_length=128)
211
     value = models.CharField(_("Value"), max_length=255)    
199
     value = models.CharField(_("Value"), max_length=255)    
218
     
206
     
219
     
207
     
220
 class AbstractBatchLinePrice(models.Model):
208
 class AbstractBatchLinePrice(models.Model):
221
-    """
209
+    u"""
222
     For tracking the prices paid for each unit within a line.
210
     For tracking the prices paid for each unit within a line.
223
     
211
     
224
     This is necessary as offers can lead to units within a line 
212
     This is necessary as offers can lead to units within a line 
241
    
229
    
242
    
230
    
243
 class AbstractPaymentEvent(models.Model):    
231
 class AbstractPaymentEvent(models.Model):    
244
-    """
232
+    u"""
245
     An event is something which happens to a line such as
233
     An event is something which happens to a line such as
246
     payment being taken for 2 items, or 1 item being dispatched.
234
     payment being taken for 2 items, or 1 item being dispatched.
247
     """
235
     """
261
 
249
 
262
 
250
 
263
 class AbstractPaymentEventType(models.Model):
251
 class AbstractPaymentEventType(models.Model):
264
-    """ 
265
-    Payment events are things like 'Paid', 'Failed', 'Refunded'
266
-    """
252
+    u"""Payment events are things like 'Paid', 'Failed', 'Refunded'"""
267
     # Code is used in forms
253
     # Code is used in forms
268
     code = models.CharField(max_length=128)
254
     code = models.CharField(max_length=128)
269
     # Name is the friendly description of an event
255
     # Name is the friendly description of an event
286
 
272
 
287
 
273
 
288
 class AbstractShippingEvent(models.Model):    
274
 class AbstractShippingEvent(models.Model):    
289
-    """
275
+    u"""
290
     An event is something which happens to a group of lines such as
276
     An event is something which happens to a group of lines such as
291
     1 item being dispatched.
277
     1 item being dispatched.
292
     """
278
     """
312
 
298
 
313
 
299
 
314
 class ShippingEventQuantity(models.Model):
300
 class ShippingEventQuantity(models.Model):
315
-    """
316
-    A "through" model linking lines to shipping events
317
-    """
301
+    u"""A "through" model linking lines to shipping events"""
318
     event = models.ForeignKey('order.ShippingEvent')
302
     event = models.ForeignKey('order.ShippingEvent')
319
     line = models.ForeignKey('order.BatchLine')
303
     line = models.ForeignKey('order.BatchLine')
320
     quantity = models.PositiveIntegerField()
304
     quantity = models.PositiveIntegerField()
321
 
305
 
322
     def _check_previous_events_are_complete(self):
306
     def _check_previous_events_are_complete(self):
323
-        """
324
-        Checks whether previous shipping events have passed
325
-        """
307
+        u"""Checks whether previous shipping events have passed"""
326
         previous_events = ShippingEventQuantity.objects.filter(line=self.line, 
308
         previous_events = ShippingEventQuantity.objects.filter(line=self.line, 
327
                                                                event__event_type__order__lt=self.event.event_type.order)
309
                                                                event__event_type__order__lt=self.event.event_type.order)
328
         self.quantity = int(self.quantity)
310
         self.quantity = int(self.quantity)
349
 
331
 
350
 
332
 
351
 class AbstractShippingEventType(models.Model):
333
 class AbstractShippingEventType(models.Model):
352
-    """ 
353
-    Shipping events are things like 'OrderPlaced', 'Acknowledged', 'Dispatched', 'Refunded'
354
-    """
334
+    u"""Shipping events are things like 'OrderPlaced', 'Acknowledged', 'Dispatched', 'Refunded'"""
355
     # Code is used in forms
335
     # Code is used in forms
356
     code = models.CharField(max_length=128)
336
     code = models.CharField(max_length=128)
357
     # Name is the friendly description of an event
337
     # Name is the friendly description of an event

+ 1
- 3
oscar/order/models.py Просмотреть файл

1
-"""
2
-Vanilla implementation of order models
3
-"""
1
+u"""Vanilla implementation of order models"""
4
 from django.db import models
2
 from django.db import models
5
 
3
 
6
 from oscar.order.abstract_models import *
4
 from oscar.order.abstract_models import *

+ 7
- 2
oscar/order_management/views.py Просмотреть файл

14
 
14
 
15
 
15
 
16
 class OrderListView(ListView):
16
 class OrderListView(ListView):
17
-
17
+    u"""A list of orders"""
18
     context_object_name = "orders"
18
     context_object_name = "orders"
19
     template_name = 'order_management/browse.html'
19
     template_name = 'order_management/browse.html'
20
     paginate_by = 20
20
     paginate_by = 20
24
     
24
     
25
   
25
   
26
 class OrderView(ModelView):
26
 class OrderView(ModelView):
27
+    u"""A detail view of an order"""
27
     template_file = "order_management/order.html"
28
     template_file = "order_management/order.html"
28
     
29
     
29
     def get_model(self):
30
     def get_model(self):
31
+        u"""Return an order object or a 404"""
30
         return get_object_or_404(order_models.Order, number=self.kwargs['order_number'])
32
         return get_object_or_404(order_models.Order, number=self.kwargs['order_number'])
31
     
33
     
32
     def handle_GET(self, order):
34
     def handle_GET(self, order):
40
         super(OrderView, self).handle_POST(order)
42
         super(OrderView, self).handle_POST(order)
41
         
43
         
42
     def do_create_event(self, order):
44
     def do_create_event(self, order):
45
+        u"""Create an event for an order"""
43
         line_ids = self.request.POST.getlist('order_line')
46
         line_ids = self.request.POST.getlist('order_line')
44
         batch = order.batches.get(id=self.request.POST['batch_id'])
47
         batch = order.batches.get(id=self.request.POST['batch_id'])
45
         lines = batch.lines.in_bulk(line_ids)
48
         lines = batch.lines.in_bulk(line_ids)
53
             messages.error(self.request, str(e))    
56
             messages.error(self.request, str(e))    
54
                 
57
                 
55
     def create_shipping_event(self, order, batch, lines):
58
     def create_shipping_event(self, order, batch, lines):
59
+        u"""Create a shipping event for an order"""
56
         with transaction.commit_on_success():
60
         with transaction.commit_on_success():
57
             event_type = order_models.ShippingEventType.objects.get(code=self.request.POST['shipping_event'])
61
             event_type = order_models.ShippingEventType.objects.get(code=self.request.POST['shipping_event'])
58
             event = order_models.ShippingEvent.objects.create(order=order, event_type=event_type, batch=batch)
62
             event = order_models.ShippingEvent.objects.create(order=order, event_type=event_type, batch=batch)
62
                                                                   quantity=event_quantity)
66
                                                                   quantity=event_quantity)
63
             
67
             
64
     def create_payment_event(self, order, lines, type_code):
68
     def create_payment_event(self, order, lines, type_code):
69
+        u"""Create a payment event for an order"""
65
         event_type = order_models.PaymentEventType.objects.get(code=type_code)
70
         event_type = order_models.PaymentEventType.objects.get(code=type_code)
66
         for line in lines.values():
71
         for line in lines.values():
67
             order_models.PaymentEvent.objects.create(order=order, line=line, 
72
             order_models.PaymentEvent.objects.create(order=order, line=line, 
68
                                                      quantity=line.quantity, event_type=event_type)
73
                                                      quantity=line.quantity, event_type=event_type)
69
             
74
             
70
     def do_add_note(self, order):
75
     def do_add_note(self, order):
71
-        u"""Save a note against the order."""
76
+        u"""Save a note against an order."""
72
         if self.request.user.is_authenticated():
77
         if self.request.user.is_authenticated():
73
             message = self.request.POST['message'].strip()
78
             message = self.request.POST['message'].strip()
74
             if message:
79
             if message:

+ 3
- 5
oscar/payment/abstract_models.py Просмотреть файл

3
 from django.utils.translation import ugettext as _
3
 from django.utils.translation import ugettext as _
4
 
4
 
5
 class AbstractSource(models.Model):
5
 class AbstractSource(models.Model):
6
-    """
6
+    u"""
7
     A source of payment for an order.  
7
     A source of payment for an order.  
8
     
8
     
9
     This is normally a credit card which has been pre-authed
9
     This is normally a credit card which has been pre-authed
27
         return description
27
         return description
28
     
28
     
29
 class AbstractSourceType(models.Model):
29
 class AbstractSourceType(models.Model):
30
-    """
31
-    A type of payment source (eg Bankcard, Business account, Gift card)
32
-    """
30
+    u"""A type of payment source (eg Bankcard, Business account, Gift card)"""
33
     name = models.CharField(max_length=128)
31
     name = models.CharField(max_length=128)
34
 
32
 
35
     class Meta:
33
     class Meta:
39
         return self.name
37
         return self.name
40
 
38
 
41
 class AbstractTransaction(models.Model):
39
 class AbstractTransaction(models.Model):
42
-    """
40
+    u"""
43
     A transaction for payment sources which need a secondary 'transaction' to actually take the money
41
     A transaction for payment sources which need a secondary 'transaction' to actually take the money
44
     
42
     
45
     This applies mainly to credit card sources which can be a pre-auth for the money.  A 'complete'
43
     This applies mainly to credit card sources which can be a pre-auth for the money.  A 'complete'

+ 18
- 15
oscar/product/abstract_models.py Просмотреть файл

12
 from oscar.product.managers import BrowsableItemManager
12
 from oscar.product.managers import BrowsableItemManager
13
 
13
 
14
 def _convert_to_underscores(str):
14
 def _convert_to_underscores(str):
15
-    """
15
+    u"""
16
     For converting a string in CamelCase or normal text with spaces
16
     For converting a string in CamelCase or normal text with spaces
17
     to the normal underscored variety
17
     to the normal underscored variety
18
     """
18
     """
22
 
22
 
23
 
23
 
24
 class AbstractItemClass(models.Model):
24
 class AbstractItemClass(models.Model):
25
-    """
26
-    Defines an item type (equivqlent to Taoshop's MediaType).
27
-    """
25
+    u"""Defines an item type (equivqlent to Taoshop's MediaType)."""
28
     name = models.CharField(_('name'), max_length=128)
26
     name = models.CharField(_('name'), max_length=128)
29
     slug = models.SlugField(max_length=128, unique=True)
27
     slug = models.SlugField(max_length=128, unique=True)
30
     options = models.ManyToManyField('product.Option', blank=True)
28
     options = models.ManyToManyField('product.Option', blank=True)
47
 
45
 
48
 
46
 
49
 class AbstractItem(models.Model):
47
 class AbstractItem(models.Model):
50
-    """
51
-    The base product object
52
-    """
48
+    u"""The base product object"""
53
     # If an item has no parent, then it is the "canonical" or abstract version of a product
49
     # If an item has no parent, then it is the "canonical" or abstract version of a product
54
     # which essentially represents a set of products.  If a product has a parent
50
     # which essentially represents a set of products.  If a product has a parent
55
     # then it is a specific version of a product.
51
     # then it is a specific version of a product.
84
 
80
 
85
     @property
81
     @property
86
     def is_top_level(self):
82
     def is_top_level(self):
83
+        u"""Return True if this is a parent product"""
87
         return self.parent_id == None
84
         return self.parent_id == None
88
     
85
     
89
     @property
86
     @property
90
     def is_group(self):
87
     def is_group(self):
88
+        u"""Return True if this is a top level product and has more than 0 variants"""
91
         return self.is_top_level and self.variants.count() > 0
89
         return self.is_top_level and self.variants.count() > 0
92
     
90
     
93
     @property
91
     @property
94
     def is_variant(self):
92
     def is_variant(self):
93
+        u"""Return True if a product is not a top level product"""
95
         return not self.is_top_level
94
         return not self.is_top_level
96
 
95
 
97
     @property
96
     @property
98
     def min_variant_price_incl_tax(self):
97
     def min_variant_price_incl_tax(self):
98
+        u"""Return minimum variant price including tax"""
99
         return self._min_variant_price('price_incl_tax')
99
         return self._min_variant_price('price_incl_tax')
100
     
100
     
101
     @property
101
     @property
102
     def min_variant_price_excl_tax(self):
102
     def min_variant_price_excl_tax(self):
103
+        u"""Return minimum variant price excluding tax"""
103
         return self._min_variant_price('price_excl_tax')
104
         return self._min_variant_price('price_excl_tax')
104
 
105
 
105
     @property
106
     @property
106
     def has_stockrecord(self):
107
     def has_stockrecord(self):
108
+        u"""Return True if a product has a stock record, False if not"""
107
         try:
109
         try:
108
             sr = self.stockrecord
110
             sr = self.stockrecord
109
             return True
111
             return True
111
             return False
113
             return False
112
 
114
 
113
     def attribute_summary(self):
115
     def attribute_summary(self):
116
+        u"""Return a string of all of a product's attributes"""
114
         return ", ".join([attribute.__unicode__() for attribute in self.attributes.all()])
117
         return ", ".join([attribute.__unicode__() for attribute in self.attributes.all()])
115
 
118
 
116
     def get_title(self):
119
     def get_title(self):
120
+        u"""Return a product's title or it's parent's title if it has no title"""
117
         title = self.__dict__.setdefault('title', '')
121
         title = self.__dict__.setdefault('title', '')
118
         if not title and self.parent_id:
122
         if not title and self.parent_id:
119
             title = self.parent.title
123
             title = self.parent.title
120
         return title
124
         return title
121
     
125
     
122
     def get_item_class(self):
126
     def get_item_class(self):
127
+        u"""Return a product's item class"""
123
         if self.item_class:
128
         if self.item_class:
124
             return self.item_class
129
             return self.item_class
125
         if self.parent.item_class:
130
         if self.parent.item_class:
129
     # Helpers
134
     # Helpers
130
     
135
     
131
     def _min_variant_price(self, property):
136
     def _min_variant_price(self, property):
137
+        u"""Return minimum variant price"""
132
         prices = []
138
         prices = []
133
         for variant in self.variants.all():
139
         for variant in self.variants.all():
134
             if variant.has_stockrecord:
140
             if variant.has_stockrecord:
148
         return self.get_title()
154
         return self.get_title()
149
     
155
     
150
     def get_absolute_url(self):
156
     def get_absolute_url(self):
157
+        u"""Return a product's absolute url"""
151
         args = {'item_class_slug': self.get_item_class().slug, 
158
         args = {'item_class_slug': self.get_item_class().slug, 
152
                 'item_slug': self.slug,
159
                 'item_slug': self.slug,
153
                 'item_id': self.id}
160
                 'item_id': self.id}
163
 
170
 
164
 
171
 
165
 class AbstractAttributeType(models.Model):
172
 class AbstractAttributeType(models.Model):
166
-    """
167
-    Defines an attribute. (Eg. size)
168
-    """
173
+    u"""Defines an attribute. (Eg. size)"""
169
     code = models.CharField(_('code'), max_length=128)
174
     code = models.CharField(_('code'), max_length=128)
170
     name = models.CharField(_('name'), max_length=128)
175
     name = models.CharField(_('name'), max_length=128)
171
     has_choices = models.BooleanField(default=False)
176
     has_choices = models.BooleanField(default=False)
184
         
189
         
185
 
190
 
186
 class AbstractAttributeValueOption(models.Model):
191
 class AbstractAttributeValueOption(models.Model):
187
-    """
188
-    Defines an attribute value choice (Eg: S,M,L,XL for a size attribute type)
189
-    """
192
+    u"""Defines an attribute value choice (Eg: S,M,L,XL for a size attribute type)"""
190
     type = models.ForeignKey('product.AttributeType', related_name='options')
193
     type = models.ForeignKey('product.AttributeType', related_name='options')
191
     value = models.CharField(max_length=255)
194
     value = models.CharField(max_length=255)
192
 
195
 
198
 
201
 
199
 
202
 
200
 class AbstractItemAttributeValue(models.Model):
203
 class AbstractItemAttributeValue(models.Model):
201
-    """
204
+    u"""
202
     A specific attribute value for an item.
205
     A specific attribute value for an item.
203
     
206
     
204
     Eg: size = L
207
     Eg: size = L
215
     
218
     
216
     
219
     
217
 class AbstractOption(models.Model):
220
 class AbstractOption(models.Model):
218
-    """
221
+    u"""
219
     An option that can be selected for a particular item when the product
222
     An option that can be selected for a particular item when the product
220
     is added to the basket.  Eg a message for a SMS message.  This is not
223
     is added to the basket.  Eg a message for a SMS message.  This is not
221
     the same as an attribute as options do not have a fixed value for 
224
     the same as an attribute as options do not have a fixed value for 

+ 7
- 7
oscar/product/views.py Просмотреть файл

13
 
13
 
14
 
14
 
15
 class ItemDetailView(DetailView):
15
 class ItemDetailView(DetailView):
16
-    """
17
-    View a single product.
18
-    """
16
+    u"""View a single product."""
19
     template_name = "product/item.html"
17
     template_name = "product/item.html"
20
     
18
     
21
     def get(self, request, **kwargs):
19
     def get(self, request, **kwargs):
20
+        u"""Return a product's detail or a 404"""
22
         item = self.get_object()
21
         item = self.get_object()
23
         correct_path = item.get_absolute_url() 
22
         correct_path = item.get_absolute_url() 
24
         if correct_path != request.path:
23
         if correct_path != request.path:
26
         return super(ItemDetailView, self).get(request, **kwargs)
25
         return super(ItemDetailView, self).get(request, **kwargs)
27
     
26
     
28
     def get_object(self):
27
     def get_object(self):
28
+        u"""Return a product object or a 404"""
29
         return get_object_or_404(product_models.Item, pk=self.kwargs['item_id'])
29
         return get_object_or_404(product_models.Item, pk=self.kwargs['item_id'])
30
     
30
     
31
     def get_context_data(self, **kwargs):
31
     def get_context_data(self, **kwargs):
39
 
39
 
40
 
40
 
41
 class ItemClassListView(ListView):
41
 class ItemClassListView(ListView):
42
-    """
43
-    View products filtered by item-class.
44
-    """
42
+    u"""View products filtered by item-class."""
45
     context_object_name = "products"
43
     context_object_name = "products"
46
     template_name = 'product/browse.html'
44
     template_name = 'product/browse.html'
47
     paginate_by = 20
45
     paginate_by = 20
52
 
50
 
53
 
51
 
54
 class ProductListView(ListView):
52
 class ProductListView(ListView):
55
-
53
+    u"""A list of products"""
56
     context_object_name = "products"
54
     context_object_name = "products"
57
     template_name = 'product/browse.html'
55
     template_name = 'product/browse.html'
58
     paginate_by = 20
56
     paginate_by = 20
59
 
57
 
60
     def get_search_query(self):
58
     def get_search_query(self):
59
+        u"""Return a search query from GET"""
61
         q = None
60
         q = None
62
         if 'q' in self.request.GET and self.request.GET['q']:
61
         if 'q' in self.request.GET and self.request.GET['q']:
63
             q = self.request.GET['q'].strip()
62
             q = self.request.GET['q'].strip()
64
         return q
63
         return q
65
 
64
 
66
     def get_queryset(self):
65
     def get_queryset(self):
66
+        u"""Return a set of prodcuts"""
67
         q = self.get_search_query()
67
         q = self.get_search_query()
68
         if q:
68
         if q:
69
             return product_models.Item.browsable.filter(title__icontains=q)
69
             return product_models.Item.browsable.filter(title__icontains=q)

+ 1
- 1
oscar/services.py Просмотреть файл

7
     pass
7
     pass
8
 
8
 
9
 def import_module(module_label, classes=[]):
9
 def import_module(module_label, classes=[]):
10
-    """
10
+    u"""
11
     For dynamically importing classes from a module based on the mapping within 
11
     For dynamically importing classes from a module based on the mapping within 
12
     settings.py
12
     settings.py
13
     
13
     

+ 2
- 0
oscar/shipping/abstract_models.py Просмотреть файл

30
         self._basket = basket
30
         self._basket = basket
31
     
31
     
32
     def basket_charge_incl_tax(self):
32
     def basket_charge_incl_tax(self):
33
+        u"""Return basket total including tax"""
33
         charge = self.price_per_order
34
         charge = self.price_per_order
34
         for line in self._basket.lines.all():
35
         for line in self._basket.lines.all():
35
             charge += line.quantity * self.price_per_item
36
             charge += line.quantity * self.price_per_item
36
         return charge
37
         return charge
37
     
38
     
38
     def basket_charge_excl_tax(self):
39
     def basket_charge_excl_tax(self):
40
+        u"""Return basket total excluding tax"""
39
         # @todo store tax amounts?
41
         # @todo store tax amounts?
40
         return self.basket_charge_incl_tax()
42
         return self.basket_charge_incl_tax()

+ 5
- 0
oscar/stock/abstract_models.py Просмотреть файл

44
         abstract = True
44
         abstract = True
45
     
45
     
46
     def decrement_num_in_stock(self, delta):
46
     def decrement_num_in_stock(self, delta):
47
+        u"""Decrement an item's stock level"""
47
         if self.num_in_stock >= delta:
48
         if self.num_in_stock >= delta:
48
             self.num_in_stock -= delta
49
             self.num_in_stock -= delta
49
         self.num_allocated += delta
50
         self.num_allocated += delta
54
     
55
     
55
     @property
56
     @property
56
     def availability(self):
57
     def availability(self):
58
+        u"""Return an item's availability as a string"""
57
         if self.num_in_stock:
59
         if self.num_in_stock:
58
             return _("In stock (%d available)" % self.num_in_stock)
60
             return _("In stock (%d available)" % self.num_in_stock)
59
         return _("Out of stock")
61
         return _("Out of stock")
60
     
62
     
61
     @property 
63
     @property 
62
     def price_incl_tax(self):
64
     def price_incl_tax(self):
65
+        u"""Return a product's price including tax"""
63
         return self.price_excl_tax
66
         return self.price_excl_tax
64
     
67
     
65
     @property 
68
     @property 
66
     def price_tax(self):
69
     def price_tax(self):
70
+        u"""Return a product's tax value"""
71
+        #TODO?
67
         return 0
72
         return 0
68
         
73
         
69
     def __unicode__(self):
74
     def __unicode__(self):

+ 1
- 0
oscar/templatetags/currency_filters.py Просмотреть файл

8
 
8
 
9
 @register.filter(name='currency')
9
 @register.filter(name='currency')
10
 def currency(value):
10
 def currency(value):
11
+    u"""Return value converted to a locale currency"""
11
     try:
12
     try:
12
         locale.setlocale(locale.LC_ALL, settings.LOCALE)
13
         locale.setlocale(locale.LC_ALL, settings.LOCALE)
13
     except AttributeError:
14
     except AttributeError:

Загрузка…
Отмена
Сохранить