Skip to content

Commit

Permalink
import forums
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurk committed Dec 11, 2009
1 parent 5d1c763 commit 9689637
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 4 additions & 9 deletions disqus/management/commands/disqus-import.py
Expand Up @@ -4,20 +4,15 @@
from disqus.models import Forum

class Command(NoArgsCommand):
help = 'Import DISQUS data into local database'
help = 'Import DISQUS data into the local database'

def handle_noargs(self, **options):
from django.conf import settings

client = DisqusClient()
forums = client.get_forum_list(user_api_key=settings.DISQUS_API_KEY)
Forum.import_from_api()
try:
forum = [f for f in forums if f['shortname'] == settings.DISQUS_WEBSITE_SHORTNAME][0]
except IndexError:
forum = Forum.objects.get(shortname=settings.DISQUS_WEBSITE_SHORTNAME)
except Forum.DoesNotExist:
raise CommandError("Could not find forum with shortname '%s'. " \
"Check your 'DISQUS_WEBSITE_SHORTNAME' " \
"setting" % setting.DISQUS_WEBSITE_SHORTNAME)
forum_obj = Forum.objects.get_or_create(id=forum['id'], defaults=dict(
shortname=forum['shortname'],
name=forum['name']
))
15 changes: 15 additions & 0 deletions disqus/models.py
@@ -1,6 +1,9 @@
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _

from disqus.api import DisqusClient


class Forum(models.Model):
id = models.CharField(primary_key=True, max_length=15,
Expand All @@ -19,6 +22,18 @@ class Meta:
def __unicode__(self):
return self.name

@staticmethod
def import_from_api():
client = DisqusClient()
forums = client.get_forum_list(user_api_key=settings.DISQUS_API_KEY)
for forum in forums:
f, created = Forum.objects.get_or_create(id=forum['id'],
defaults=dict(shortname=forum['shortname'],
name=forum['name']))
if not created:
f.shortname = forum['shortname']
f.name = forum['name']
f.save()

class Thread(models.Model):
id = models.CharField(primary_key=True, max_length=15,
Expand Down

0 comments on commit 9689637

Please sign in to comment.