Browse Source

Added models for customer emails

master
David Winterbottom 14 years ago
parent
commit
107d56afca

+ 5
- 1
oscar/apps/checkout/views.py View File

@@ -25,6 +25,7 @@ import_module('order.models', ['Order', 'ShippingAddress', 'CommunicationEventTy
25 25
 import_module('order.utils', ['OrderNumberGenerator', 'OrderCreator'], locals())
26 26
 import_module('address.models', ['UserAddress'], locals())
27 27
 import_module('shipping.repository', ['Repository'], locals())
28
+import_module('customer.models', ['Email'], locals())
28 29
 
29 30
 logger = logging.getLogger('oscar.checkout')
30 31
 
@@ -326,10 +327,13 @@ class PaymentDetailsView(CheckoutView):
326 327
         if self.request.user.is_authenticated():
327 328
             # Send email
328 329
             logger.info(_("Order #%s: sending confirmation email" % order.number))
329
-            email = EmailMessage(subject='Subject', body='Body', to=[self.request.user.email])
330
+            email = EmailMessage('Subject', 'Body', to=[self.request.user.email])
330 331
             email.send()
331 332
             
332 333
             # If user is signed in, save email in history
334
+            Email._default_manager.create(user=self.request.user, 
335
+                                          subject=email.subject,
336
+                                          body_text=email.body)
333 337
             
334 338
         # Create order communication event
335 339
         self.create_order_placed_event(order)

+ 17
- 0
oscar/apps/customer/abstract_models.py View File

@@ -0,0 +1,17 @@
1
+from django.db import models
2
+from django.utils.translation import ugettext_lazy as _
3
+
4
+
5
+class AbstractEmail(models.Model):
6
+    
7
+    user = models.ForeignKey('auth.User', related_name='emails')
8
+    subject = models.TextField(_('Subject'), max_length=255)
9
+    body_text = models.TextField()
10
+    body_html = models.TextField(blank=True, null=True)
11
+    date_sent = models.DateTimeField(auto_now_add=True)
12
+    
13
+    class Meta:
14
+        abstract = True
15
+        
16
+    def __unicode__(self):
17
+        return u"Email to %s with subject '%s'" % (self.user.username, self.subject)

+ 9
- 0
oscar/apps/customer/admin.py View File

@@ -0,0 +1,9 @@
1
+from django.contrib import admin
2
+
3
+from oscar.core.loading import import_module
4
+import_module('customer.models', ['Email'], locals())
5
+
6
+admin.site.register(Email)
7
+
8
+
9
+

+ 10
- 0
oscar/apps/customer/models.py View File

@@ -0,0 +1,10 @@
1
+from django.db import models
2
+
3
+from oscar.apps.customer.abstract_models import AbstractEmail
4
+
5
+class Email(AbstractEmail):
6
+    pass
7
+
8
+
9
+
10
+    

Loading…
Cancel
Save