From 934fd540098d7903340f8ca78b143fd2646e8016 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 15 Nov 2012 15:10:27 +0530 Subject: [PATCH] deal with erroneous year entries --- ifa/films/imports.py | 12 ++++++++++-- ifa/films/models.py | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ifa/films/imports.py b/ifa/films/imports.py index 306488c..048c74d 100644 --- a/ifa/films/imports.py +++ b/ifa/films/imports.py @@ -31,13 +31,21 @@ def do(path=path): def import_csv(path=csv_path): lines = csv.reader(open(path)) + try: + year = int(line[1].replace('"', '')[0:4]) + year_error = False + except: + year = None + year_error = True + for line in lines: d = { 'title': line[0], - 'year': int(line[1].replace('"', '')[0:4]), + 'year': year, 'director': line[2], 'producer': line[3], - 'language': line[4] + 'language': line[4], + 'year_error': year_error } f = Film(**d) f.save() diff --git a/ifa/films/models.py b/ifa/films/models.py index 7a7f6fa..ca2600c 100644 --- a/ifa/films/models.py +++ b/ifa/films/models.py @@ -6,6 +6,7 @@ class Film(models.Model): producer = models.CharField(max_length=512, blank=True) language = models.CharField(max_length=64, blank=True) year = models.IntegerField(max_length=4, blank=True, null=True) + year_error = models.BooleanField(default=False) available = models.BooleanField(default=False) notes = models.TextField(blank=True)