Mercurial > public > sg101
comparison gpp/legacy/management/commands/import_old_news.py @ 292:2367c4795c92
Added a legacy management command to import old news comments.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 22:20:30 +0000 |
parents | a6357f2bcbbc |
children | 254db4cb6a86 |
comparison
equal
deleted
inserted
replaced
291:a6357f2bcbbc | 292:2367c4795c92 |
---|---|
10 from django.core.management.base import LabelCommand, CommandError | 10 from django.core.management.base import LabelCommand, CommandError |
11 from django.contrib.auth.models import User | 11 from django.contrib.auth.models import User |
12 | 12 |
13 from news.models import Category, Story | 13 from news.models import Category, Story |
14 from legacy.phpbb import unescape | 14 from legacy.phpbb import unescape |
15 import legacy.data | |
15 | 16 |
16 KNOWN_USERNAME_CHANGES = { | |
17 'cavefishbutchdelux': 'butchdelux', | |
18 'Findicator1': 'WaveOhhh', | |
19 } | |
20 | 17 |
21 class Command(LabelCommand): | 18 class Command(LabelCommand): |
22 args = '<filename filename ...>' | 19 args = '<filename filename ...>' |
23 help = 'Imports news stories from the old database in CSV format' | 20 help = 'Imports news stories from the old database in CSV format' |
24 option_list = LabelCommand.option_list + ( | 21 option_list = LabelCommand.option_list + ( |
112 | 109 |
113 try: | 110 try: |
114 user = User.objects.get(username=username) | 111 user = User.objects.get(username=username) |
115 except User.DoesNotExist: | 112 except User.DoesNotExist: |
116 try: | 113 try: |
117 user = User.objects.get(username=KNOWN_USERNAME_CHANGES[username]) | 114 user = User.objects.get( |
115 username=legacy.data.KNOWN_USERNAME_CHANGES[username]) | |
118 except KeyError: | 116 except KeyError: |
119 raise User.DoesNotExist | 117 raise User.DoesNotExist |
120 | 118 |
121 self.users[username] = user | 119 self.users[username] = user |
122 return user | 120 return user |