Przeglądaj źródła

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

master
Kura 15 lat temu
rodzic
commit
048673f8e6

+ 4
- 0
docs/source/conf.py Wyświetl plik

@@ -214,3 +214,7 @@ man_pages = [
214 214
     ('index', 'django-oscar', u'django-oscar Documentation',
215 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 Wyświetl plik

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

+ 15
- 1
oscar/basket/abstract_models.py Wyświetl plik

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

+ 2
- 0
oscar/checkout/calculators.py Wyświetl plik

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

+ 1
- 0
oscar/checkout/signals.py Wyświetl plik

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

+ 11
- 1
oscar/checkout/utils.py Wyświetl plik

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

+ 1
- 1
oscar/checkout/views.py Wyświetl plik

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

+ 11
- 0
oscar/customer/views.py Wyświetl plik

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

+ 1
- 0
oscar/image/abstract_models.py Wyświetl plik

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

+ 22
- 42
oscar/order/abstract_models.py Wyświetl plik

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

+ 1
- 3
oscar/order/models.py Wyświetl plik

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

+ 7
- 2
oscar/order_management/views.py Wyświetl plik

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

+ 3
- 5
oscar/payment/abstract_models.py Wyświetl plik

@@ -3,7 +3,7 @@ from django.db import models
3 3
 from django.utils.translation import ugettext as _
4 4
 
5 5
 class AbstractSource(models.Model):
6
-    """
6
+    u"""
7 7
     A source of payment for an order.  
8 8
     
9 9
     This is normally a credit card which has been pre-authed
@@ -27,9 +27,7 @@ class AbstractSource(models.Model):
27 27
         return description
28 28
     
29 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 31
     name = models.CharField(max_length=128)
34 32
 
35 33
     class Meta:
@@ -39,7 +37,7 @@ class AbstractSourceType(models.Model):
39 37
         return self.name
40 38
 
41 39
 class AbstractTransaction(models.Model):
42
-    """
40
+    u"""
43 41
     A transaction for payment sources which need a secondary 'transaction' to actually take the money
44 42
     
45 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 Wyświetl plik

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

+ 7
- 7
oscar/product/views.py Wyświetl plik

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

+ 1
- 1
oscar/services.py Wyświetl plik

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

+ 2
- 0
oscar/shipping/abstract_models.py Wyświetl plik

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

+ 5
- 0
oscar/stock/abstract_models.py Wyświetl plik

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

+ 1
- 0
oscar/templatetags/currency_filters.py Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz