Update user_check command to report username more consistently for ease of parsing.
@@ -14,21 +14,27 @@ logger = logging.getLogger(__name__)
class Command(BaseCommand):
def handle(self, **options):
- editors = Editor.objects.all()
- for editor in editors:
- global_userinfo = self.get_global_userinfo(editor)
+ users = User.objects.all()
+ for user in users:
try:
- assert editor.wp_sub == global_userinfo['id']
- #self.stdout.write(u'ID match for {name}: local ID: {twlight_sub} remote ID: {sul_id}'.format(name=urllib2.quote(editor.wp_username),twlight_sub=editor.wp_sub,sul_id=global_userinfo['id']))
+ assert hasattr(user, 'editor')
except AssertionError:
- self.stdout.write(u'ID mismatch for {name}: local ID: {twlight_sub} remote ID: {sul_id}'.format(name=urllib2.quote(editor.wp_username),twlight_sub=editor.wp_sub,sul_id=global_userinfo['id']))
+ self.stdout.write(u'{username}: no editor object.'.format(username=(user.username)))
+ # Move on to the next user
+ continue
+
+ try:
+ global_userinfo = self.get_global_userinfo(user)
+ assert user.editor.wp_sub == global_userinfo['id']
+ except AssertionError:
+ self.stdout.write(u'{name}: ID mismatch - local ID: {twlight_sub} remote ID: {sul_id}'.format(name=user.editor.wp_username,twlight_sub=user.editor.wp_sub,sul_id=global_userinfo['id']))
pass
except:
pass
- def get_global_userinfo(self, editor):
+ def get_global_userinfo(self, user):
try:
- endpoint = '{base}/w/api.php?action=query&meta=globaluserinfo&guiuser={name}&format=json&formatversion=2'.format(base='https://meta.wikimedia.org',name=urllib2.quote(editor.wp_username))
+ endpoint = '{base}/w/api.php?action=query&meta=globaluserinfo&guiuser={name}&format=json&formatversion=2'.format(base='https://meta.wikimedia.org',name=urllib2.quote(user.editor.wp_username))
results = json.loads(urllib2.urlopen(endpoint).read())
global_userinfo = results['query']['globaluserinfo']
@@ -37,6 +43,6 @@ class Command(BaseCommand):
assert 'missing' not in global_userinfo
return global_userinfo
except:
- self.stdout.write(u'could not fetch global_userinfo for django user #{editor_id}.'.format(editor_id=str(editor.id)))
+ self.stdout.write(u'{username}: could not fetch global_userinfo.'.format(username=str(user.username)))
return None
pass
