def do_update(self): version = self.r.get('version') if not version: self.r.set('version', 8) return version = int(version) r = JSONRedis(self.r.r) r.caching = False # Deprecated since 0.14.0 if version < 7: now = time() lists = r.omget(r.lrange('lists', 0, -1)) for lst in lists: r.zadd('{}.lists'.format(lst['authors'][0]), {lst['id']: -now}) r.set('version', 7) # Deprecated since 0.23.0 if version < 8: lists = r.omget(r.lrange('lists', 0, -1)) for lst in lists: users_key = '{}.users'.format(lst['id']) self.r.zadd(users_key, {lst['authors'][0].encode(): 0}) events = r.omget(r.lrange('{}.activity.items'.format(lst['id']), 0, -1)) for event in reversed(events): t = parse_isotime(event['time'], aware=True).timestamp() self.r.zadd(users_key, {event['user'].encode(): -t}) r.set('version', 8)
def __init__(self, id, trashed, app, authors, title, time, location, description): super().__init__(id=id, trashed=trashed, app=app) Editable.__init__(self, authors=authors) self.title = title self.time = parse_isotime(time) if time else None self.location = location self.description = description self._items_key = self.id + '.items' self._trashed_items_key = self.id + '.trashed_items' self.items = JSONRedisMapping(self.app.r, self._items_key) self.trashed_items = JSONRedisMapping(self.app.r, self._trashed_items_key)
def post(self): args = self.check_args({ 'title': str, 'time': (str, None, 'opt'), 'location': (str, None, 'opt'), 'description': (str, None, 'opt') }) if 'time' in args and args['time']: try: args['time'] = parse_isotime(args['time']) except ValueError: raise micro.InputError({'time': 'bad_type'}) meeting = self.app.create_meeting(**args) self.write(meeting.json(restricted=True, include_users=True))
def post(self): args = self.check_args({ 'title': str, 'time': (str, None, 'opt'), 'location': (str, None, 'opt'), 'description': (str, None, 'opt') }) if 'time' in args and args['time']: try: args['time'] = parse_isotime(args['time']) except ValueError: raise micro.InputError({'time': 'bad_type'}) meeting = self.app.create_meeting(**args) self.write(meeting.json(restricted=True, include=True))
def _meeting(time, **kwargs): return Meeting(time=parse_isotime(time) if time else time, **kwargs)
def test_parse_isotime_date(self) -> None: t = parse_isotime('2015-08-27') self.assertEqual(t, date(2015, 8, 27))
def test_parse_isotime(self) -> None: t = parse_isotime('2015-08-27T00:42:00.000Z') self.assertEqual(t, datetime(2015, 8, 27, 0, 42, 0, 0, timezone.utc))