3 from south.db import db
4 from south.v2 import DataMigration
5 from django.db import models
7 class Migration(DataMigration):
9 def forwards(self, orm):
10 """ Look for HTML files without any real content and delete them """
11 from lxml import etree
12 from librarian.html import html_has_content
14 for book in orm.Book.objects.exclude(html_file=''):
15 if not html_has_content(etree.parse(book.html_file)):
16 book.html_file.delete()
17 # must do it by hand, we don't see real Book.save
18 for key in filter(lambda x: x.startswith('_short_html'), book.__dict__):
19 book.__setattr__(key, '')
22 def backwards(self, orm):
23 """ Do nothing. We don't want empty HTML files anyway. """
28 'Meta': {'object_name': 'Group'},
29 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
30 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
31 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'})
34 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
35 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
36 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
37 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
38 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
41 'Meta': {'object_name': 'User'},
42 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
43 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
44 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
45 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True'}),
46 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
47 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
48 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
49 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
50 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
51 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
52 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
53 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'}),
54 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
57 'Meta': {'object_name': 'Book'},
58 '_short_html': ('django.db.models.fields.TextField', [], {}),
59 '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
60 '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
61 '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
62 '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
63 '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
64 '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
65 '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
66 '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
67 '_tag_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
68 '_theme_counter': ('catalogue.fields.JSONField', [], {'null': 'True'}),
69 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
70 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
71 'epub_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
72 'extra_info': ('catalogue.fields.JSONField', [], {}),
73 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
74 'html_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
75 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
76 'mp3_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
77 'odt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
78 'ogg_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
79 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}),
80 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
81 'pdf_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
82 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120', 'db_index': 'True'}),
83 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
84 'txt_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'}),
85 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
86 'xml_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'blank': 'True'})
88 'catalogue.bookstub': {
89 'Meta': {'object_name': 'BookStub'},
90 'author': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
91 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
92 'pd': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
93 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120', 'db_index': 'True'}),
94 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
95 'translator': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
96 'translator_death': ('django.db.models.fields.TextField', [], {'blank': 'True'})
98 'catalogue.fragment': {
99 'Meta': {'object_name': 'Fragment'},
100 '_short_html': ('django.db.models.fields.TextField', [], {}),
101 '_short_html_de': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
102 '_short_html_en': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
103 '_short_html_es': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
104 '_short_html_fr': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
105 '_short_html_lt': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
106 '_short_html_pl': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
107 '_short_html_ru': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
108 '_short_html_uk': ('django.db.models.fields.TextField', [], {'null': True, 'blank': True}),
109 'anchor': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
110 'book': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'fragments'", 'to': "orm['catalogue.Book']"}),
111 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
112 'short_text': ('django.db.models.fields.TextField', [], {}),
113 'text': ('django.db.models.fields.TextField', [], {})
116 'Meta': {'object_name': 'Tag'},
117 'book_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
118 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
119 'death': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
120 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
121 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}),
122 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
123 'main_page': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}),
124 'name': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
125 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120', 'db_index': 'True'}),
126 'sort_key': ('django.db.models.fields.SlugField', [], {'max_length': '120', 'db_index': 'True'}),
127 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
128 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'})
130 'catalogue.tagrelation': {
131 'Meta': {'unique_together': "(('tag', 'content_type', 'object_id'),)", 'object_name': 'TagRelation', 'db_table': "'catalogue_tag_relation'"},
132 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
133 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
134 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
135 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'to': "orm['catalogue.Tag']"})
137 'contenttypes.contenttype': {
138 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
139 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
140 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
141 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
142 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
146 complete_apps = ['catalogue']