]> git.parisson.com Git - diggersdigest.git/commitdiff
Put back cover/vinyl condition in record model
authorThomas Fillon <thomas@parisson.com>
Mon, 7 Sep 2015 12:55:00 +0000 (14:55 +0200)
committerThomas Fillon <thomas@parisson.com>
Mon, 7 Sep 2015 12:55:00 +0000 (14:55 +0200)
diggersdigest/records/management/commands/populate_db.py
diggersdigest/records/migrations/0006_auto_20150907_0835.py [new file with mode: 0644]
diggersdigest/records/models.py

index 1012d1cb9b2728e39950fcf5b38baeac473f234f..51e71b2ae305e2cc0701718a96badaf72e025358 100644 (file)
@@ -11,7 +11,7 @@ from django.core.management.base import BaseCommand, CommandError
 
 import os
 from records import models as rec_models
-from cartridge.shop.models import Product, ProductOption, Category
+from cartridge.shop.models import Product, ProductVariation, Category, ProductImage
 
 from diggersdigest import settings
 
@@ -116,14 +116,14 @@ class Command(BaseCommand):
         self.stdout.write("\t%d new country objects" % count)
         self.stdout.write("\t%d countries in DB ( %d in old DB)" % (len(Country.objects.all()), len(old_country)))
 
-        
+
 
 
     # PODCAST FROM MIX
     def populate_podcast(self, user):
         MIX_CATEGORY = 'Podcast'
         blog_models.BlogCategory.objects.get_or_create(title=MIX_CATEGORY)
-        
+
         PODCAST_IMG_PATH = os.path.join('uploads/blog/mixes')
         PODCAST_AUDIO_PATH = os.path.join('uploads/audio/mixes')
 
@@ -162,7 +162,7 @@ class Command(BaseCommand):
                     obj.status=mix.published+1
                     obj.featured_image=img_path
                     obj.save()
-                
+
         self.stdout.write("\t%d new Podcast objects" % count)
         self.stdout.write("\t%d Podcast in DB ( %d in old DB)" % (len(rec_models.Podcast.objects.all()), len(ordered_mix_list)))
 
@@ -189,7 +189,7 @@ class Command(BaseCommand):
     ##                                                 )
     ##       #obj.delete()
     ##       #obj.description= "Fill in the form below to get in touch with us."
-          
+
     # NEWS
     def populate_news(self):
         ## news fields :
@@ -215,19 +215,23 @@ class Command(BaseCommand):
                 except AttributeError:
                     d = ''
                 print n.titre, ' - ', d
-                
+
 
     # Theme -> Category
     def populate_category(self):
         #
+        shop_cat, created = Category.objects.get_or_create(title="Shop")
+
         theme_list = [theme for theme in rec_models.Theme.objects.all() if theme.published==1]
         count = 0
         for theme in theme_list:
-            obj, create = Category.objects.get_or_create(pk=theme.id,
-                                                         title = theme.nom)
+            obj, create = Category.objects.get_or_create(pk=theme.id)
+            obj.title = theme.nom
+            obj.parent = shop_cat
+            obj.save()
             if create:
                 count +=1
-                
+
         self.stdout.write('Category\n-------\n')
         self.stdout.write("\t%d new Category objects" % count)
 
@@ -238,9 +242,10 @@ class Command(BaseCommand):
 
         AUDIO_PATH = 'uploads/audio/'
         RECORDS_PATH = os.path.join(AUDIO_PATH, "records")
-
+        IMG_PATH = os.path.join('uploads/product')
         shop_list = rec_models.Shop.objects.all()
-                     
+
+
         for shop in shop_list:
             obj, created = rec_models.Record.objects.get_or_create(pk=shop.id)
 
@@ -248,10 +253,12 @@ class Command(BaseCommand):
             obj.country = rec_models.Country.objects.get(name = shop.pays)
             obj.audio_file = os.path.join(RECORDS_PATH, shop.mp3)
             # product_id --> FK
-            
+
             obj.release_year , obj.release_decade = get_year(shop.date)
             obj.date_text = shop.date # To be deleted later ?
             obj.record_status = shop.new
+            obj.cover_condition_id = shop.cover
+            obj.vinyl_condition_id = shop.vinyl
             obj.label = rec_models.Label.objects.get(name = shop.label)
             obj.artist = rec_models.Artist.objects.get(name = shop.artiste)
             obj.save()
@@ -261,9 +268,9 @@ class Command(BaseCommand):
 
             theme = rec_models.Theme.objects.get(id=shop.theme)
             if (theme.published == 1) and (shop.published==1):
-                prod_obj, prod_created = Product.objects.get_or_create(pk=shop.id,
-                                                                       site_id=1)
-
+                prod_obj, prod_created = Product.objects.get_or_create(
+                                                title=obj.title,
+                                                content = shop.desc)
                 if shop.devise == 3: #Euros
                     prod_obj.unit_price = shop.prix
                 elif shop.devise == 1: # Dollar
@@ -275,12 +282,22 @@ class Command(BaseCommand):
                 category = Category.objects.get(pk=shop.theme)
                 prod_obj.categories.add(category)
 
+                prodvar = ProductVariation.objects.get_or_create(product=prod_obj,
+                                                                 default=True)
+
                 prod_obj.save()
                 obj.product = prod_obj
                 obj.save()
-                
+
+                img_file = os.path.join(IMG_PATH, str(shop.pk)+'.jpg')
+                abs_img_file = os.path.join(settings.MEDIA_ROOT, img_file)
+                if os.path.exists(abs_img_file):
+                    image, created = ProductImage.objects.get_or_create(
+                        file=img_file,
+                        product=prod_obj)
+
                 self.stdout.write('Product %d / %d --> %s' % (prod_obj.pk,len(shop_list), prod_obj.available))
-            
+
             #self.stdout.write('\b\b\b\b%.4d' % obj.pk)
             #print obj.__dict__
 
@@ -323,7 +340,7 @@ class Command(BaseCommand):
         digger, created = auth_models.User.objects.get_or_create(username=u'digger',
                                                                  password=u'admin',
                                                                  is_staff=True,
-                                                                 email=u'') 
+                                                                 email=u'')
 
         self.populate_category()
         self.populate_label()
@@ -333,7 +350,7 @@ class Command(BaseCommand):
         #self.populate_pages()
         #self.populate_news()
 
-        self.populate_record()
+        #self.populate_record()
 
 
 
@@ -395,9 +412,5 @@ for grade in rec_models.Grading.objects.all():
         print "Create new GradingCondition : %s" % obj.name
         count += 1
 
-    for option in settings.SHOP_OPTION_TYPE_CHOICES:
-        option_obj, option_created = ProductOption.objects.get_or_create(type=option[0],
-                                                                         name=grade.nom)
 
 print "%d fiches GradingCondition crées" % count
-
diff --git a/diggersdigest/records/migrations/0006_auto_20150907_0835.py b/diggersdigest/records/migrations/0006_auto_20150907_0835.py
new file mode 100644 (file)
index 0000000..2b8b73a
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('records', '0005_auto_20150904_1309'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='record',
+            name='cover_condition',
+            field=models.ForeignKey(related_name='records_cover_condition', on_delete=django.db.models.deletion.SET_NULL, verbose_name='cover condition', to='records.ConditionGrading', null=True),
+        ),
+        migrations.AddField(
+            model_name='record',
+            name='vinyl_condition',
+            field=models.ForeignKey(related_name='records_vinyl_condition', on_delete=django.db.models.deletion.SET_NULL, verbose_name='vinyl condition', to='records.ConditionGrading', null=True),
+        ),
+    ]
index 3f24318e5c2586c407e2dc823dbd3a5975f9715c..17bff9bc936a30b8bd347441dd128bdd95d08317 100644 (file)
@@ -216,7 +216,7 @@ class Record(models.Model):
         (ON_HOLD, 'On Hold'),
         (JUST_SOLD, 'Just Sold')
     )
-        
+
     YEAR_START = 1920
 
     YEAR_STOP = datetime.datetime.now().year + 10
@@ -233,8 +233,8 @@ class Record(models.Model):
     release_decade = models.IntegerField(_('release decade'), null=True, choices=DECADE_CHOICES)
     date_text = models.CharField(_('date text'), max_length=8, null=True)
     country = models.ForeignKey(Country, verbose_name=_('country'), related_name='records', null=True, on_delete=models.SET_NULL)
-    #cover_state = models.ForeignKey(ConditionGrading, verbose_name=_('cover condition'), related_name='records_cover_condition', null=True, on_delete=models.SET_NULL)
-    #vinyl_state = models.ForeignKey(ConditionGrading, verbose_name=_('vinyl condition'), related_name='records_vinyl_condition', null=True, on_delete=models.SET_NULL)
+    cover_condition = models.ForeignKey(ConditionGrading, verbose_name=_('cover condition'), related_name='records_cover_condition', null=True, on_delete=models.SET_NULL)
+    vinyl_condition = models.ForeignKey(ConditionGrading, verbose_name=_('vinyl condition'), related_name='records_vinyl_condition', null=True, on_delete=models.SET_NULL)
     audio_file =  FileField(_("audio file"), max_length=1024, format="audio",
                         upload_to=upload_to("records.Record.audio", "audio/records"), null=True)
     product = models.ForeignKey(Product, verbose_name=_('product'), related_name='records', null=True, on_delete=models.SET_NULL)