1. mickt
  2. django-lfs

Commits

Kai Diefenbach  committed 56cb527

Added Application model.

  • Participants
  • Parent commits 9c05988
  • Branches default

Comments (0)

Files changed (2)

File lfs/core/management/commands/lfs_migrate.py

View file
 from django.utils.translation import ugettext_lazy as _
 
 # lfs imports
+import lfs.core.settings as lfs_settings
 from lfs.voucher.models import Voucher
-import lfs.core.settings as lfs_settings
 
 # south imports
 from south.db import db
     def handle(self, *args, **options):
         """
         """
-        # 0.5 -> trunk
-        db.add_column("voucher_voucher", "used_amount", models.PositiveSmallIntegerField(default=0))
-        db.add_column("voucher_voucher", "last_used_date", models.DateTimeField(blank=True, null=True))
-        db.add_column("voucher_voucher", "limit", models.PositiveSmallIntegerField(default=1))
+        from lfs.core.models import Application
+        try:
+            application = Application.objects.get(pk=1)
+        except Application.DoesNotExist:
+            application = Application.objects.create(version="0.5")
 
-        for voucher in Voucher.objects.all():
-            voucher.limit = 1
-            voucher.save()
+        version = application.version
+        print "Detected version: %s" % version
 
-        # This mus be done with execute because the old fields are not there
-        # anymore (and therefore can't be accessed via attribute) after the user
-        # has upgraded to the latest version.
-        db.execute("update voucher_voucher set used_amount = 1 where used = 1")
-        db.execute("update voucher_voucher set used_amount = 0 where used = 0")
-        db.execute("update voucher_voucher set last_used_date = used_date")
+        # 0.5 -> 0.6
+        if version == "0.5":
+            print "Migrate to 0.6"
+            db.add_column("voucher_voucher", "used_amount", models.PositiveSmallIntegerField(default=0))
+            db.add_column("voucher_voucher", "last_used_date", models.DateTimeField(blank=True, null=True))
+            db.add_column("voucher_voucher", "limit", models.PositiveSmallIntegerField(default=1))
 
-        db.delete_column('voucher_voucher', 'used')
-        db.delete_column('voucher_voucher', 'used_date')
+            for voucher in Voucher.objects.all():
+                voucher.limit = 1
+                voucher.save()
 
-        # price calculator
-        db.add_column("catalog_product", "price_calculator", models.CharField(
-            null=True, blank=True, choices=lfs_settings.LFS_PRICE_CALCULATOR_DICTIONARY.items(), max_length=255))
+            # This mus be done with execute because the old fields are not there
+            # anymore (and therefore can't be accessed via attribute) after the user
+            # has upgraded to the latest version.
+            db.execute("update voucher_voucher set used_amount = 1 where used = 1")
+            db.execute("update voucher_voucher set used_amount = 0 where used = 0")
+            db.execute("update voucher_voucher set last_used_date = used_date")
 
-        db.add_column("core_shop", "price_calculator",
-            models.CharField(choices=lfs_settings.LFS_PRICE_CALCULATOR_DICTIONARY.items(), default=lfs_settings.LFS_DEFAULT_PRICE_CALCULATOR, max_length=255))
+            db.delete_column('voucher_voucher', 'used')
+            db.delete_column('voucher_voucher', 'used_date')
 
-        # Locale and currency settings
-        db.add_column("core_shop", "default_locale",
-            models.CharField(_(u"Default Shop Locale"), max_length=20, default="de_DE.UTF-8"))
-        db.add_column("core_shop", "use_international_currency_code",
-            models.BooleanField(_(u"Use international currency codes"), default=False))
-        db.delete_column('core_shop', 'default_currency')
+            # price calculator
+            db.add_column("catalog_product", "price_calculator", models.CharField(
+                null=True, blank=True, choices=lfs_settings.LFS_PRICE_CALCULATOR_DICTIONARY.items(), max_length=255))
 
-        db.add_column("catalog_product", "supplier_id", models.IntegerField(blank=True, null=True))
+            db.add_column("core_shop", "price_calculator",
+                models.CharField(choices=lfs_settings.LFS_PRICE_CALCULATOR_DICTIONARY.items(), default=lfs_settings.LFS_DEFAULT_PRICE_CALCULATOR, max_length=255))
+
+            # Locale and currency settings
+            db.add_column("core_shop", "default_locale",
+                models.CharField(_(u"Default Shop Locale"), max_length=20, default="en_US.UTF-8"))
+            db.add_column("core_shop", "use_international_currency_code",
+                models.BooleanField(_(u"Use international currency codes"), default=False))
+            db.delete_column('core_shop', 'default_currency')
+
+            db.add_column("catalog_product", "supplier_id", models.IntegerField(_(u"Supplier"), blank=True, null=True))
+
+            application.version = "0.6"
+            application.save()

File lfs/core/models.py

View file
     - confirm_toc
        If this is activated the shop customer has to confirm terms and
        conditions to checkout.
+
+    - version
+       The current version of the shop. Can be used for migrations.
     """
     name = models.CharField(_(u"Name"), max_length=30)
     shop_owner = models.CharField(_(u"Shop owner"), max_length=100, blank=True)
         """
         return None
 
+class Application(models.Model):
+    version = models.CharField(_("Version"), blank=True, max_length=10)
+
 from monkeys import *