]> git.openstreetmap.org Git - osqa.git/commitdiff
Should auto link old stuff in the node cache migration.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 1 Jan 2011 18:56:21 +0000 (18:56 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sat, 1 Jan 2011 18:56:21 +0000 (18:56 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@660 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/migrations/0044_markdown_cache_migration.py

index 7ae4abdce230252ac121e31d44887421119e468c..ac317423f073e0cec8dcd9873e83c5d729097724 100644 (file)
@@ -1,4 +1,5 @@
 # encoding: utf-8
+import os, sys
 import datetime
 from south.db import db
 from south.v2 import DataMigration
@@ -13,11 +14,20 @@ from forum.utils.html import sanitize_html
 class Migration(DataMigration):
 
     def forwards(self, orm):
+        sys.path.append(os.path.join(os.path.dirname(__file__),'../markdownext'))
+
         count  = orm.Node.objects.count()
         progress = ProgressBar(count)
         
         for node in orm.Node.objects.all():
-            node.body = mark_safe(sanitize_html(markdown.markdown(node.body)))
+            rev = node.active_revision
+
+            if not rev:
+                try:
+                    rev = node.revisions.order_by('-revision')[0]
+                except:
+                    continue
+            node.body = sanitize_html(markdown.markdown(rev.body, ['urlize']))
             node.save()
             progress.update()