3 from south.db import db
4 from south.v2 import DataMigration
5 from django.db import models
6 from forum.migrations import ProgressBar
7 from forum.models.utils import dbsafe_decode
9 class Migration(DataMigration):
11 def forwards(self, orm):
12 b_count = orm.Badge.objects.count()
13 print "\nConverting %d badges:" % b_count
14 progress = ProgressBar(b_count)
16 for b in orm.Badge.objects.all():
17 b.cls = "".join([s[0].upper() + s[1:] for s in b.slug.split('-')])
24 ctypes = dict([(ct.name, ct.id) for ct in orm['contenttypes.ContentType'].objects.all()])
26 a_count = orm.Award.objects.count()
27 print "\nConverting %d awards:" % a_count
28 progress = ProgressBar(a_count)
30 for a in orm.Award.objects.all():
31 if a.content_type.id == ctypes['user']:
35 a.node = orm.Node.objects.get(id=a.object_id)
43 action_type = "award",
44 action_date = a.awarded_at,
57 a_count = orm.Action.objects.filter(action_type__in=("voteup", "votedown", "voteupcomment")).count()
58 print "\nConverting %d votes:" % a_count
59 progress = ProgressBar(a_count)
61 for a in orm.Action.objects.filter(action_type__in=("voteup", "votedown", "voteupcomment"), canceled=False):
65 value = (a.action_type in ("voteup", "voteupcomment")) and 1 or -1,
67 voted_at = a.action_date
76 a_count = orm.Action.objects.filter(action_type__in=("voteup", "votedown", "voteupcomment")).count()
77 print "\nConverting %d votes:" % a_count
78 progress = ProgressBar(a_count)
80 for a in orm.Action.objects.filter(action_type="flag", canceled=False):
86 flagged_at = a.action_date
96 def backwards(self, orm):
97 "Write your backwards methods here."
101 'Meta': {'object_name': 'Group'},
102 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
103 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
104 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'})
107 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
108 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
109 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
110 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
111 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
114 'Meta': {'object_name': 'User'},
115 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
116 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
117 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
118 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True'}),
119 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
120 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
121 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
122 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
123 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
124 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
125 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
126 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True'}),
127 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
129 'contenttypes.contenttype': {
130 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
131 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
132 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
133 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
134 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
137 'Meta': {'object_name': 'Action'},
138 'action_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
139 'action_type': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
140 'canceled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
141 'canceled_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
142 'canceled_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'canceled_actions'", 'null': 'True', 'to': "orm['forum.User']"}),
143 'canceled_ip': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
144 'extra': ('forum.models.utils.PickledObjectField', [], {'null': 'True'}),
145 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
146 'ip': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
147 'node': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'actions'", 'null': 'True', 'to': "orm['forum.Node']"}),
148 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'actions'", 'to': "orm['forum.User']"})
150 'forum.actionrepute': {
151 'Meta': {'object_name': 'ActionRepute'},
152 'action': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reputes'", 'to': "orm['forum.Action']"}),
153 'by_canceled': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
154 'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
155 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
156 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reputes'", 'to': "orm['forum.User']"}),
157 'value': ('django.db.models.fields.IntegerField', [], {'default': '0'})
159 'forum.authkeyuserassociation': {
160 'Meta': {'object_name': 'AuthKeyUserAssociation'},
161 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
162 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
163 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
164 'provider': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
165 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'auth_keys'", 'to': "orm['forum.User']"})
168 'Meta': {'unique_together': "(('user', 'badge', 'node'),)", 'object_name': 'Award'},
169 'action': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award'", 'to': "orm['forum.Action']"}),
170 'awarded_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
171 'badge': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Badge']"}),
172 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
173 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
174 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Node']", 'null': 'True'}),
175 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
176 'trigger': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'awards'", 'null': 'True', 'to': "orm['forum.Action']"}),
177 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']"})
180 'Meta': {'object_name': 'Badge'},
181 'awarded_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
182 'awarded_to': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'badges'", 'through': "'Award'", 'to': "orm['forum.User']"}),
183 'cls': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
184 'description': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
185 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
186 'multiple': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
187 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
188 'slug': ('django.db.models.fields.SlugField', [], {'db_index': 'True', 'max_length': '50', 'blank': 'True'}),
189 'type': ('django.db.models.fields.SmallIntegerField', [], {})
192 'Meta': {'unique_together': "(('user', 'node'),)", 'object_name': 'Flag'},
193 'action': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'flag'", 'unique': 'True', 'to': "orm['forum.Action']"}),
194 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
195 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Node']"}),
196 'reason': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
197 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']"}),
198 'flagged_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
201 'Meta': {'object_name': 'KeyValue'},
202 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
203 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
204 'value': ('forum.models.utils.PickledObjectField', [], {'null': 'True'})
207 'Meta': {'object_name': 'MarkedTag'},
208 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
209 'reason': ('django.db.models.fields.CharField', [], {'max_length': '16'}),
210 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'user_selections'", 'to': "orm['forum.Tag']"}),
211 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tag_selections'", 'to': "orm['forum.User']"})
214 'Meta': {'object_name': 'Node'},
215 'abs_parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'all_children'", 'null': 'True', 'to': "orm['forum.Node']"}),
216 'active_revision': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'active'", 'unique': 'True', 'null': 'True', 'to': "orm['forum.NodeRevision']"}),
217 'added_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
218 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'nodes'", 'to': "orm['forum.User']"}),
219 'body': ('django.db.models.fields.TextField', [], {}),
220 'deleted': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'deleted_node'", 'unique': 'True', 'null': 'True', 'to': "orm['forum.Action']"}),
221 'extra_action': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'extra_node'", 'null': 'True', 'to': "orm['forum.Action']"}),
222 'extra_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
223 'extra_ref': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Node']", 'null': 'True'}),
224 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
225 'in_moderation': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'moderated_node'", 'unique': 'True', 'null': 'True', 'to': "orm['forum.Action']"}),
226 'last_activity_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
227 'last_activity_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']", 'null': 'True'}),
228 'last_edited': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'edited_node'", 'unique': 'True', 'null': 'True', 'to': "orm['forum.Action']"}),
229 'marked': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
230 'node_type': ('django.db.models.fields.CharField', [], {'default': "'node'", 'max_length': '16'}),
231 'parent': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'children'", 'null': 'True', 'to': "orm['forum.Node']"}),
232 'score': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
233 'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}),
234 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'nodes'", 'to': "orm['forum.Tag']"}),
235 'title': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
236 'wiki': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'})
238 'forum.noderevision': {
239 'Meta': {'unique_together': "(('node', 'revision'),)", 'object_name': 'NodeRevision'},
240 'author': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'noderevisions'", 'to': "orm['forum.User']"}),
241 'body': ('django.db.models.fields.TextField', [], {}),
242 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
243 'node': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': "orm['forum.Node']"}),
244 'revised_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
245 'revision': ('django.db.models.fields.PositiveIntegerField', [], {}),
246 'summary': ('django.db.models.fields.CharField', [], {'max_length': '300'}),
247 'tagnames': ('django.db.models.fields.CharField', [], {'max_length': '125'}),
248 'title': ('django.db.models.fields.CharField', [], {'max_length': '300'})
250 'forum.openidassociation': {
251 'Meta': {'object_name': 'OpenIdAssociation'},
252 'assoc_type': ('django.db.models.fields.TextField', [], {'max_length': '64'}),
253 'handle': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
254 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
255 'issued': ('django.db.models.fields.IntegerField', [], {}),
256 'lifetime': ('django.db.models.fields.IntegerField', [], {}),
257 'secret': ('django.db.models.fields.TextField', [], {'max_length': '255'}),
258 'server_url': ('django.db.models.fields.TextField', [], {'max_length': '2047'})
260 'forum.openidnonce': {
261 'Meta': {'object_name': 'OpenIdNonce'},
262 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
263 'salt': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
264 'server_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
265 'timestamp': ('django.db.models.fields.IntegerField', [], {})
267 'forum.questionsubscription': {
268 'Meta': {'object_name': 'QuestionSubscription'},
269 'auto_subscription': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
270 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
271 'last_view': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2010, 5, 3, 11, 43, 54, 540000)'}),
272 'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Node']"}),
273 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']"})
275 'forum.subscriptionsettings': {
276 'Meta': {'object_name': 'SubscriptionSettings'},
277 'all_questions': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
278 'all_questions_watched_tags': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
279 'enable_notifications': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
280 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
281 'member_joins': ('django.db.models.fields.CharField', [], {'default': "'n'", 'max_length': '1'}),
282 'new_question': ('django.db.models.fields.CharField', [], {'default': "'d'", 'max_length': '1'}),
283 'new_question_watched_tags': ('django.db.models.fields.CharField', [], {'default': "'i'", 'max_length': '1'}),
284 'notify_accepted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
285 'notify_answers': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
286 'notify_comments': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
287 'notify_comments_own_post': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
288 'notify_reply_to_comments': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
289 'questions_answered': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
290 'questions_asked': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
291 'questions_commented': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
292 'questions_viewed': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
293 'subscribed_questions': ('django.db.models.fields.CharField', [], {'default': "'i'", 'max_length': '1'}),
294 'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'subscription_settings'", 'unique': 'True', 'to': "orm['forum.User']"})
297 'Meta': {'object_name': 'Tag'},
298 'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_tags'", 'to': "orm['forum.User']"}),
299 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
300 'deleted_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
301 'deleted_by': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'deleted_tags'", 'null': 'True', 'to': "orm['forum.User']"}),
302 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
303 'marked_by': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'marked_tags'", 'through': "'MarkedTag'", 'to': "orm['forum.User']"}),
304 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
305 'used_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'})
308 'Meta': {'object_name': 'User', '_ormbases': ['auth.User']},
309 'about': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
310 'bronze': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
311 'date_of_birth': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
312 'email_isvalid': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
313 'gold': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
314 'is_approved': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
315 'last_seen': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
316 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
317 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
318 'reputation': ('django.db.models.fields.PositiveIntegerField', [], {'default': '1'}),
319 'silver': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
320 'subscriptions': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'subscribers'", 'through': "'QuestionSubscription'", 'to': "orm['forum.Node']"}),
321 'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}),
322 'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
324 'forum.validationhash': {
325 'Meta': {'unique_together': "(('user', 'type'),)", 'object_name': 'ValidationHash'},
326 'expiration': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2010, 5, 4, 11, 43, 54, 592000)'}),
327 'hash_code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
328 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
329 'seed': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
330 'type': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
331 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']"})
334 'Meta': {'unique_together': "(('user', 'node'),)", 'object_name': 'Vote'},
335 'action': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'vote'", 'unique': 'True', 'to': "orm['forum.Action']"}),
336 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
337 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.Node']"}),
338 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['forum.User']"}),
339 'value': ('django.db.models.fields.SmallIntegerField', [], {}),
340 'voted_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
344 complete_apps = ['forum']