adding management command to strip existing Note.html into raw note.text for previews...
authorSeth Woodworth <seth@sethish.com>
Mon, 18 Mar 2013 20:39:12 +0000 (16:39 -0400)
committerSeth Woodworth <seth@sethish.com>
Mon, 18 Mar 2013 20:39:12 +0000 (16:39 -0400)
karmaworld/apps/notes/management/__init__.py [new file with mode: 0644]
karmaworld/apps/notes/management/commands/__init__.py [new file with mode: 0644]
karmaworld/apps/notes/management/commands/strip_html_to_text.py [new file with mode: 0644]
reqs/common.txt

diff --git a/karmaworld/apps/notes/management/__init__.py b/karmaworld/apps/notes/management/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/karmaworld/apps/notes/management/commands/__init__.py b/karmaworld/apps/notes/management/commands/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/karmaworld/apps/notes/management/commands/strip_html_to_text.py b/karmaworld/apps/notes/management/commands/strip_html_to_text.py
new file mode 100644 (file)
index 0000000..2fa00c0
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# -*- coding:utf8 -*-
+# Copyright (C) 2012  FinalsClub Foundation
+
+from lxml.html import fromstring
+
+from django.core.management.base import BaseCommand
+from apps.notes.models import Note
+
+class Command(BaseCommand):
+    args = 'none'
+    help = "Take all notes with the .html property and use that to fill Note.text by stripping html"
+
+    def handle(self, *args, **kwargs):
+        notes = Note.objects.filter(html__isnull=False).filter(text__isnull=True)
+        cleaned_notes = 0
+        for note in notes:
+            note.text = fromstring(note.html).text_content()
+            note.save()
+            cleaned_notes += 1
+        self.stdout.write('Processed %s notes' % cleaned_notes)
+
index d1655abf13f2dd54d7c2917dde9c86f11a962a06..2a42a6bd966b5a0bbe090edd1bd0305950b1aad2 100644 (file)
@@ -10,3 +10,4 @@ oauth2client==1.0
 urllib3==1.5
 google-api-python-client==1.0
 django-grappelli==2.4.3
+lxml==3.1.0