Commit 2bbaaf6b by Greg Price

Fix management commands more

parent c9771a78
...@@ -90,12 +90,14 @@ class Command(BaseCommand): ...@@ -90,12 +90,14 @@ class Command(BaseCommand):
def show_users(self, users): def show_users(self, users):
json.dump(list(users), self.stdout) json.dump(list(users), self.stdout)
def show_content(self, users_by_id, from_dt, to_dt): def show_content(self, users, from_dt, to_dt):
users_by_id = dict((str(u['id']), u) for u in users)
all_content = generate_digest_content(users_by_id, from_dt, to_dt) all_content = generate_digest_content(users_by_id, from_dt, to_dt)
# use django's encoder; builtin one doesn't handle datetime objects # use django's encoder; builtin one doesn't handle datetime objects
json.dump(list(all_content), self.stdout, cls=DigestJSONEncoder) json.dump(list(all_content), self.stdout, cls=DigestJSONEncoder)
def show_rendered(self, fmt, users_by_id, from_dt, to_dt): def show_rendered(self, fmt, users, from_dt, to_dt):
users_by_id = dict((str(u['id']), u) for u in users)
def _fail(msg): def _fail(msg):
logger.warning('could not show rendered %s: %s', fmt, msg) logger.warning('could not show rendered %s: %s', fmt, msg)
...@@ -130,8 +132,6 @@ class Command(BaseCommand): ...@@ -130,8 +132,6 @@ class Command(BaseCommand):
# get all the users subscribed to notifications # get all the users subscribed to notifications
users = get_digest_subscribers() # generator users = get_digest_subscribers() # generator
users_by_id = dict((str(u['id']), u) for u in users)
if options.get('show_users'): if options.get('show_users'):
self.show_users(users) self.show_users(users)
return return
...@@ -146,11 +146,11 @@ class Command(BaseCommand): ...@@ -146,11 +146,11 @@ class Command(BaseCommand):
datetime.timedelta(minutes=options['minutes']) datetime.timedelta(minutes=options['minutes'])
if options.get('show_content'): if options.get('show_content'):
self.show_content(users_by_id, from_datetime, to_datetime) self.show_content(users, from_datetime, to_datetime)
return return
if options.get('show_text'): if options.get('show_text'):
self.show_rendered('text', users_by_id, from_datetime, to_datetime) self.show_rendered('text', users, from_datetime, to_datetime)
return return
if options.get('show_html'): if options.get('show_html'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment