3 from hashlib import sha1
4 from south.db import db
5 from south.v2 import SchemaMigration
6 from django.db import models
11 for piece in iter(lambda: f.read(1024*1024), ''):
13 return sha.hexdigest()
16 class Migration(SchemaMigration):
18 def forwards(self, orm):
20 # Adding field 'Audiobook.source_sha1'
21 db.add_column('archive_audiobook', 'source_sha1', self.gf('django.db.models.fields.CharField')(default='', max_length=40), keep_default=False)
23 # Adding field 'Audiobook.translator'
24 db.add_column('archive_audiobook', 'translator', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True), keep_default=False)
27 for obj in orm.Audiobook.objects.all():
29 f = open(obj.source_file.path)
31 print "Audiobook has no source file"
34 obj.source_sha1 = sha1_file(f)
39 def backwards(self, orm):
41 # Deleting field 'Audiobook.source_sha1'
42 db.delete_column('archive_audiobook', 'source_sha1')
44 # Deleting field 'Audiobook.translator'
45 db.delete_column('archive_audiobook', 'translator')
49 'archive.audiobook': {
50 'Meta': {'ordering': "('title',)", 'object_name': 'Audiobook'},
51 'artist': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
52 'conductor': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
53 'date': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
54 'encoded_by': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
55 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
56 'modified': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
57 'mp3_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True'}),
58 'mp3_published': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
59 'mp3_published_tags': ('jsonfield.fields.JSONField', [], {'null': 'True'}),
60 'mp3_status': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True'}),
61 'mp3_tags': ('jsonfield.fields.JSONField', [], {'null': 'True'}),
62 'mp3_task': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
63 'ogg_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True'}),
64 'ogg_published': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
65 'ogg_published_tags': ('jsonfield.fields.JSONField', [], {'null': 'True'}),
66 'ogg_status': ('django.db.models.fields.SmallIntegerField', [], {'null': 'True'}),
67 'ogg_tags': ('jsonfield.fields.JSONField', [], {'null': 'True'}),
68 'ogg_task': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
69 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['archive.Project']"}),
70 'source_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
71 'source_sha1': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
72 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
73 'translator': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
74 'url': ('django.db.models.fields.URLField', [], {'max_length': '255'})
77 'Meta': {'ordering': "('name',)", 'object_name': 'Project'},
78 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
79 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'db_index': 'True'}),
80 'sponsors': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'})
84 complete_apps = ['archive']