Esempio n. 1
0
 def prepare(self):  # 请求前执行
     logging.info('every request_handler to be prepared')
     # 只有登陆者   才能保存session
     yield self.init_session()  # 一般情况下这个session是{} 空字典,得往里面加数据
     if session_keys['login_user'] in self.session:
         self.current_user = LoginUser(
             self.session[session_keys['login_user']])
     self.add_pv_uv()  # 与主代码异步执行,所以不用yield阻塞
Esempio n. 2
0
 def save_login_user(self, user):
     login_user = LoginUser(None)
     login_user['id'] = user.id
     login_user['name'] = user.username
     login_user['avatar'] = self.get_gravatar_url(user.email)
     login_user['email'] = user.email
     self.session[session_keys['login_user']] = login_user
     self.current_user = login_user
     self.save_session()
Esempio n. 3
0
 def prepare(self):
     yield self.init_session()
     if session_keys['login_user'] in self.session:
         self.current_user = LoginUser(
             self.session[session_keys['login_user']])
     self.add_pv_uv()  # 与主代码异步执行,所以不用yield阻塞
     # 更新博客统计数据
     SiteCollection.article_month_count = yield self.async_do(
         ArticleService.get_count_by_month, self.db)
Esempio n. 4
0
 async def save_login_user(self, user):
     login_user = LoginUser(None)
     login_user['id'] = user.id
     login_user['name'] = user.username
     # 获取通用头像
     login_user['avatar'] = self.get_gravatar_url(user.email)
     login_user['email'] = user.email
     self.session[session_keys['login_user']] = login_user
     self.current_user = login_user
     # self.save_session()
     # 保存到redis
     await self.session.save(self.session_expire_time)
Esempio n. 5
0
    async def prepare(self):
        # await self.init_session()
        if not self.session:
            self.session = Session(self)

        # 如果已登录
        session_id = self.session.get_session_id()
        if session_id:
            uinfo = await self.session.get()
            self.current_user = LoginUser(uinfo['login_user'])

        # if session_keys['login_user'] in self.session:
        #     self.current_user = LoginUser(self.session[session_keys['login_user']])

        # 添加pv和uv
        await self.add_pv_uv()
        # 获取博客信息
        if self.site_info.navbar is None:
            # 博客概况
            blog = BlogInfoService.get_blog_info(self.db)
            self.site_info.title = blog.title
            self.site_info.signature = blog.signature
            self.site_info.navbar = blog.navbar
            # 插件列表
            plugin = PluginService.list_plugins(self.db)
            self.site_info.plugins = plugin
            # 今日uv和pv
            view = BlogViewService.get_blog_view(self.db)
            self.site_info.todaypv = view.pv
            self.site_info.todayuv = view.uv
            # 文章来源
            self.site_info.article_sources = ArticleService.get_article_sources(
                self.db)
            # 文章数量
            self.site_info.article_count = ArticleService.get_article_count(
                self.db)
            # 评论数
            self.site_info.comment_count = CommentService.get_comment_count(
                self.db)
Esempio n. 6
0
 def prepare(self):
     yield self.init_session()
     if session_keys['login_user'] in self.session:
         self.current_user = LoginUser(self.session[session_keys['login_user']])
     self.add_pv_uv() # 与主代码异步执行,所以不用yield阻塞