Exemplo n.º 1
0
 def calculate(self):
     def query_count(model):
         q = model.query.filter_by(topic_id=self.ident)
         return q.with_entities(func.count(1)).scalar()
     redis.hmset(self._key, dict(
         likes=query_count(TopicLike),
         reads=query_count(TopicRead),
         comments=query_count(Comment),
     ))
Exemplo n.º 2
0
    def calculate(self):
        def query_count(model):
            q = model.query.filter_by(topic_id=self.ident)
            return q.with_entities(func.count(1)).scalar()

        redis.hmset(
            self._key,
            dict(
                likes=query_count(TopicLike),
                reads=query_count(TopicRead),
                comments=query_count(Comment),
            ))
Exemplo n.º 3
0
    def login(cls, user, permanent=False):
        request._current_user = user
        ua = request.user_agent
        sess = cls()

        now = int(time.time())
        redis.hmset(sess._key, {
            'user_id': user.id,
            'platform': ua.platform,
            'browser': ua.browser,
            'created_at': now,
            'last_used': now,
        })
        session['id'] = sess.sid
        session['ts'] = now
        return sess
Exemplo n.º 4
0
    def login(cls, user, permanent=False):
        request._current_user = user
        ua = request.user_agent
        sess = cls()

        now = int(time.time())
        redis.hmset(
            sess._key, {
                'user_id': user.id,
                'platform': ua.platform,
                'browser': ua.browser,
                'created_at': now,
                'last_used': now,
            })
        session['id'] = sess.sid
        session['ts'] = now
        return sess