From: Thomas Fillon Date: Tue, 1 Sep 2015 16:13:48 +0000 (+0200) Subject: Update script for data migration X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=467cea7869717fec2729eed53e3ab36dabcb5b5a;p=diggersdigest.git Update script for data migration --- diff --git a/diggersdigest/records/script_data_recover.py b/diggersdigest/records/script_data_recover.py index 2825e08..94c790b 100644 --- a/diggersdigest/records/script_data_recover.py +++ b/diggersdigest/records/script_data_recover.py @@ -13,51 +13,61 @@ from diggersdigest import settings import HTMLParser parser = HTMLParser.HTMLParser() +import mezzanine.blog.models as blog_models + -# Label -label_set = set([shop.label for shop in rec_models.Shop.objects.all()]) -count = 0 -for lab in label_set: - obj, created = rec_models.Label.objects.get_or_create(name = lab) - if created: - print "Create new Label : %s" % obj.name - count += 1 -print '--------------------------------------' -print "%d created label objects" % count -print "%d label in new db / %d in old db" % (len(rec_models.Label.objects.all()), len(label_set)) -print '--------------------------------------' +def populate_label(): + # Label + label_set = set([shop.label for shop in rec_models.Shop.objects.all()]) + count = 0 + for lab in label_set: + obj, created = rec_models.Label.objects.get_or_create(name = lab) + if created: + print "Create new Label : %s" % obj.name + count += 1 + print '--------------------------------------' + print "%d created label objects" % count + print "%d label in new db / %d in old db" % (len(rec_models.Label.objects.all()), len(label_set)) + print '--------------------------------------' + + return # Artist -artist_set = set([shop.artiste for shop in rec_models.Shop.objects.all()]) -count = 0 -for artist in artist_set: - obj, created = rec_models.Artist.objects.get_or_create(name = artist) - if created: - print "Create new Artist : %s" % obj.name - count += 1 +def populate_artist(): + artist_set = set([shop.artiste for shop in rec_models.Shop.objects.all()]) + count = 0 + for artist in artist_set: + obj, created = rec_models.Artist.objects.get_or_create(name = artist) + if created: + print "Create new Artist : %s" % obj.name + count += 1 + + print '--------------------------------------' + print "%d created artist object" % count + print "%d artist in new db / %d in old db" % (len(rec_models.Artist.objects.all()), len(artist_set)) + print '--------------------------------------' -print '--------------------------------------' -print "%d created artist object" % count -print "%d artist in new db / %d in old db" % (len(rec_models.Artist.objects.all()), len(artist_set)) -print '--------------------------------------' + return -# Pays -country_set = set([shop.pays for shop in rec_models.Shop.objects.all()]) -count = 0 -for country in country_set: - obj, created = rec_models.Country.objects.get_or_create(name = country) - if created: - print "Create new Country : %s" % obj.name - count += 1 +# Country +def populate_country( + country_set = set([shop.pays for shop in rec_models.Shop.objects.all()]) + count = 0 + for country in country_set: + obj, created = rec_models.Country.objects.get_or_create(name = country) + if created: + print "Create new Country : %s" % obj.name + count += 1 -print '--------------------------------------' -print "%d created country object" % count -print "%d country in new db / %d in old db" % (len(rec_models.Country.objects.all()), len(country_set)) -print '--------------------------------------' + print '--------------------------------------' + print "%d created country object" % count + print "%d country in new db / %d in old db" % (len(rec_models.Country.objects.all()), len(country_set)) + print '--------------------------------------' + return # Theme [theme for theme in rec_models.Theme.objects.all()] @@ -92,6 +102,9 @@ check_mp3(mp3_mix_list, MIX_PATH) # PODCAST FROM MIX +MIX_CATEGORY = 'Podcast' +blog_models.BlogCategory.objects.get_or_create(title='Podcast') + PODCAST_IMG_PATH = os.path.join('uploads/blog/mixes') PODCAST_AUDIO_PATH = os.path.join('uploads/audio/mixes') from django.contrib.auth import models as auth_models @@ -152,6 +165,7 @@ check_mp3(mp3_shop_list, RECORDS_PATH) # NEWS news_list = [news for news in rec_models.News.objects.all()] +blog_models.BlogCategory.objects.get_or_create(title='News') # GRADING @@ -252,3 +266,6 @@ for shop in shop_list: ## """ ## Model for Record ## """ + +if __name__ == '__main__': + pass