def forwards(self, orm): User = orm['auth.User'] for x in range(40): day = datetime.date.today() - datetime.timedelta(x) dayset = RedisSet('metrics:signup:%s:uniques' % day.strftime("%Y.%m.%d")) for user_id in User.objects.filter(date_joined__range=(day, day+datetime.timedelta(1))).values_list('id', flat=True): dayset.sadd(user_id)
def forwards(self, orm): User = orm['auth.User'] for x in range(40): day = datetime.date.today() - datetime.timedelta(x) dayset = RedisSet('metrics:signup:%s:uniques' % day.strftime("%Y.%m.%d")) for user_id in User.objects.filter( date_joined__range=(day, day + datetime.timedelta(1))).values_list( 'id', flat=True): dayset.sadd(user_id)
def forwards(self, orm): "Write your forwards methods here." count = 0 for c in orm.Comment.objects.all(): if c.category is not None: cname = c.category.name tags = RedisSet("comment:{}:tags".format(c.id)) if tags.scard() == 0: tags.sadd(cname) Tag(cname).tag_comment(c, c.timestamp) count += 1 if count % 10000 == 0: print count
class UserPalettes(object): def __init__(self, user_id=None): self.user_id = user_id self._palettes = None if user_id: self._palettes = RedisSet('user:{}:palettes'.format(user_id)) def __iter__(self): yield DEFAULT_PALETTE if self._palettes: for palette in self._palettes.smembers(): yield get_palette_by_id(palette) def __contains__(self, palette): if palette.id == DEFAULT_PALETTE.id: return True return self._palettes and palette.id in self._palettes def to_client(self): return [palette for palette in self] def unlock(self, palette): if not self.user_id: raise TypeError("Cannot unlock a palette for a logged-out user.") if isinstance(palette, basestring): palette = get_palette_by_name(name) if palette.id == DEFAULT_PALETTE.id: return self._palettes.sadd(palette.id)
class UserPalettes(object): def __init__(self, user_id=None): self.user_id = user_id self._palettes = None if user_id: self._palettes = RedisSet('user:{}:palettes'.format(user_id)) def __iter__(self): yield DEFAULT_PALETTE if self._palettes: for palette in self._palettes.smembers(): yield get_palette_by_id(palette) def __contains__(self, palette): if palette.id == DEFAULT_PALETTE.id: return True return self._palettes and palette.id in self._palettes def to_client(self, **kwargs): return [palette for palette in self] def unlock(self, palette): if not self.user_id: raise TypeError("Cannot unlock a palette for a logged-out user.") if isinstance(palette, basestring): palette = get_palette_by_name(name) if palette.id == DEFAULT_PALETTE.id: return self._palettes.sadd(palette.id)