Browse Source

Use choices for CommunicationEventType.category

From #1435:
CommunicationEventType.category is used also to "detect" order-related
emails, in which case when previewing that email Oscar will put a
user-supplied order in the context for the email template.
This doesn't always work because the string that's saved in category
is localized.

Using choices remedies the problem. I don't think this feature is
commonly used, so no attempt at backwards-compatibility for
non-English setups is made.

South doesn't create a migration for this change.

Fixes #1435.
master
Maik Hoepfel 11 years ago
parent
commit
16582f386e

+ 6
- 0
docs/source/releases/v0.8.rst View File

@@ -484,6 +484,12 @@ Misc
484 484
   ``ImportError`` if a model can't be found. That brings it more in line with
485 485
   what Django does since the app refactor.
486 486
 
487
+* ``CommunicationEventType.category`` was storing a localised string, which
488
+  breaks when switching locale. It now uses ``choices`` to map between the
489
+  value and a localised string. Unfortunately, if you're using this feature
490
+  and not running an English locale, you will need to migrate the existing
491
+  data to the English values.
492
+
487 493
 .. _rewritten: https://github.com/tangentlabs/django-oscar/commit/d8b4dbfed17be90846ea4bc47b5f7b39ad944c24
488 494
 
489 495
 Basket line stockrecords

+ 11
- 4
oscar/apps/customer/abstract_models.py View File

@@ -149,10 +149,17 @@ class AbstractCommunicationEventType(models.Model):
149 149
         help_text=_("This is just used for organisational purposes"))
150 150
 
151 151
     # We allow communication types to be categorised
152
-    ORDER_RELATED = _('Order related')
153
-    USER_RELATED = _('User related')
154
-    category = models.CharField(_('Category'), max_length=255,
155
-                                default=ORDER_RELATED)
152
+    # For backwards-compatibility, the choice values are quite verbose
153
+    ORDER_RELATED = 'Order related'
154
+    USER_RELATED = 'User related'
155
+    CATEGORY_CHOICES = (
156
+        (ORDER_RELATED, _('Order related')),
157
+        (USER_RELATED, _('User related'))
158
+    )
159
+
160
+    category = models.CharField(
161
+        _('Category'), max_length=255, default=ORDER_RELATED,
162
+        choices=CATEGORY_CHOICES)
156 163
 
157 164
     # Template content for emails
158 165
     # NOTE: There's an intentional distinction between None and ''. None

+ 19
- 0
oscar/apps/customer/migrations/0002_auto_20140808_1205.py View File

@@ -0,0 +1,19 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.db import models, migrations
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('customer', '0001_initial'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AlterField(
15
+            model_name='communicationeventtype',
16
+            name='category',
17
+            field=models.CharField(choices=[('Order related', 'Order related'), ('User related', 'User related')], verbose_name='Category', max_length=255, default='Order related'),
18
+        ),
19
+    ]

Loading…
Cancel
Save