Переглянути джерело

Refactor out a method for getting order message context

This was suggested in the code to #1437 and is an excellent idea. Allows
easy overriding and makes a long method easier to comprehend.
master
Maik Hoepfel 11 роки тому
джерело
коміт
e9db45f6c3
1 змінених файлів з 26 додано та 22 видалено
  1. 26
    22
      oscar/apps/checkout/mixins.py

+ 26
- 22
oscar/apps/checkout/mixins.py Переглянути файл

234
         order is submitted.
234
         order is submitted.
235
         """
235
         """
236
         # Send confirmation message (normally an email)
236
         # Send confirmation message (normally an email)
237
-        self.send_confirmation_message(order)
237
+        self.send_confirmation_message(order, self.communication_type_code)
238
 
238
 
239
         # Flush all session data
239
         # Flush all session data
240
         self.checkout_session.flush()
240
         self.checkout_session.flush()
254
     def get_success_url(self):
254
     def get_success_url(self):
255
         return reverse('checkout:thank-you')
255
         return reverse('checkout:thank-you')
256
 
256
 
257
-    def send_confirmation_message(self, order, **kwargs):
258
-        code = self.communication_type_code
259
-        ctx = {'user': self.request.user,
260
-               'order': order,
261
-               'site': get_current_site(self.request),
262
-               'lines': order.lines.all()}
263
-
264
-        if not self.request.user.is_authenticated():
265
-            # Attempt to add the anon order status URL to the email template
266
-            # ctx.
267
-            try:
268
-                path = reverse('customer:anon-order',
269
-                               kwargs={'order_number': order.number,
270
-                                       'hash': order.verification_hash()})
271
-            except NoReverseMatch:
272
-                # We don't care that much if we can't resolve the URL
273
-                pass
274
-            else:
275
-                site = Site.objects.get_current()
276
-                ctx['status_url'] = 'http://%s%s' % (site.domain, path)
277
-
257
+    def send_confirmation_message(self, order, code, **kwargs):
258
+        ctx = self.get_message_context(order)
278
         try:
259
         try:
279
             event_type = CommunicationEventType.objects.get(code=code)
260
             event_type = CommunicationEventType.objects.get(code=code)
280
         except CommunicationEventType.DoesNotExist:
261
         except CommunicationEventType.DoesNotExist:
296
             logger.warning("Order #%s - no %s communication event type",
277
             logger.warning("Order #%s - no %s communication event type",
297
                            order.number, code)
278
                            order.number, code)
298
 
279
 
280
+    def get_message_context(self, order):
281
+        ctx = {
282
+            'user': self.request.user,
283
+            'order': order,
284
+            'site': get_current_site(self.request),
285
+            'lines': order.lines.all()
286
+        }
287
+
288
+        if not self.request.user.is_authenticated():
289
+            # Attempt to add the anon order status URL to the email template
290
+            # ctx.
291
+            try:
292
+                path = reverse('customer:anon-order',
293
+                               kwargs={'order_number': order.number,
294
+                                       'hash': order.verification_hash()})
295
+            except NoReverseMatch:
296
+                # We don't care that much if we can't resolve the URL
297
+                pass
298
+            else:
299
+                site = Site.objects.get_current()
300
+                ctx['status_url'] = 'http://%s%s' % (site.domain, path)
301
+        return ctx
302
+
299
     # Basket helpers
303
     # Basket helpers
300
     # --------------
304
     # --------------
301
 
305
 

Завантаження…
Відмінити
Зберегти