]> git.parisson.com Git - diggersdigest.git/commitdiff
Change release_date field to release_year and release_decade in Record model
authorThomas Fillon <thomas@parisson.com>
Fri, 4 Sep 2015 07:59:10 +0000 (09:59 +0200)
committerThomas Fillon <thomas@parisson.com>
Fri, 4 Sep 2015 07:59:10 +0000 (09:59 +0200)
diggersdigest/records/management/commands/populate_db.py
diggersdigest/records/migrations/0004_auto_20150904_0733.py [new file with mode: 0644]
diggersdigest/records/models.py

index cdb8226b7a558e3b1694a39596094cea8a2e5e1f..49673e3ddcb21f8a424cac83adc799c881b4fb6e 100644 (file)
@@ -24,7 +24,8 @@ from mezzanine.pages.models import Page
 
 # Check mp3 in media upload path
 def check_mp3(file_list, file_path):
-    file_exists = [os.path.exists(os.path.join(file_path, file_name))
+    abs_file_path = os.path.join(settings.MEDIA_ROOT, file_path)
+    file_exists = [os.path.exists(os.path.join(abs_file_path, file_name))
                    for file_name in file_list]
 
     missing_files = [file_name for (file_name, ok) in zip(file_list, file_exists) if not ok]
@@ -97,7 +98,7 @@ class Command(BaseCommand):
         # MP3 for mix
         mp3_mix_list = [mix.mp3 for mix in rec_models.Mix.objects.all()]
 
-        check_mp3(mp3_mix_list, PODCAST_AUDIO_PATH)
+        check_mp3(mp3_mix_list, os.join(PODCAST_AUDIO_PATH)
 
         ordered_mix_list = sorted(rec_models.Mix.objects.all(), key=lambda mix: mix.ordre)
         count = 0
@@ -181,11 +182,21 @@ class Command(BaseCommand):
                     d = ''
                 print n.titre, ' - ', d
                 
+
+    def get_year(date):
+        import parsedatime
+        cal = parsedatetime.Calendar()
+        res_date, flag = cal.parse(date)
+        if flag:
+            return res_date.tm_year, (res_date.tm_year//10) * 10
+        else:
+            return (None,None)
+    
     # SHOPS TO RECORDS
     def populate_record(self):
         self.stdout.write('Records\n-------\n')
 
-        AUDIO_PATH = os.path.join(settings.MEDIA_ROOT, 'uploads/audio/')
+        AUDIO_PATH = 'uploads/audio/'
         RECORDS_PATH = os.path.join(AUDIO_PATH, "records")
 
         shop_list = rec_models.Shop.objects.all()
@@ -196,7 +207,8 @@ 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_date = 
+            #obj.release_year =
+            # obj.release_decade =
             obj.date_text = shop.date
             obj.record_status = shop.new
             obj.label = rec_models.Label.objects.get(name = shop.label)
diff --git a/diggersdigest/records/migrations/0004_auto_20150904_0733.py b/diggersdigest/records/migrations/0004_auto_20150904_0733.py
new file mode 100644 (file)
index 0000000..8c22f3e
--- /dev/null
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('records', '0003_record_date_text'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='record',
+            name='release_date',
+        ),
+        migrations.AddField(
+            model_name='record',
+            name='release_decade',
+            field=models.CharField(max_length=8, null=True, verbose_name='release decade', choices=[(1920, '1920s'), (1930, '1930s'), (1940, '1940s'), (1950, '1950s'), (1960, '1960s'), (1970, '1970s'), (1980, '1980s'), (1990, '1990s'), (2000, '2000s'), (2010, '2010s'), (2020, '2020s')]),
+        ),
+        migrations.AddField(
+            model_name='record',
+            name='release_year',
+            field=models.IntegerField(null=True, verbose_name='release year', choices=[(1920, 1920), (1921, 1921), (1922, 1922), (1923, 1923), (1924, 1924), (1925, 1925), (1926, 1926), (1927, 1927), (1928, 1928), (1929, 1929), (1930, 1930), (1931, 1931), (1932, 1932), (1933, 1933), (1934, 1934), (1935, 1935), (1936, 1936), (1937, 1937), (1938, 1938), (1939, 1939), (1940, 1940), (1941, 1941), (1942, 1942), (1943, 1943), (1944, 1944), (1945, 1945), (1946, 1946), (1947, 1947), (1948, 1948), (1949, 1949), (1950, 1950), (1951, 1951), (1952, 1952), (1953, 1953), (1954, 1954), (1955, 1955), (1956, 1956), (1957, 1957), (1958, 1958), (1959, 1959), (1960, 1960), (1961, 1961), (1962, 1962), (1963, 1963), (1964, 1964), (1965, 1965), (1966, 1966), (1967, 1967), (1968, 1968), (1969, 1969), (1970, 1970), (1971, 1971), (1972, 1972), (1973, 1973), (1974, 1974), (1975, 1975), (1976, 1976), (1977, 1977), (1978, 1978), (1979, 1979), (1980, 1980), (1981, 1981), (1982, 1982), (1983, 1983), (1984, 1984), (1985, 1985), (1986, 1986), (1987, 1987), (1988, 1988), (1989, 1989), (1990, 1990), (1991, 1991), (1992, 1992), (1993, 1993), (1994, 1994), (1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)]),
+        ),
+    ]
index cc56e12195389b1214362627286058ac21617d48..d8ff5afc5fce081c2f9b9031777987e1921e82d5 100644 (file)
@@ -6,6 +6,8 @@ from __future__ import unicode_literals
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
+import datetime
+
 from mezzanine.core.fields import FileField
 from mezzanine.core.models import CONTENT_STATUS_DRAFT, CONTENT_STATUS_PUBLISHED
 from mezzanine.blog.models import BlogPost
@@ -13,6 +15,7 @@ from mezzanine.utils.models import upload_to
 
 from cartridge.shop.models import Product, ProductVariation
 
+
 # Auto-generated Django models with manage.py inspectdb on the old database
 # You'll have to do the following manually to clean this up:
 #   * Make sure each model has one field with primary_key=True
@@ -213,12 +216,21 @@ class Record(models.Model):
         (ON_HOLD, 'On Hold'),
         (JUST_SOLD, 'Just Sold')
     )
+        
+    YEAR_START = 1920
+
+    YEAR_STOP = datetime.datetime.now().year + 10
+    DECADE_START = (YEAR_START // 10) * 10
+    YEAR_CHOICES = [(y, y) for y in range(YEAR_START, YEAR_STOP)]
+    DECADE_CHOICES = [(d, str(d)+'s') for d in range (DECADE_START, YEAR_STOP, 10)]
+
     title = models.CharField(max_length=128)
     artist = models.ForeignKey(Artist, verbose_name=_('artist'), related_name='records_artists', null=True, on_delete=models.SET_NULL)
     performers = models.ManyToManyField(Artist, verbose_name=_('performers'), related_name='records_performers')
     record_status = models.IntegerField(_('record status'), choices=NOVELTY_CHOICES, default=NEW)
     label = models.ForeignKey(Label, verbose_name=_('label'), related_name='records', null=True, on_delete=models.SET_NULL)
-    release_date = models.DateField(_('release date'), null=True)
+    release_year = models.IntegerField(_('release year'), null=True, choices=YEAR_CHOICES)
+    release_decade = models.CharField(_('release decade'), max_length=8, 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)