3 from south.db import db
4 from south.v2 import SchemaMigration
5 from django.db import models
6 from django.utils import simplejson as json
7 from mutagen import id3
10 def get_mp3_info(file):
11 """Retrieves artist and director names from audio ID3 tags."""
13 audio = id3.ID3(file.path)
14 artist_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE1'))
15 director_name = ', '.join(', '.join(tag.text) for tag in audio.getall('TPE3'))
17 artist_name = director_name = ''
18 return {'artist_name': artist_name, 'director_name': director_name}
21 class Migration(SchemaMigration):
23 def forwards(self, orm):
24 # Adding model 'BookMedia'
25 db.create_table('catalogue_bookmedia', (
26 ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
27 ('type', self.gf('django.db.models.fields.CharField')(max_length='100')),
28 ('name', self.gf('django.db.models.fields.CharField')(max_length='100', blank=True)),
29 ('file', self.gf('django.db.models.fields.files.FileField')(max_length=100, blank=True)),
30 ('uploaded_at', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
31 ('extra_info', self.gf('catalogue.fields.JSONField')(default='{}')),
33 db.send_create_signal('catalogue', ['BookMedia'])
35 # Adding M2M table for field medias on 'Book'
36 db.create_table('catalogue_book_medias', (
37 ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
38 ('book', models.ForeignKey(orm['catalogue.book'], null=False)),
39 ('bookmedia', models.ForeignKey(orm['catalogue.bookmedia'], null=False))
41 db.create_unique('catalogue_book_medias', ['book_id', 'bookmedia_id'])
45 jsonencoder = json.JSONEncoder()
46 for book in orm['old.book'].objects.all():
49 medias.append({"file": book.odt_file, "type": "odt"})
51 medias.append({"file": book.daisy_file, "type": "daisy"})
53 medias.append({"file": book.ogg_file, "type": "ogg"})
55 medias.append({"file": book.mp3_file, "type": "mp3"})
56 newbook = orm.Book.objects.get(pk=book.pk)
59 bookMedia = orm.BookMedia.objects.create(file=media['file'], type=media['type'], name=name)
60 if bookMedia.type == 'mp3':
61 bookMedia.extra_info = jsonencoder.encode(get_mp3_info(bookMedia.file))
63 newbook.medias.add(bookMedia)
65 # Deleting field 'Book.odt_file'
66 db.delete_column('catalogue_book', 'odt_file')
68 # Deleting field 'Book.daisy_file'
69 db.delete_column('catalogue_book', 'daisy_file')
71 # Deleting field 'Book.ogg_file'
72 db.delete_column('catalogue_book', 'ogg_file')
74 # Deleting field 'Book.mp3_file'
75 db.delete_column('catalogue_book', 'mp3_file')
77 # Changing field 'Tag.main_page'
78 db.alter_column('catalogue_tag', 'main_page', self.gf('django.db.models.fields.BooleanField')(blank=True))
81 def backwards(self, orm):
82 # Deleting model 'BookMedia'
83 db.delete_table('catalogue_bookmedia')
85 # Adding field 'Book.odt_file'
86 db.add_column('catalogue_book', 'odt_file', self.gf('django.db.models.fields.files.FileField')(default='', max_length=100, blank=True), keep_default=False)
88 # Adding field 'Book.daisy_file'
89 db.add_column('catalogue_book', 'daisy_file', self.gf('django.db.models.fields.files.FileField')(default='', max_length=100, blank=True), keep_default=False)
91 # Adding field 'Book.ogg_file'
92 db.add_column('catalogue_book', 'ogg_file', self.gf('django.db.models.fields.files.FileField')(default='', max_length=100, blank=True), keep_default=False)
94 # Adding field 'Book.mp3_file'
95 db.add_column('catalogue_book', 'mp3_file', self.gf('django.db.models.fields.files.FileField')(default='', max_length=100, blank=True), keep_default=False)
97 # Removing M2M table for field medias on 'Book'
98 db.delete_table('catalogue_book_medias')
100 # Changing field 'Tag.main_page'
101 db.alter_column('catalogue_tag', 'main_page', self.gf('django.db.models.fields.BooleanField')())
106 'Meta': {'object_name': 'Group'},
107 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
108 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True'}),
109 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
112 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
113 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
114 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
115 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
116 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
119 'Meta': {'object_name': 'User'},
120 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
121 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
122 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
123 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
124 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
125 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
126 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
127 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
128 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
129 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
130 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
131 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
132 'username': ('django.db.models.fields.CharField', [], {'max_length': '30', 'unique': 'True'})
135 'Meta': {'object_name': 'Book'},
136 '_short_html': ('django.db.models.fields.TextField', [], {}),
137 '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
138 '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
139 '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
140 '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
141 '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
142 '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
143 '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
144 '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
145 '_tag_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
146 '_theme_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
147 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
148 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
149 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
150 'extra_info': ('catalogue.fields.JSONField', [], {}),
151 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
152 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
153 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
154 'medias': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['catalogue.BookMedia']", 'symmetrical': 'False'}),
155 'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'children'", 'blank': 'True', 'null': 'True', 'to': "orm['catalogue.Book']"}),
156 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
157 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
158 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'db_index': 'True'}),
159 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
160 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
161 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
162 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
164 'catalogue.bookmedia': {
165 'Meta': {'object_name': 'BookMedia'},
166 'extra_info': ('catalogue.fields.JSONField', [], {'default': "'{}'"}),
167 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
168 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
169 'name': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
170 'type': ('django.db.models.fields.CharField', [], {'max_length': "'100'"}),
171 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
173 'catalogue.bookstub': {
174 'Meta': {'object_name': 'BookStub'},
175 'author': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
176 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
177 'pd': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
178 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'db_index': 'True'}),
179 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
180 'translator': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
181 'translator_death': ('django.db.models.fields.TextField', [], {'blank': 'True'})
183 'catalogue.filerecord': {
184 'Meta': {'object_name': 'FileRecord'},
185 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
186 'sha1': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
187 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
188 'time': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
189 'type': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_index': 'True'})
191 'catalogue.fragment': {
192 'Meta': {'object_name': 'Fragment'},
193 '_short_html': ('django.db.models.fields.TextField', [], {}),
194 '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
195 '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
196 '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
197 '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
198 '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
199 '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
200 '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
201 '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
202 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
203 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
204 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
205 'short_text': ('django.db.models.fields.TextField', [], {}),
206 'text': ('django.db.models.fields.TextField', [], {})
209 'Meta': {'unique_together': "(('slug', 'category'),)", 'object_name': 'Tag'},
210 'book_count': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
211 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
212 'death': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
213 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
214 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
215 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
216 'main_page': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
217 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
218 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
219 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}),
220 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
221 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
223 'catalogue.tagrelation': {
224 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
225 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
226 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
227 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
228 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
230 'contenttypes.contenttype': {
231 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
232 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
233 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
234 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
235 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
238 'Meta': {'ordering': "('title',)", 'object_name': 'Book', 'db_table': "'catalogue_book'"},
239 '_short_html': ('django.db.models.fields.TextField', [], {}),
240 '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
241 '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
242 '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
243 '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
244 '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
245 '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
246 '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
247 '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
248 '_tag_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
249 '_theme_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
250 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
251 'daisy_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
252 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
253 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
254 'extra_info': ('catalogue.fields.JSONField', [], {}),
255 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
256 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
257 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
258 'mp3_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
259 'odt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
260 'ogg_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
261 'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'children'", 'blank': 'True', 'null': 'True', 'to': "orm['catalogue.Book']"}),
262 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
263 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
264 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'unique': 'True', 'db_index': 'True'}),
265 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
266 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
267 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
268 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
272 complete_apps = ['catalogue']