Mercurial > p > roundup > code
view tools/fixroles.py @ 7590:5fbd3af526bd
fix: issue2551278 - datetime.datetime.utcnow deprecation.
We now use the timezone aware utc dates for python 3.11+.
But we have to make all the rest of the dates (datetime.min, unix
epoch date) timezon aware so we can subtract them. Also need to
marshall/unmarshall timezone aware iso formatted date strings.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 27 Jul 2023 00:53:36 -0400 |
| parents | 52c8324d1539 |
| children |
line wrap: on
line source
import sys from roundup import admin class AdminTool(admin.AdminTool): def __init__(self): self.commands = admin.CommandDict() for k in AdminTool.__dict__.keys(): if k[:3] == 'do_': self.commands[k[3:]] = getattr(self, k) self.help = {} for k in AdminTool.__dict__.keys(): if k[:5] == 'help_': self.help[k[5:]] = getattr(self, k) self.instance_home = '' self.db = None def do_fixroles(self, args): '''Usage: fixroles Set the roles property for all users to reasonable defaults. The admin user gets "Admin", the anonymous user gets "Anonymous" and all other users get "User". ''' # get the user class cl = self.get_class('user') for userid in cl.list(): username = cl.get(userid, 'username') if username == 'admin': roles = 'Admin' elif username == 'anonymous': roles = 'Anonymous' else: roles = 'User' cl.set(userid, roles=roles) return 0 if __name__ == '__main__': tool = AdminTool() sys.exit(tool.main())
