diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-01-25 20:21:21 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-01-25 20:21:21 -0500 |
commit | fe5565bc98c7c14c9a544ab50f27dac9e32700c7 (patch) | |
tree | 6029af19f75e91bae82bd724ee0ca89841189894 /askbot/importers | |
parent | a759e17bc67a9923c0e84b84fec3684e978e6f62 (diff) | |
download | askbot-fe5565bc98c7c14c9a544ab50f27dac9e32700c7.tar.gz askbot-fe5565bc98c7c14c9a544ab50f27dac9e32700c7.tar.bz2 askbot-fe5565bc98c7c14c9a544ab50f27dac9e32700c7.zip |
finalized the SE import app and documented it, fixed some tests
Diffstat (limited to 'askbot/importers')
-rw-r--r-- | askbot/importers/stackexchange/management/__init__.py | 15 | ||||
-rw-r--r-- | askbot/importers/stackexchange/management/commands/load_stackexchange.py | 9 |
2 files changed, 23 insertions, 1 deletions
diff --git a/askbot/importers/stackexchange/management/__init__.py b/askbot/importers/stackexchange/management/__init__.py index 66103e27..174bdaaf 100644 --- a/askbot/importers/stackexchange/management/__init__.py +++ b/askbot/importers/stackexchange/management/__init__.py @@ -1,6 +1,8 @@ +import logging import threading from django.core import management -import logging +from django.core.exceptions import ImproperlyConfigured +from django.db.models import get_model class ImporterThread(threading.Thread): def __init__(self, dump_file = None): @@ -9,3 +11,14 @@ class ImporterThread(threading.Thread): def run(self): management.call_command('load_stackexchange', self.dump_file) + +def is_ready(): + """determines whether the stackexchange app is ready to roll + by trying to load a model from the database + """ + try: + get_model('stackexchange', 'User2Vote') + return True + except Exception: + return False + diff --git a/askbot/importers/stackexchange/management/commands/load_stackexchange.py b/askbot/importers/stackexchange/management/commands/load_stackexchange.py index 6b656f58..c1d045ae 100644 --- a/askbot/importers/stackexchange/management/commands/load_stackexchange.py +++ b/askbot/importers/stackexchange/management/commands/load_stackexchange.py @@ -16,6 +16,7 @@ from django.contrib.auth.models import Message as DjangoMessage from django.utils.translation import ugettext as _ from askbot.utils.slug import slugify from askbot.models.badges import award_badges_signal, award_badges +from askbot.importers.stackexchange.management import is_ready as importer_is_ready #from markdown2 import Markdown #markdowner = Markdown(html4tags=True) @@ -277,6 +278,14 @@ class Command(BaseCommand): @transaction.commit_manually def handle(self, *arg, **kwarg): + if not importer_is_ready(): + raise CommandError( + "Looks like stackexchange tables are not yet initialized in the database.\n" + "Please, run command: \npython manage.py syncdb\n" + "then import the data." + ) + + award_badges_signal.disconnect(award_badges) if len(arg) < 1 or not os.path.isfile(arg[0]): |