From: Seth Woodworth Date: Mon, 18 Mar 2013 20:39:12 +0000 (-0400) Subject: adding management command to strip existing Note.html into raw note.text for previews... X-Git-Tag: release-20150131~498^2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7e379e220fd462b492e37b5e18153a597a956316;p=oweals%2Fkarmaworld.git adding management command to strip existing Note.html into raw note.text for previews and search --- diff --git a/karmaworld/apps/notes/management/__init__.py b/karmaworld/apps/notes/management/__init__.py new file mode 100644 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 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 index 0000000..2fa00c0 --- /dev/null +++ b/karmaworld/apps/notes/management/commands/strip_html_to_text.py @@ -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) + diff --git a/reqs/common.txt b/reqs/common.txt index d1655ab..2a42a6b 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -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